Blog
By Scott Moss on 6/8/2009 9:23:15 PM • Rank (2783) • Views 3096
0

0

I've been messing around with this one for a few months and wanted to share this. This code will get a list of all alerts that are closed that were created by a monitor, that are older than 1 day, and reset the monitor that created the alert. Before running this script I would suggest getting a count of what your going to be resetting , so you've got an idea how long this script might take to run.

#get an idea how many alerts are in this state

$targetdate = (get-date).AddDays(-1)

(Get-Alert -criteria 'ResolutionState = ''255'' AND IsMonitorAlert = ''True'''| Where-Object {$_.LastModified -gt $targetdate }).count

 

# script

# targetdate or cut off date which is the past 1 day or 24 hours
$targetdate = (get-date).AddDays(-1)
# get closed alerts created by a monitor whose lastmodified is greater than the targetdate
$alerts = Get-Alert -criteria 'ResolutionState = ''255'' AND IsMonitorAlert = ''True'''| Where-Object {$_.LastModified -gt $targetdate }

ForEach($alert in $alerts) {
$mon = get-monitor -criteria "Id = '$($alert.MonitoringRuleId)'"
$mc = get-monitoringClass -id $alert.MonitoringClassId
$mc | get-monitoringObject -criteria "Id = '$($alert.MonitoringObjectId)'" | foreach {$_.ResetMonitoringState($mon)}
}

Comments (2) - Comment RSS
kobile wrote: on Dec 07, 2009 05:21 AM
Hi, is there a way to reset a specific monitor, like "logical disk free space" ?
leu21 wrote: on Jan 11, 2012 05:55 AM
kobile:

use next script with own name for $monitorName


$monitorName = 'Health Service Heartbeat Failure'

$checkSnap = Get-PSSnapin | Where-Object {$_.name -eq “Microsoft.EnterpriseManagement.OperationsManager.Client”}
if ($checkSnap.name -ne “Microsoft.EnterpriseManagement.OperationsManager.Client”)
{
add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”;
}
new-managementGroupConnection -ConnectionString:”spscom51.vesta-trading.com”;
set-location “OperationsManagerMonitoring::”;
$alerts = get-alert | where-object {$_.Severity -eq “Error” -and $_.ResolutionState -eq “0" -and $_.Name -eq “$monitorName”}

ForEach($alert in $alerts) {
$monitor = get-monitor -criteria “Id = '$($alert.MonitoringRuleId)'”
$moncls = get-monitoringClass -id $alert.MonitoringClassId
$moncls| get-monitoringObject -criteria “Id = '$($alert.MonitoringObjectId)'” | foreach {$_.ResetMonitoringState($monitor)}
}


Who Viewed
Who Reviewed
Categories
Related Pages
Shortened URL
http://tinyurl.com/yhjev6s

Top Contributors
Featured Members
Pete Zerger
Points: 65622
Level: System Center Expert
Tommy Gunn
Points: 42748
Level: System Center Expert
Simon Skinner
Points: 40804
Level: System Center Expert
Stefan Koell
Points: 28999
Level: System Center Expert
Andreas Zuckerhut
Points: 27734
Level: System Center Expert