80 likes | 245 Views
SCOM 2007 Development. Wei Wang Consultant MCS. SCOM SDK. Assembly.
E N D
SCOM 2007 Development Wei Wang Consultant MCS
Assembly • Each Management Group contains a Root Management Server, which hosts an SDK Service. The SDK Service is a Windows service that processes all external requests to access Operations Manager features and data. To access Operations Manager functionality, an application must connect as a client to the SDK Service. Operations Manager provides two .NET managed code libraries that you can use to connect to the SDK Service, perform Operations Manager functions, and access Operations Manager data. These libraries are: • Microsoft.EnterpriseManagement.OperationsManager.dll • Microsoft.EnterpriseManagement.OperationsManager.Common.dll
SCOM Connection SecureString password = new SecureString(); foreach (Char pwdChar in userPassword.ToCharArray()) { password.AppendChar(pwdChar); } try { ManagementGroupConnectionSettings mgSettings = new ManagementGroupConnectionSettings(server); mgSettings.UserName = name; mgSettings.Domain = userDomain; mgSettings.Password = password; richTextBox1.Text += "Connecting to the SDK Service as user: " + name + "\r\n"; ManagementGroup mg = ManagementGroup.Connect(mgSettings); if (mg.IsConnected) { richTextBox1.Text += "Connection succeeded.\r\n"; return mg; } else { throw new InvalidOperationException("Not connected to an SDK Service."); } } catch (Exception ex) { richTextBox1.Text += "\nConnection failed. " + ex.Message + "\r\n"; if (ex.InnerException != null) { richTextBox1.Text += ex.InnerException.Message + "\r\n"; } }
Get MonitoringObject ManagementGroup mg = ConnectScom(serverName, name, userDomain, userPassword); // The criteria specifies that you want to collect computers running Windows Server 2003. MonitoringClassCriteria classCriteria = new MonitoringClassCriteria("Name = 'Microsoft.Windows.Server.2003.Computer'"); richTextBox1.Text += "Querying for data...\r\n"; // There should only be one item in the monitoringClasses collection. ReadOnlyCollection<MonitoringClass> monitoringClasses = mg.GetMonitoringClasses(classCriteria); if (monitoringClasses.Count > 0) { // Get all instances of computers running Windows Server 2003 in the management group. ReadOnlyCollection<MonitoringObject> monitoringObjects = mg.GetMonitoringObjects(monitoringClasses[0]); if (monitoringObjects.Count > 0) { richTextBox1.Text += "Monitoring Object name: " + monitoringObjects[0].DisplayName + "\r\n"; DisplayHierarchyInformation(monitoringObjects[0]); DisplayPerformanceData(monitoringObjects[0]); DisplayPropertyValues(monitoringObjects[0]); DisplayRelationshipInformation(monitoringObjects[0]); DisplayRelatedObjects(monitoringObjects[0]); DisplayMonitoringStateHierarchy(monitoringObjects[0]); } else { richTextBox1.Text += "MonitoringObjects count=0. \r\n"; } } else { richTextBox1.Text += "MonitoringClasses count=0. \r\n"; }
Get Monitoring Object Property void DisplayPropertyValues(MonitoringObject mObject) { richTextBox1.Text += "Property value information: \r\n"; foreach (MonitoringClassProperty property in mObject.GetMonitoringProperties()) { richTextBox1.Text += " " + property.Name + " = " + mObject.GetMonitoringPropertyValue(property) + "\r\n"; } }
Get MonitoringObject Hierarchy //--------------------------------------------------------------------------------- // Get the monitoring hierarchy and display information about the hierarchy. void DisplayHierarchyInformation(MonitoringObject mObject) { MonitoringHierarchyNode<ManagementPackMonitor> hierarchy = mObject.GetMonitorHierarchy(); richTextBox1.Text += "Monitoring hierarchy: \r\n"; // Parent node information. if (hierarchy.ParentNode != null) { richTextBox1.Text += " Parent node: " + hierarchy.ParentNode.Item.DisplayName + "\r\n"; } else { richTextBox1.Text += " No parent node.\r\n"; } // Child node information. if (hierarchy.TotalChildNodeCount > 0) { richTextBox1.Text += " Child nodes: \r\n"; foreach (MonitoringHierarchyNode<ManagementPackMonitor> child in hierarchy.ChildNodes) { richTextBox1.Text += " " + child.Item.DisplayName + "\r\n"; } } else { richTextBox1.Text += " No child nodes available.\r\n"; } }
Q&A Thanks!