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
Event Handler
-
slansing
- Posts: 7698
- Joined: Mon Apr 23, 2012 4:28 pm
- Location: Travelling through time and space...
Re: Event Handler
Can you share your event handler? And your configuration that you are using this on?
Re: Event Handler
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
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
Make sure your nagios.cfg has
Also add
to your service definition, like this
Code: Select all
enable_event_handlers=1Code: Select all
event_handler_enabled 1Code: 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
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
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
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:
Fire off the event handler by forcing a state change on the object and then check the /tmp/test.txt file for any strings.
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
;;
esacFormer 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.
"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.