In Operations Manager 2007, monitors can be used to assess various conditions that can occur in monitored objects. For example, a monitor can be used to assess the values of a performance counter, the existence of an event, the occurrence of data in a log file, or the status of a Windows service. The result of this assessment determines the health state of a target and the alerts that are generated.

You can query for monitors by defining criteria in the Microsoft.EnterpriseManagement.Configuration.MonitorCriteria class constructor. The criteria syntax is defined in Criteria Expression Syntax. The following property names are valid names that can be used in the criteria expression:

The following code queries for all state collection monitors that have an alert priority equal to one.

C#  Copy Code
/// <summary> 
/// Query for monitors.
/// </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 the monitors you want to collect.
			MonitorCriteria monitorCriteria =
				new MonitorCriteria(
				"Category = 'StateCollection' AND AlertPriority = 1");

			Console.WriteLine("Querying for data...");
			ReadOnlyCollection<ManagementPackMonitor> monitors =
				mg.GetMonitors(monitorCriteria);

			// Display information about each monitor.
			foreach (ManagementPackMonitor monitor in monitors)
			{
				Console.WriteLine("Monitor name: " + monitor.Name);
				Console.WriteLine("Status: " + monitor.Status.ToString());
				Console.WriteLine("Description: " + monitor.Description +
					Environment.NewLine);
		}

	}
}
}

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