How to create a custom service monitor and automatically restart it
For this little demo, we will be using the Print Spooler service and targeting Windows Operating System
This will target all version of Server and Client OS but I won’t go into rollups here
In SCOM Console
Authoring > Monitors > Create a Monitor > Unit Monitor
Take a look at the varying out of the box options, many different monitor types available.
We select > Basic Service Monitor
Make sure you choose an appropriate Management Pack to save the monitor into.
I recommend having a Custom Management Pack per Imported Management Pack to ensure you don’t cross the streams…
For this demo in my lab I am choosing my capture all monitors management pack
Enter a distinguishable name that meets your naming convention.
Select the Monitor Target
Choose parent monitor
And I recommend you disable the monitor by default
Search and select the class target
Enter the service name or ideally search for it.
Choose the computer name you know has the service you are targeting to get the correct name
The monitor conditions for service monitors are static
Enable the Alerts and Auto resolve.
Check the Alert name and align the priority and severity accordingly
Click Create
Ok, great… The Monitor and Alert is created.
Next is to create the recovery task.
Find the newly created Monitor
notice I have limited my search scope to the management pack object defined in the monitor
Right-click and choose properties.
The pertinent tab is the Diagnostic and Recovery tab
Add > Recovery for critical health state
Choose Run Command
Define the name. Again follow your naming conventions and keep it clear
For this task, I am opting to recalculate monitor state
To start a service, we need to run the ‘net start %servicename%’
Hint: not sure on the command.. run it from cmd on a server with the service… i.e. ‘net start spooler’ is the pertinent command.
Create!
After a moment, the task will appear in the recovery tasks field
Ok…