A Microsoft.EnterpriseManagement.Monitoring.MonitoringObject represents an instance of a Microsoft.EnterpriseManagement.Configuration.MonitoringClass that is defined in a Management Pack. You can query Operations Manager to obtain the existing monitoring objects in a Management Group. You can query for Monitoring Objects by defining criteria in the Microsoft.EnterpriseManagement.Monitoring.MonitoringObjectCriteria class constructor. The criteria syntax is defined in Criteria Expression Syntax.

The following code queries for all computers in an error state that are running Windows Server 2003.

C#  Copy Code
/// <summary> 
/// Query for all computers in an error state that are running Windows Server 2003.
/// </summary>
using System;
using System.Collections.ObjectModel;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Monitoring;

namespace SDKSamples
{
	class Program
	{
		static void Main(string[] args)
		{
			ManagementGroup mg = new ManagementGroup("localhost");

			// The criteria specifies that you want to collect
			// computers running Windows Server 2003.
			MonitoringClassCriteria classCriteria =
				new MonitoringClassCriteria("Name = 'Microsoft.Windows.Server.2003.Computer'");

			// There should only be one item in the monitoringClasses collection.
			ReadOnlyCollection<MonitoringClass> monitoringClasses =
				mg.GetMonitoringClasses(classCriteria);

			// The criteria specifies that you want to collect
			// all the monitoring objects (computers running Windows Server 2003) in an error state.
			MonitoringObjectCriteria objectCriteria =
				new MonitoringObjectCriteria(
				"HealthState = 3", monitoringClasses[0]);

			Console.WriteLine("Querying for data...");
			ReadOnlyCollection<MonitoringObject> objects =
				mg.GetMonitoringObjects(objectCriteria);

			// Display information about each object.
			foreach (MonitoringObject monitoringObject in objects)
			{
				Console.WriteLine("Object name: " + monitoringObject.DisplayName);
				Console.WriteLine("Health State: " + monitoringObject.HealthState.ToString());
				Console.WriteLine("Last Modified: " + monitoringObject.LastModified +
					Environment.NewLine);
		}
	}
}
}

Send comments about this topic to Microsoft.
[an error occurred while processing this directive]