Wednesday, April 08, 2009

Monitoring and automatically restarting services in Zenoss

Now we need to monitor a service - say the Print Spooler - and we want to know when it fails. Actually, since we are lazy and overworked, we want to automatically restart the service, and only be alerted if it doesnt restart.

Monitor a Windows Service
Enabling monitoring of Windows services is quite intuitive, below are the steps needed to setup monitoring.
  1. In the action pane, select Services -- various classes of services will be listed
  2. Select WinService
  3. Find the service you are interested in monitoring (spooler) by paging through the list, or type in the name in the search box to the right
  4. Click the Spooler service and select the Edit tab
  5. Change Monitor to True, click Save

Enable Automatic Restart
This was inspired from http://blog.zenoss.com/2008/03/21/restarting-windows-services-with-zenoss, more help may be available from there if my words dont make sense.

Create a Transform to recognize the event
  1. In the action pane, select Events
  2. Select Status, WinService
  3. Select WinService | More | Transform
  4. Enter the following in the Transform and click Save
#get service name
msg = getattr(evt, "message", None)
#parse the message which looks like this
#Windows Service 'W32Time' is down
if msg:service = msg.split("'")[1]
#make new message now with only service name
#we don’t loose anything since summary is the same message
evt.message = service

Create an Event Manager Command
  1. In the Action pane, under Management select Event Manager and click the Commands tab
  2. Enter the name Start Windows Service and click Add
  3. Click the command just created and change Enabled to True
  4. For Command, enter the following: winexe -U "${dev/zWinUser}%${dev/zWinPassword}" //${dev/manageIp} "net start ${evt/message}"
  5. For the Where clause, enter Event Class | begins with | /Status/WinService (see image below)
  6. Click Save

To test this, simply stop the spooler service on a monitored system - it should automatically restart. If you stop and disable the service, you should recieve an alert.


2 comments:

Paul said...

This is the best blog post I've found on monitoring Windows devices!!! Thanks soo much for posting this!

Anonymous said...

The information here is great. I will invite my friends here.

Thanks