Udostępnij za pośrednictwem


How to Display Operations Manager Data

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.]

By using the Operations Manager class libraries, you can programmatically access operations data, such as alert, event, and performance data, that is stored in the Operations Manager database. 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%'");
            IList<MonitoringAlert> alerts =
                mg.OperationalData.GetMonitoringAlerts(alertCriteria, default(DateTime));

            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");
            IList<MonitoringEvent> events = 
                mg.OperationalData.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

Tasks

How to Resolve Alerts
How to Insert Custom Event and Performance Data

Other Resources

Automating Operations Manager Administration