Freigeben über


How to Display Operations Manager Data

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.");
            }
        }
    }
}
' <summary> 
' Displays information about health service alerts 
' that have occurred in the management group.
' </summary>
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Text
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.Administration
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Common
Imports Microsoft.EnterpriseManagement.Monitoring


Namespace SDKSamples
    Class Program
        Public Overloads Shared Function Main(ByVal args() As String) As Integer

            Dim mg As ManagementGroup = New ManagementGroup("localhost")

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

            Dim alertCriteria As MonitoringAlertCriteria = _
                New MonitoringAlertCriteria("Description LIKE '%health service%'")
            Dim alerts As ReadOnlyCollection(Of MonitoringAlert) = _
                mg.GetMonitoringAlerts(alertCriteria)

            If (alerts.Count > 0) Then

                For Each alert As MonitoringAlert 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())
                Next

            Else

                Console.WriteLine("No alerts found.")
            End If


            '-----------------------------------------------------------
            ' Display events.
            Console.WriteLine("Displaying events...")
            Dim eventCriteria As MonitoringEventCriteria = _
                New MonitoringEventCriteria("Number = 187")
            Dim events As ReadOnlyCollection(Of MonitoringEvent) = _
                mg.GetMonitoringEvents(eventCriteria)

            If (events.Count > 0) Then

                For Each OMEvent As MonitoringEvent 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)
                Next

            Else

                Console.WriteLine("No events with number 187 found.")
            End If
        End Function
    End Class
End Namespace

See Also

Tasks

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

Other Resources

Automating Operations Manager Administration