Page 1 of 1
Event Handler
Posted: Fri Jan 24, 2014 9:25 am
by manzoor
Hi,
I am trying to use event handler for check_disk , so that whenever it goes to warning let event handler take care of it.
Its not working as expected. The event handler script not getting executed .
when we call the script manual from the server it executing the handler script on client side
/usr/local/nagios/libexec/check_nrpe -H 10.14.114.47 -c myhandler -a OK
Nothing ------> return from client
when the check_disk command return warning the event handler script on client side is not getting executed.
Regards
Manzoor
Re: Event Handler
Posted: Fri Jan 24, 2014 1:34 pm
by slansing
Can you share your event handler? And your configuration that you are using this on?
Re: Event Handler
Posted: Tue Jan 28, 2014 9:31 pm
by manzoor
Hi,
Server side config
/usr/local/nagios/etc/services.cfg
------------------------------------------
define service{
use generic-service
host_name hostname
service_description Check_disk
check_command check_nrpe!check_disk
event_handler my_eventhandler!$SERVICESTATE$
}
/usr/local/nagios/etc/objects/commands.cfg
--------------------------------------------------------
define command{
command_name my_eventhandler
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c myhandler -a $ARG1$
}
This is my client side configuration.
--------------------------------------------
/usr/local/nagios/etc/nrpe.cfg
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 90% -c 85% -p /dev/sda1
command[myhandler]=/usr/local/nagios/libexec/eventhandlers/rm.sh $ARG1$
event handler script location & permissions
-rwxr-xr-x 1 root root 268 Jan 24 13:48 /usr/local/nagios/libexec/eventhandlers/rm.sh
My handler script is
#!/bin/bash
case "$1" in
OK)
#Do nothing
echo "Nothing"
;;
UNKNOWN)
#Do nothing
;;
WARNING)
find /var/log/tomcat6/ -type f -name xyz -amin +30 | xargs rm -f
echo "DELETED"
;;
CRITICAL)
find /var/log/tomcat6/ -type f -name xyz -amin +30 | xargs rm
;;
esac
The script is to delete the files whose access time is older than 30 minutes in a specified directory.
Regards
Manzoor
Re: Event Handler
Posted: Wed Jan 29, 2014 10:58 am
by scottwilkerson
Make sure your nagios.cfg has
Also add
to your service definition, like this
Code: Select all
define service{
use generic-service
host_name hostname
service_description Check_disk
check_command check_nrpe!check_disk
event_handler_enabled 1
event_handler my_eventhandler!$SERVICESTATE$
}
Re: Event Handler
Posted: Sat Feb 01, 2014 2:21 am
by manzoor
Hi Scott,
No it doesn't work. I made changes in services.cfg and also enable_event_handlers=1 its enabled in nagios.cfg , still doesn't work.
Regards
Manzoor
Re: Event Handler
Posted: Mon Feb 03, 2014 12:20 pm
by abrist
Can you throw some "echos to file" commands to your script. This will allow us to see if it is running at all and dieing, or if it is failing to run at all:
Code: Select all
#!/bin/bash
case "$1" in
OK)
#Do nothing
echo "OK" > /tmp/test.txt
echo "Nothing"
;;
UNKNOWN)
echo "UNKNOWN" > /tmp/test.txt
#Do nothing
;;
WARNING)
echo "WARNING" > /tmp/test.txt
find /var/log/tomcat6/ -type f -name xyz -amin +30 | xargs rm -f
echo "DELETED"
;;
CRITICAL)
echo "CRITICAL" > /tmp/test.txt
find /var/log/tomcat6/ -type f -name xyz -amin +30 | xargs rm
;;
esac
Fire off the event handler by forcing a state change on the object and then check the /tmp/test.txt file for any strings.