You can use rules in Operations Manager 2007 to collect data, such as events, generated by managed objects. Rules can be used instead of monitors to generate alerts when the data that is collected from managed objects does not indicate the health state of the managed objects. You can query for rules by defining criteria in the Microsoft.EnterpriseManagement.Configuration.MonitoringRuleCriteria 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 the performance collection rules that are enabled.

C#  Copy Code
/// <summary> 
/// Query for rules.
/// </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
			// all the rules that are enabled and categorized by 
			// performance collection.
			MonitoringRuleCriteria ruleCriteria =
				new MonitoringRuleCriteria(
				"Enabled = 4 AND Category = 'PerformanceCollection'");

			Console.WriteLine("Querying for data...");
			ReadOnlyCollection<MonitoringRule> monitoringRules =
				mg.GetMonitoringRules(ruleCriteria);

			// Display information about each rule.
			foreach (MonitoringRule rule in monitoringRules)
			{
				Console.WriteLine("Rule name: " + rule.Name);
				Console.WriteLine("Category: " + rule.Category);
				Console.WriteLine("Enabled: " + rule.Enabled.ToString());
				Console.WriteLine("Description: " + rule.Description +
					Environment.NewLine);
		}

	}
}
}

Send comments about this topic to Microsoft.