How to Query for Rules

Updated: January 31, 2012

Applies To: System Center 2012 - Operations Manager

You can use rules in Operations Manager to collect data, such as events, that are 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 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:

  • Id

  • Name

  • ManagementPackId

  • Target

  • Enabled

  • CategoryOld

  • DisplayName

  • Description

  • ConfirmDelivery

  • TimeAdded

  • LastModified

  • Remotable

  • Priority

  • DiscardLevel

  • HasNonCategoryOverride

  • Category

The following code queries for all the performance collection rules that are enabled:

/// <summary> 
/// Query for rules.
/// </summary>
using System;
using System.Collections.Generic;
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.
			ManagementPackRuleCriteria ruleCriteria =
				new ManagementPackRuleCriteria(
				"Enabled = 4 AND Category = 'PerformanceCollection'");

			Console.WriteLine("Querying for data...");
			IList<ManagementPackRule> monitoringRules =

			// Display information about each rule.
			foreach (ManagementPackRule 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 +


See Also