How to restart a service through nagios

Hi guys,

Want to know,whether we can restart the service of a remote host through nagios or not…

Like,if some service of a host is critical for some time period,can nagios restart that service ???

Thanks in advance…

Yes, using “event handlers”. Take a look at nagios.sourceforge.net/docs/3_0/ … dlers.html

Strides thanks for ur quick reply…
But I am asking about restarting a remote host’s service.The page explains about restarting a local service,isn’t it ???
So pls…can u guide ???

Sure. You are going to be using some method to check the remote services in the first place, nominally nsclient++ for windows of NRPE for *nix or similar. As you can use NRPE (or the NRPE functionality built into nsclient++) to create custom checks using scripts local on the box, you can also use it to create custom scripts to restart a service in exactly the same manner, you just need to define the command objects and configure NRPE appropriately to run it on the remote server. So you will need to…

[list]Get NRPE (or the nsclient++ NRPE daemon) working if you haven’t already[/list:u][list]Write your script on the remote server to restart the service[/list:u][list]Configure NRPE to fire the script when called by nagios[/list:u][list]Write your event handler script to call the remote restart script via NRPE when the service fails[/list:u]
You can find more info on NRPE here - nagios.sourceforge.net/docs/nrpe/NRPE.pdf

Hopefully that will set you on the right path

/S

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”

That looks like a jolly good way to achieve the results, thanks for posting.

[quote=“Spad”]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”[/quote]

Hi. When I tried to start Nagios tell me that restart-service is not define anywhere. Do I have to put a restart-service.sh in libexec dir? And modify commands.cfg adding

define command{
command_name restart-service
command_line !$SERVICESTATE$!$SERVICESTATETYPE$!$SERVICEATTEMPT$![servicename]!$HOSTADDRESS$
}

I’m not sure that i’ve understand all … :wink: sorry and thanks for ur help