Powershell command/script to reset the healthstate of a monitor
I need to reset the healthstate of certain alerts (DB Space) daily to get worked on accordingly. I put a Powershell to close the alert, but no new alert as the state is still in critical. We do have the GUI to reset the status, I need to similar one on Powershell ot commans line, so that I can schedule it automatically when I close the alerts.
April 2nd, 2011 2:09am

Hi

"I need to similar one on Powershell ot commans line, so that I can schedule it automatically when I close the alerts."

It isn't good practice to set the alert state of monitors to closed - if you reset the health then alert state will automatically resolve. Scott Moss gives some powershell code here:

http://systemcentercentral.com/downloads/downloadsdetails/tabid/144/indexid/76934/default.aspx

More generically, when looking to automate this type of functionality:

- use IsMonitorAlert to determine if the alert is generated by a monitor.

-- If it isn't (ie it is generated by a rule) then you can close the alert.

-- If it is generated by a monitor then reset health

More helpful code here:

http://www.systemcentercentral.com/BlogDetails/tabid/143/indexid/78922/Default.aspx

Good Luck

Graham

Free Windows Admin Tool Kit Click here and download it now
April 2nd, 2011 12:31pm

http://blogs.technet.com/b/ken_brumfield/archive/2010/06/23/making-the-world-greener-one-monitor-at-a-time-_2d00_-reset-scom-monitors-enmasse.aspx

This links to a script or the "greenmachine" which is a bit of a bruteforce approach. or: http://blogs.msdn.com/b/mariussutara/archive/2009/02/02/how-to-reset-monitor-when-closing-alert.aspx to reset on cl

April 2nd, 2011 12:33pm

Hi

Try the following

$RMS = TestSCOMServer

## Connect to Management Group 
# Initialise Snap-in
# Initialise Snap-in


if ((Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.EnterpriseManagement.OperationsManager.Client'}) -eq $null) { 
  Write-Host 
  Write-Host "File loaded." 
  Write-Host "Initializing shell for operations manager..." 
  Write-Host "Add Microsoft.EnterpriseManagement.OperationsManager.Client snap in." 
  Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client -ErrorAction SilentlyContinue -ErrorVariable Err

  if ($Err) { $(throw write-Host $Err) } 
} 

if ((Get-ManagementGroupConnection | Where-Object {$_.ManagementServerName -eq $RMS}) -eq $null) { 
  Write-Host "Connect to Management Server: $RMS" 
  New-ManagementGroupConnection $RMS -ErrorAction SilentlyContinue -ErrorVariable Err 
  if ($Err) { $(throw write-Host $Err) } 
} 

if ((Get-PSDrive | Where-Object {$_.Name -eq 'Monitoring'}) -eq $null) { 
  Write-Host "Create Monitoring drive from Provider." 
  New-PSDrive -Name: Monitoring -PSProvider: OperationsManagerMonitoring -Root: \ -ErrorAction SilentlyContinue -ErrorVariable Err

  if ($Err) { $(throw write-Host $Err) } 
  Write-Host "Operations manager shell initialized." 
  Write-Host 
} 

Set-Location Monitoring:\$RMS 

$alerts = Get-Alert -criteria 'Name = ''Microsoft.SQLServer.2008.AgentJob.JobLastRunState'' AND IsMonitorAlert = ''True'''

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


You'll need to set the RMS at the top of the script.

And the Name in the script is the name of the ALERT (not the name of the monitor).

Give a try in a TEST environment and let us know if it meets your needs or if it needs a tweak.

Cheers

Graham

 

Free Windows Admin Tool Kit Click here and download it now
April 2nd, 2011 6:46pm

 

In addition, I would like to share the following with you for your reference:

 

OpsMgr Powershell: Reset monitoring state of closed alerts in PowerShell

http://systemcentercentral.com/BlogDetails/tabid/143/IndexID/19345/Default.aspx

Please Note: Since the website is not hosted by Microsoft, the link may change without notice. Microsoft does not guarantee the accuracy of this information.

 

Hope this can give you some hints.

 

Thanks.

April 5th, 2011 10:03am

Great.. it worked .....
Free Windows Admin Tool Kit Click here and download it now
April 21st, 2011 1:46am

Hi,

 

Thank you for your feedback. I am glad to know it works.

 

In the future, if you experience any issues regarding our products or if you have any feedbacks, you are also welcome to post a new thread in our forum. It is always our pleasure to be of assistance.

 

Have a nice day!

April 21st, 2011 11:58am

Hi Nicholas,

The last 3 lines are not working for me.

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

I am not getting anything in $mon.

can you please suggegst on this.?

Free Windows Admin Tool Kit Click here and download it now
May 28th, 2013 11:25pm

For future references I uploaded a script that resets the monitors that triggered the alerts.

Powershell: Reset SCOM Monitors automatically based on generated alerts

January 30th, 2015 12:31am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics