How to Resolve Alerts

Updated: January 31, 2012

Applies To: System Center 2012 - Operations Manager

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.


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 =
			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";
			Console.WriteLine("Closed availability alerts.");

See Also