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.

Visual Basic  Copy Code
' 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) = _

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

				If (thisState.Name = "Closed") Then

					closedState = thisState
				End If

			' 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"
				End If
			Console.WriteLine("Closed availability alerts.")
		End Function
	End Class
End Namespace
C#  Copy Code
/// <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 = 

			// Find the "Closed" resolution state that is defined 
			// for this Management Group.
			ReadOnlyCollection<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

Send comments about this topic to Microsoft.