Udostępnij za pośrednictwem


How to Query for Rules

Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1, System Center Operations Manager 2007

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 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:

  • Id

  • Name

  • ManagementPackId

  • TargetMonitoringClassId

  • Enabled

  • Category

  • DisplayName

  • Description

  • ConfirmDelivery

  • TimeAdded

  • LastModified

  • Remotable

  • Priority

  • DiscardLevel

  • HasNonCategoryOverride

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

/// <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);
            }

        }
    }
}