我正在使用 SCOM 工具来监控 windows 系统。使用 C# 代码和 SDK,我应该获取平台和服务器以及它正在使用的服务的详细信息。我能够获得 Platfroms。任何人都可以帮助从平台获取服务器。
这是我的代码。
ManagementGroup mgGroup = new ManagementGroup(mgGroupConnection);
if (!mgGroup.IsConnected)
{
throw new InvalidOperationException("Not connected to an SDK Service.");
}
MonitoringClassCriteria classCriteria = new MonitoringClassCriteria("Name = 'Microsoft.Windows.Computer'OR Name='Microsoft.Linux.Computer'");
Console.WriteLine("Querying for data...");
ReadOnlyCollection<MonitoringClass> monitoringClasses = mgGroup.GetMonitoringClasses(classCriteria);
ReadOnlyCollection<MonitoringObject> monitoringObjects = mgGroup.GetMonitoringObjects(monitoringClasses[0]);
if (monitoringObjects.Count > 0)
{
foreach (MonitoringObject objects in monitoringObjects)
{
Console.WriteLine("Monitoring Object name: " + objects.DisplayName + Environment.NewLine);
DisplayPropertyValues(objects);
Console.WriteLine(objects.HealthState.ToString());
}
}
public static void DisplayPropertyValues(MonitoringObject mObject)
{
Console.WriteLine();
Console.WriteLine("Property value information: ");
foreach (MonitoringClassProperty property in mObject.GetMonitoringProperties())
{
Console.WriteLine(" " + property.Name + " = " + ((mObject.GetMonitoringPropertyValue(property) != null) ? mObject.GetMonitoringPropertyValue(property).ToString() : "NULL"));
}
}`
输出:
Querying for data...
Monitoring Object name: SCOM1.IMTS.TEST
Property value information:
IsVirtualNode = NULL
PrincipalName = SCOM1.IMTS.TEST
DNSName = SCOM1.IMTS.TEST
NetbiosComputerName = SCOM1
NetbiosDomainName = IMTS
IPAddress = 192.168.147.7, fe80::619d:83dd:1edc:cf32
NetworkName = SCOM1.IMTS.TEST
ActiveDirectoryObjectSid = NULL
IsVirtualMachine = True
DomainDnsName = IMTS.TEST
OrganizationalUnit = CN=Computers,DC=IMTS,DC=TEST
ForestDnsName = IMTS.TEST
ActiveDirectorySite = Default-First-Site-Name
LogicalProcessors = 2
PhysicalProcessors = 1
HostServerName = RD24BE05B7D840
VirtualMachineName = 668ff774-591e-4e2b-990a-7ea00147846c
OffsetInMinuteFromGreenwichTime = NULL
LastInventoryDate = NULL
DisplayName = SCOM1.IMTS.TEST
InstallDirectory = C:\Program Files\Microsoft System Center 2012 R2\Operations
Manager\Server\
Success
criteria Name LIKE '%Memory%'
Monitoring Object name: activedirectory.imts.test
Property value information:
IsVirtualNode = NULL
PrincipalName = ActiveDirectory.IMTS.TEST
DNSName = ActiveDirectory.IMTS.TEST
NetbiosComputerName = ActiveDirectory
NetbiosDomainName = IMTS
IPAddress = 192.168.147.6
NetworkName = ActiveDirectory.IMTS.TEST
ActiveDirectoryObjectSid = S-1-5-21-1598398879-2601050756-607317532-1001
IsVirtualMachine = True
DomainDnsName = IMTS.TEST
OrganizationalUnit = OU=Domain Controllers,DC=IMTS,DC=TEST
ForestDnsName = IMTS.TEST
ActiveDirectorySite = Default-First-Site-Name
LogicalProcessors = 2
PhysicalProcessors = 1
HostServerName = RD008CFA118C0A
VirtualMachineName = 9c55d1d2-0fe6-4942-bc49-78d914464b9f
OffsetInMinuteFromGreenwichTime = NULL
LastInventoryDate = NULL
DisplayName = activedirectory.imts.test
InstallDirectory = C:\Program Files\Microsoft Monitoring Agent\Agent\
Success