OpsMgr Powershell: Reset monitoring state of closed alerts in PowerShell

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)}
}

0 thoughts on “OpsMgr Powershell: Reset monitoring state of closed alerts in PowerShell

  1. leu21

    kobile:<br /><br />use next script with name your name $monitorName<br /><br /><br /> $monitorName = ‘Health Service Heartbeat Failure'<br /> <br />$checkSnap = Get-PSSnapin | Where-Object {$_.name -eq “Microsoft.EnterpriseManagement.OperationsManager.Client”}<br /> if ($checkSnap.name -ne “Microsoft.EnterpriseManagement.OperationsManager.Client”)<br /> {<br /> add-pssnapin “Microsoft.EnterpriseManagement.OperationsManager.Client”;<br /> }<br /> new-managementGroupConnection -ConnectionString:”scomserver.local.com”;<br /> set-location “OperationsManagerMonitoring::”;<br /> $alerts = get-alert | where-object {$_.Severity -eq “Error” -and $_.ResolutionState -eq “0&quot; -and $_.Name -eq “$monitorName”}<br /> <br />ForEach($alert in $alerts) {<br /> $monitor = get-monitor -criteria “Id = ‘$($alert.MonitoringRuleId)’”<br /> $moncls = get-monitoringClass -id $alert.MonitoringClassId<br /> $moncls| get-monitoringObject -criteria “Id = ‘$($alert.MonitoringObjectId)’” | foreach {$_.ResetMonitoringState($monitor)}<br /> }<br />

  2. leu21

    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)}
    }

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.