Share via


How to Resolve Alerts

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

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'");
            IList<MonitoringAlert> alerts = 
                mg.OperationalData.GetMonitoringAlerts(alertCriteria, default(DateTime));

            // Find the "Closed" resolution state that is defined 
            // for this Management Group.
            IList<MonitoringAlertResolutionState> alertStates =
                mg.OperationalData.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.");
        }
    }
}

See Also

Other Resources

Automating Operations Manager Administration