Submitted By: Eric Payne

Internal MOM script that loops through the alerts generated by an alert rule and auto-resolve those alerts.

Visual Basic
Edit|Remove
'#####================================================================================ 
'## Title: AutoResolveAlertsByRule.vbs
'## Author: Eric Payne 
'## Client\Company: xxxx
'## Date: 10/16/2006
'##		
'## Purpose: 
'##		1. Loops through all alerts by passed in Rule name not set to Resolved and resolves them
'##					 
'## Requirements:
'##		1. Mom Script Parameter of "Rule" = The name of rule to search for
'##
'##	Issues: 
'##		1. 
'##		
'##	Revisions:
'##		1.
'##		
'##	To Do Items: 
'##		1. 
'##		2. 
'##		3. 
'##
'## Basic Logic: 
'##		1. Loop Through each alert from alert rule and resolves them
'##		2. 
'##		4. 
'#####================================================================================ 

Dim objAlert
Dim objAlerts
Dim objComputers
Dim objComputer
Dim strQuery
Dim strRule
Dim strComputerGUID
Dim strComputer

Const RESOLVED_STATE = 255

strRule = ScriptContext.Parameters.Get("Rule")

If (ScriptContext.IsEvent()) Then
	Set objEvent = ScriptContext.Event
	strComputer=objEvent.SourceComputer
End If

strQueryComputer= "Select * from MSFT_Computer where Name=""" + strComputer + """"
set objComputers = GetObject("winmgmts:!root\MOM").ExecQuery(strQueryComputer)

for each objcomputer in objComputers
	If Err.Number = 0 Then
		strcomputerguid = objcomputer.guid
	End If
next

strQuery = "select * from MSFT_Alert where RuleGUID=""" + strRule + """"
Set objAlerts = GetObject("winmgmts:!root\MOM").ExecQuery(strQuery)

For Each objAlert In objAlerts
	If Err.Number = 0 Then
		If Not objAlert.ResolutionState=RESOLVED_STATE Then
			set objComputers = objAlert.Associators_(,"MSFT_Computer",,,FALSE,FALSE,,,,null)
			For Each objComputer in objComputers
				If objComputer.GUID=strComputerGUID Then
					objAlert.ResolutionState = RESOLVED_STATE
					objAlert.Put_
				End If
			Next
		End If
	End If
Next