How do I set up event handler to restart Windows service

I am new to linux as well as Nagios. I have Nagios set up and it is monitoring a few test servers for some basic services. I have read and read and cannot find how to start a stopped service on Windows Server. I did make sure event handler was enabled, but the documentation refers to scripting the start up of linux services, not Windows. I figured I can create a .bat file to do a simple net start, but how does Nagios run it? Is it something like this? (example of the server service)

define service{
host_name somehost
service_description Server Service
max_check_attempts 4
event_handler restart_server
}

Than for the handler command:
define command{
command_name restart-httpd
(This is where I am unsure. Do I give it a path to the .bat file?)

Is nagios able to run this file from the host PC. In these linux script examples I am unsure if the script is on the Nagios server of the host server. Any help would be awesome. Hopefully I’m close to accurate here.

You can use NRPE/NSClient++ and instead of using it to run remote scripts to check something, use it to restart your services. See

nagios.sourceforge.net/docs/3_0/ … ndows.html
trac.nakednuns.org/nscp/

HTH

/S

Great! I’ll read up on it. Thank you.

OK… it took a while but to configure service starts it appears you need to tweak this in the NSC.ini file? Is this correct. Well I suppose I can just tweak and test and see what happens.

This is still not working. The links provided detail how to set up monitor host services. This works great. However I cannot get the NSCLient++ to actually restart the service. I edited the NSC.INI file to comment out the “check_all_services” section and have the values set to “started” however it still shows the service as stopped and it will not restart it. I am assuming there is a step I am missing in this in some config file somewhere. Any help would be greatly appreciated as I am under a deadline to have this up by this weekend. Management thought this would be easier than it is and gave me two days.

Another question. Is the NSClient++ method of restarting a service seperate from the event handler? Do I need to define a command under the event handler or does NSCLient do it on it’s own?

Use NSclient to monitor services and set an event handler to restart it using check_nrpe… see the documentation on CheckExternalScripts on the nakednuns site

I have been getting different responses depending on who answers which is fine since there seems to be more than one way to solve these issues. I am now using OpMon agent rather than NSClient. I also installed NRPE 2.8 and set it up per the documentation. I still can monitor services, but I can’t get NRPE to restart a service. Here is my windows.cfg:

Define service{

  Use                     generic service

  Host_name               jwilliamspc

  Service_description     PrintSpooler

  Check_command           check_nt!SERVICESTATE!-d SHOWALL

Personally, I use the Event_handler to call a shell script that uses Winexe (eol.ovh.org/winexe/ - Think PSEXEC for Linu:evil: to run “net start [servicename]” on the affected host.

event_handler restart-service!$SERVICESTATE$!$SERVICESTATETYPE$!$SERVICEATTEMPT$![servicename]!$HOSTADDRESS$

The restart-service script executes:

/usr/local/bin/winexe -U “username” --password=“password” --uninstall //$5 “net start $4”