How to Query for Monitors
Updated: January 31, 2012
Applies To: System Center 2012 - Operations Manager
In Operations Manager, monitors can be used to assess various conditions that can occur in monitored objects. For example, you can use a monitor 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.ManagementPackMonitorCriteria 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
-
Target
-
Algorithm
-
AlgorithmParameter
-
RelationshipType
-
CategoryOld
-
MemberMonitor
-
ParentMonitorId
-
IsUnitMonitor
-
IsInternalRollupMonitor
-
IsExternalRollupMonitor
-
AlertOnState
-
AlertAutoResolve
-
AlertPriority
-
AlertMessage
-
HasNonCategoryOverride
-
TimeAdded
-
LastModified
-
Category
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.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 the monitors you want to collect. ManagementPackMonitorCriteria monitorCriteria = new ManagementPackMonitorCriteria( "Category = 'StateCollection' AND AlertPriority = 1"); Console.WriteLine("Querying for data..."); IList<ManagementPackMonitor> monitors = mg.Monitoring.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); } } } }