Post SCOM Alerts to a REST endpoint
Extracting all SCOM Alerts for a REST Post
I wrote a quick script the other day to pull some SCOM Alert data for testing and thought I'd share a summarized version for anyone looking for easy options to extract their SCOM data.
The below sample script pulls all of the SCOM Alerts from your Management Group and pushes them via REST to a specified endpoint. Using the Operations Manager module makes this pretty quick and painless. I've called out a couple of easy tweaks you can make below to the script itself.
# Import the Operations Manager module Import-Module OperationsManager # Get all the alerts to send up to the REST destination. You can optionally filter at this point $alerts = Get-SCOMAlert # Set the destination URI for our REST POST $RESTUri = "webserver01.cookdown.local/myapp" # This example does an individual POST for each alert foreach($alert in $alerts){ # Select only the properties we need to post for simplicity $alertProperties = $alert | Select Name, Description, MonitoringObjectDisplayName, MonitoringObjectPath # Using ConvertTo-Json we'll change our new object into a JSON string $JSONpayload = $alertProperties | ConvertTo-Json -Compress # Post this to the set endpoint, if authentication headers are needed your can pass them in too Invoke-RestMethod -Method Post -Uri $RESTUri -Body $JSONpayload #-Headers $AuthenticationHeaders }
Easy Tweaks
Add a filter to Get-SCOMAlert to get only specific alerts
Modify the Select on line 14 to send additional properties
Add authentication headers to line 20 by removing the commented line
Good luck with your scripting, if you're trying to send data to ServiceNow don't forget to reach out for a free trial of our ServiceNow Connector!