How to Resolve Alerts

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

The Operations Manager class libraries can be used to view and update the properties of operations data. For example, you can change the resolution state of one or more alerts.

Example

The following example demonstrates how to set the resolution state of database monitoring alerts in the Operations Manager database. The example selects only those alerts that are related to the database's availability health. The example then checks the resolution state of each alert that is found; if the resolution state is not already set to "Closed," the example changes the alert's resolution state and adds a comment to the alert's history.

/// <summary>
/// Sets the resolution state of alerts related to database 
/// availability to "Closed".
/// </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");

            Console.WriteLine("Resolving alerts...");
            // Get database availability alerts.
            MonitoringAlertCriteria alertCriteria = new MonitoringAlertCriteria(
                "Name LIKE '%DBStatusMonitor' AND Category = 'AvailabilityHealth'");
            ReadOnlyCollection<MonitoringAlert> alerts = 
                mg.GetMonitoringAlerts(alertCriteria);

            // Find the "Closed" resolution state that is defined 
            // for this Management Group.
            ReadOnlyCollection<MonitoringAlertResolutionState> alertStates =
                mg.GetMonitoringAlertResolutionStates();
            MonitoringAlertResolutionState closedState = null;
            foreach (MonitoringAlertResolutionState thisState in alertStates)
            {
                if (thisState.Name == "Closed")
                {
                    closedState = thisState;
                }
            }

            // Close all alerts not already in the "Closed" resolution state.
            foreach (MonitoringAlert a in alerts)
            {
                if (a.ResolutionState != closedState.ResolutionState)
                {
                    a.ResolutionState = closedState.ResolutionState;
                    string comment = "closing availability alert";
                    a.Update(comment);
                }
            }
            Console.WriteLine("Closed availability alerts.");
        }
    }
}
' Sets the resolution state of alerts related to database 
' availability to "Closed".
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.Configuration.IO
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")

            Console.WriteLine("Resolving alerts...")
            ' Get database availability alerts.
            Dim alertCriteria As MonitoringAlertCriteria = New MonitoringAlertCriteria( _
                "Name LIKE '%DBStatusMonitor' AND Category = 'AvailabilityHealth'")
            Dim alerts As ReadOnlyCollection(Of MonitoringAlert) = _
                mg.GetMonitoringAlerts(alertCriteria)

            ' Find the "Closed" resolution state that is defined 
            ' for this Management Group.
            Dim alertStates As ReadOnlyCollection(Of MonitoringAlertResolutionState) = _
                mg.GetMonitoringAlertResolutionStates()
            Dim closedState As MonitoringAlertResolutionState = Nothing
            For Each thisState As MonitoringAlertResolutionState In alertStates

                If (thisState.Name = "Closed") Then

                    closedState = thisState
                End If
            Next

            ' Close all alerts not already in the "Closed" resolution state.
            For Each a As MonitoringAlert In alerts

                If (a.ResolutionState <> closedState.ResolutionState) Then

                    a.ResolutionState = closedState.ResolutionState
                    Dim comment As String = "closing availability alert"
                    a.Update(comment)
                End If
            Next
            Console.WriteLine("Closed availability alerts.")
        End Function
    End Class
End Namespace

See Also

Other Resources

Automating Operations Manager Administration