Share via


How to Query for Diagnostics

Applies To: System Center 2012 - Operations Manager

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

You can use diagnostics 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 Microsoft.EnterpriseManagement.Configuration.ManagementPackDiagnosticCriteria 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

  • Target

  • Monitor

  • ExecuteOnState

  • Remotable

  • CategoryOld

  • Timeout

  • TimeAdded

  • LastModified

  • DisplayName

  • Description

  • HasNonCategoryOverride

  • Category

The following code queries for all diagnostics that contain SystemCenter in their name:

/// <summary> 
/// Query for diagnostics.
/// </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 diagnostics that contain SystemCenter in their name.
            ManagementPackDiagnosticCriteria diagnosticCriteria =
                new ManagementPackDiagnosticCriteria(
                "Name LIKE '%SystemCenter%'");

            Console.WriteLine("Querying for data...");
            IList<ManagementPackDiagnostic> diagnostics =
                mg.Monitoring.GetDiagnostics(diagnosticCriteria);

            // Display information about each diagnostic.
            foreach (ManagementPackDiagnostic 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);
            }
        }
    }
}

See Also

Concepts

Operations Manager Data Queries Overview