Event Handler

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
manzoor
Posts: 3
Joined: Fri Jan 24, 2014 9:04 am

Event Handler

Post 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
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Event Handler

Post by slansing »

Can you share your event handler? And your configuration that you are using this on?
manzoor
Posts: 3
Joined: Fri Jan 24, 2014 9:04 am

Re: Event Handler

Post 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
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Event Handler

Post by scottwilkerson »

Make sure your nagios.cfg has

Code: Select all

enable_event_handlers=1
Also add

Code: Select all

event_handler_enabled    1
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$
        }
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
manzoor
Posts: 3
Joined: Fri Jan 24, 2014 9:04 am

Re: Event Handler

Post 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
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Event Handler

Post 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.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked