Nagios Event Handlers

Restarting-Linux-Services-With-NRPE
https://assets.nagios.com/downloads/nagiosxi/docs/Restarting-Linux-Services-With-NRPE.pdf

At each monitored server
————————
Add this line to /usr/local/nagios/etc/nrpe.cfg :
command[service_restart]=sudo service $ARG1$ restart 2>&1

And give nagios permissions to execute service
echo “nagios ALL = NOPASSWD: `which service`” > /etc/sudoers.d/nagios

At the Nagios XI server
———————–
– Test with
/usr/local/nagios/libexec/check_nrpe -H 10.25.13.34 -c service_restart -a apache2
– add these contents to /usr/local/nagios/libexec/service_restart.bash
#!/bin/bash
case “$1” in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
/usr/local/nagios/libexec/check_nrpe -H “$2” -c service_restart -a “$3”
;;
esac
exit 0

– set permissions
chown apache:nagios /usr/local/nagios/libexec/service_restart.bash
chmod 775 /usr/local/nagios/libexec/service_restart.bash

-test
/usr/local/nagios/libexec/service_restart.sh CRITICAL 10.25.13.34 apache2

– Create a “command” in the core config mannager with this command line:
$USER1$/service_restart.sh $SERVICESTATE$ $HOSTADDRESS$ $_SERVICESERVICE$
Also select “misc_command” from command type

– Update a service adding the event handler

– in the misc settings add a “free variable”
_SERVICE apache2

Read:
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/eventhandlers.html#example
http://www.techadre.com/content/nagios-event-handler-restart-remote-service

Nagios event handlers for NRPE


https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/objecttricks.html