Freigeben über


How to Query for Monitors

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

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

  • Id

  • Name

  • ManagementPackId

  • Accessibility

  • DisplayName

  • Description

  • TargetMonitoringClassId

  • Algorithm

  • AlgorithmParameter

  • MonitoringRelationshipClassId

  • Category

  • MemberMonitorId

  • ParentMonitorId

  • IsUnitMonitor

  • IsInternalRollupMonitor

  • IsExternalRollupMonitor

  • AlertOnState

  • AlertAutoResolve

  • AlertPriority

  • AlertMessage

  • HasNonCategoryOverride

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

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

        }
    }
}