Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

How to Display Operations Manager Data

System Center

Updated: May 22, 2009

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

By using the Operations Manager class libraries, you can programmatically access operations data that is stored in the Operations Manager database (such as alert, event, and performance data). You can use criteria classes to narrow the search results when you are accessing operations data. For example, you can use the MonitoringEventCriteria class to narrow the search results for event data and the MonitoringAlertCriteria class to narrow the search results for alert data.

Example

The following example demonstrates how to display information about health service alerts that are stored in the Operations Manager database. The example also shows how to display information about stored events that are numbered 187.

/// <summary> 
/// Displays information about health service alerts 
/// that have occurred in the management group.
/// </summary>
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Administration;
using Microsoft.EnterpriseManagement.Common;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Monitoring;
using System.Text;

namespace SDKSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementGroup mg = new ManagementGroup("localhost");

            //-----------------------------------------------------------
            // Display alerts.
            Console.WriteLine("Displaying alert data...");

            MonitoringAlertCriteria alertCriteria = 
                new MonitoringAlertCriteria("Description LIKE '%health service%'");
            ReadOnlyCollection<MonitoringAlert> alerts = 
                mg.GetMonitoringAlerts(alertCriteria);

            if (alerts.Count > 0)
            {
                foreach (MonitoringAlert alert in alerts)
                {
                    Console.WriteLine();
                    Console.WriteLine("Name: " + alert.Name);
                    Console.WriteLine("Description: " + alert.Description);
                    Console.WriteLine("Severity: " + alert.Severity.ToString());
                    Console.WriteLine("Resolution state: " + alert.ResolutionState.ToString());
                }
            }
            else
            {
                Console.WriteLine("No alerts found.");
            }


            //-----------------------------------------------------------
            // Display events.
            Console.WriteLine("Displaying events...");
            MonitoringEventCriteria eventCriteria = 
                new MonitoringEventCriteria("Number = 187");
            ReadOnlyCollection<MonitoringEvent> events = 
                mg.GetMonitoringEvents(eventCriteria);

            if (events.Count > 0)
            {
                foreach (MonitoringEvent OMEvent in events)
                {
                    Console.WriteLine();
                    Console.WriteLine("Number: " + OMEvent.Number.ToString());
                    Console.WriteLine("Description: " + OMEvent.Description);
                    Console.WriteLine("Channel: " + OMEvent.Channel);
                    Console.WriteLine("Computer: " + OMEvent.LoggingComputer);
                }
            }
            else
            {
                Console.WriteLine("No events with number 187 found.");
            }
        }
    }
}

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.