running script on remote host

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
vvz
Posts: 187
Joined: Wed Oct 30, 2013 5:15 pm

running script on remote host

Post 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
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: running script on remote host

Post 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.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
vvz
Posts: 187
Joined: Wed Oct 30, 2013 5:15 pm

Re: running script on remote host

Post by vvz »

OK, clear enough. Thank you
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: running script on remote host

Post by tmcdonald »

Safe to close the thread?
Former Nagios employee
vvz
Posts: 187
Joined: Wed Oct 30, 2013 5:15 pm

Re: running script on remote host

Post by vvz »

yes, absolutely. Thank you
Locked