How to Query for Diagnostics
Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1, System Center Operations Manager 2007
Diagnostics allow you to take action on alerts, state changes, and other significant issues that are generated by monitoring objects. You can query for diagnostics by defining criteria in the MonitoringDiagnosticCriteria 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
Accessibility
ManagementPackId
Enabled
TargetMonitoringClassId
MonitorId
ExecuteOnState
Remotable
Category
Timeout
TimeAdded
LastModified
DisplayName
Description
HasNonCategoryOverride
The following code queries for all diagnostics that contain SystemCenter in their name.
/// <summary>
/// Query for diagnostics.
/// </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 diagnostics that contain SystemCenter in their name.
MonitoringDiagnosticCriteria diagnosticCriteria =
new MonitoringDiagnosticCriteria(
"Name LIKE '%SystemCenter%'");
Console.WriteLine("Querying for data...");
ReadOnlyCollection<MonitoringDiagnostic> diagnostics =
mg.GetMonitoringDiagnostics(diagnosticCriteria);
// Display information about each diagnostic.
foreach (MonitoringDiagnostic diagnostic in diagnostics)
{
Console.WriteLine("Diagnostic name: " + diagnostic.Name);
Console.WriteLine("Status: " + diagnostic.Status.ToString());
Console.WriteLine("Category: " + diagnostic.Category);
Console.WriteLine("Description: " + diagnostic.Description +
Environment.NewLine);
}
}
}
}