Page 1 of 1

running script on remote host

Posted: Wed May 14, 2014 1:51 pm
by vvz
Hello!
I have a remote host with a service (it's named -smg) running on it. It is critical to receive alerts wether this service sending some (OUT) messages to another host.
The service has its own log file has to be checked for "OUT:" records every 1 minute.
I've installed check_timed_logs.pl from Nagios site and it works - checks for records every one minute, number of hits (OUT records) for previous minute.

Now I have an idea - let's say check if log file has OUT records for the last 2 minutes. If not - restart smg service on remote host (no notifications yet), check 2 minutes more. If still no OUT records in log file - send notifications for manual intervation.

Now I can see 2 possible ways to do that:

1. make a script running on remote host via cron (for checking status and restarting service, if needed) and use NSCA to send service status to nagios server when manual intervation needed. Nagios will send notifications.

2. on nagios server create service definition like this:

Code: Select all

define service{
host_name smg1
service_description check_smg_service_running
check_command check_smg
contact_groups admins
max_check_attempts 4
event_handler restart-smg-service
}
create command in commands.cfg

Code: Select all

define command{
command_name restart-smg-service
command_line /path/to/event-handler-script.sh $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ $HOSTADDRESS$ $HOSTDOWNTIME$ $SERVICEDOWNTIME$
}
on remote host put in event-handler-script with a line like this:

Code: Select all

sudo /sbin/service smg restart
and according to /path/to/event-handler-script.sh in commands.cfg

Actually I have 2 questions: 1. Which way would you recommend me to use?
2. Will 2-nd way work as described or not? will nagios run script on remote host or I have to use nrpe?


Thank you

Re: running script on remote host

Posted: Thu May 15, 2014 11:29 am
by sreinhardt
You would need some way within your event handler or an existing plugin\agent like nrpe or check_by_ssh to kick off that remote script. Otherwise either option definitely could work, but I would go the route of option 1. Having this entirely contained within that remote host as a passive check that only sends when there is an error is going to be much more manageable for you, than having to deal with storing what happened last check and doing some form of pseudo dynamic event handling as well.

Re: running script on remote host

Posted: Thu May 15, 2014 11:32 am
by vvz
OK, clear enough. Thank you

Re: running script on remote host

Posted: Thu May 15, 2014 4:12 pm
by tmcdonald
Safe to close the thread?

Re: running script on remote host

Posted: Thu May 15, 2014 4:15 pm
by vvz
yes, absolutely. Thank you