Windows Service Restart On Critical Alert.

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
kubben
Posts: 19
Joined: Thu Jun 21, 2012 3:15 pm

Windows Service Restart On Critical Alert.

Post by kubben »

Here's my scenario.

I've just read over http://library.nagios.com/library/produ ... -nagios-xi

Which is great for monitoring a service and restarting it when it has stopped, but what what i am doing, is monitoring a directory, which is acting as a spool directory for a Fax Software, which alerts on a file count.

What i need to do, is, when a critical alert is met, aka the above alert is fired, i need the event handler to restart a specific service on the host.

would this be done in the same way? I actually need an answer on this.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Windows Service Restart On Critical Alert.

Post by slansing »

Yes It would be done in the same fashion, in the documentation it cites where you need to replace the example service text with a service of your choice. :)
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Windows Service Restart On Critical Alert.

Post by scottwilkerson »

This would be done in the exact same way, the only exception is you wouldn't run the wizard on page 3 you would just add this event handler to your service that is checking the file count.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
CGraham
Posts: 115
Joined: Tue Aug 16, 2011 2:43 pm

Re: Windows Service Restart On Critical Alert.

Post by CGraham »

If this is a windows server, I have two recommendations:

1. Add a sleep into your script between the stop and start. Easiest way to do this is by pinging the loopback:

Code: Select all

:: Waiting 10 Seconds
echo Waiting 10 seconds >>%LOGFILE%
ping -n 11 -w 1000 127.0.0.1 >nul
echo Finished waiting 120 seconds >>%LOGFILE%
2. Add logging.

Code: Select all

SET LOGFILE=restart.log
Then put " >>%LOGFILE%" at the end of every command.

Actually these hold true for Linux too, but are accomplished differently.

EDIT: Additionally, I've added " >> /usr/local/nagios/var/restart.log" into my servicerestart.sh command to log those too.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Windows Service Restart On Critical Alert.

Post by slansing »

The logfile would be a good addition, though what is being done is quite simple I suppose it depends on the complexity of what is being done. As far as the sleep timer goes, in my experience the script has waited for the previous command to finish before issuing the next, unless the sleep was for something in addition to that. Time to go fiddle around with your ideas :)
Locked