I had to use monitor instead of rule (missing expression filtering option in some rule type) but without affecting the object state… well, this is my workaround for this request (part of the script is based on Scotts Moss’s script):
- Creating the monitor
- uncheck the “Automatically resolve the alert when the monitor returns to a health state”
- add the below script as a recover task for the previously created monitor
this powershell script get as a parameter the monitor name. every time alert is generated, the state is being reset for that monitor. change the myRMS.domain.local to your RMS server:
param($monitorName)
$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:”myRMS.domain.local”;
set-location “OperationsManagerMonitoring::”;
$alerts = get-alert | where-object {$_.Severity -eq “Information” -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)}
}
[Update 3/14]
A friend of mine (Shahar Nusbaum) took my old script (which was SCOM 2007 R2 oriented) and updated it to SCOM 2012 oriented, so.. here it is:
param($monitorName)
Import-Module -Name operationsManager
#$monitorName = “test event”
$alerts = get-scomalert | where-object {$_.ResolutionState -eq “0” -and $_.Name -eq “$monitorName”}ForEach($alert in $alerts) {
$monitor = get-ScomMonitor -Id $alert.MonitoringRuleId
Get-SCOMClassInstance -id $alert.MonitoringObjectId | foreach {$_.ResetMonitoringState($monitor)}}
Have fun 🙂
looks very similar to the code I wrote a few years ago and put on SystemCenterCentral.com last year http://www.systemcentercentral.com/tabid/144/IndexId/76934/Default.aspx
Hi, nice article my only problem is doing the filter on the pipe like that causes get-scomalert to run forever, especially in large deployments. It’s much easier to use the criteria param for something like that.
https://gist.github.com/jeffpatton1971/aeee67af3ed8a713101c
This wraps that as a function, and uses criteria to accomplish the same effect. The benefit is since we’re basically doing a query Get-SCOMAlert returns a LOT faster.
Thank you Jeff.
I’m imsrspeed. You’ve really raised the bar with that.