Page 1 of 1
Event handler
Posted: Tue Aug 20, 2013 11:19 am
by lord_hypnos
Hello,
I want run my own script when service fail so i used this tutorial:
http://assets.nagios.com/downloads/nagi ... ndlers.pdf
My reset_tomcat.sh file:
Code: Select all
#!/bin/bash
SERVICESTATE=$1
SERVICESTATETYPE=$2
if [$SERVICESTATETYPE == 'SOFT']
then exit
fi
case "$SERVICESTATE" in
OK)
exit 0
;;
WARNING)
net rpc service stop SERVICENAME -I IPADDRESS -U USERNAME%PASSWORD
net rpc service start SERVICENAME -I IPADDRESS -U USERNAME%PASSWORD
;;
CRITCAL)
net rpc service stop SERVICENAME -I IPADDRESS -U USERNAME%PASSWORD
net rpc service start SERVICENAME -I IPADDRESS -U USERNAME%PASSWORD
;;
UNKNOWN)
net rpc service stop SERVICENAME -I IPADDRESS -U USERNAME%PASSWORD
net rpc service start SERVICENAME -I IPADDRESS -U USERNAME%PASSWORD
;;
esac
But my problem is that this script is not running when Nagios detect failure service.
Command Management:
Service Management:
Log(How You can see notification is send properly but event is not trigger):
Thank You for answer!
Re: Event handler
Posted: Tue Aug 20, 2013 12:44 pm
by abrist
Lets enable event handler logging, if it is not already enabled. Edit /usr/local/nagios/etc/nagios.conf
Add or edit the log_event_handlers line so that it reads:
Restart nagios:
Are you sure the script is not running? You may want to add an echo-to-file to the top of the script so that you know for sure if it ran or not:
Code: Select all
echo "event handler run" > /tmp/eventhandler.tmp
What are the permissions on your script?
Code: Select all
ls -la /usr/local/nagios/libexec/reset_tomcat.sh
Re: Event handler
Posted: Tue Aug 20, 2013 3:18 pm
by lord_hypnos
abrist wrote:Lets enable event handler logging, if it is not already enabled. Edit /usr/local/nagios/etc/nagios.conf
Add or edit the log_event_handlers line so that it reads:
Restart nagios:
Done.
abrist wrote:
Are you sure the script is not running? You may want to add an echo-to-file to the top of the script so that you know for sure if it ran or not:
Code: Select all
echo "event handler run" > /tmp/eventhandler.tmp
I added but file not created so i think is not ran.
abrist wrote:
What are the permissions on your script?
Code: Select all
ls -la /usr/local/nagios/libexec/reset_tomcat.sh
In Your guide is this code :
and i used it

Also i can run this code via ./reset_tomcat.sh
Is notification enabled is necessary to trigger event handler?
Re: Event handler
Posted: Tue Aug 20, 2013 3:28 pm
by abrist
lord_hypnos wrote:and i used it

Also i can run this code via ./reset_tomcat.sh
Can you run it as the "nagios" user though?
Code: Select all
ls -la /usr/local/nagios/libexec/reset_tomcat.sh
Now that you have logging setup, check the XI Event Log for "external" commands or "events", or just tail/grep the nagios.log.
While testing, it may be advantageous to turn on "volatile" for the service so that the handler is run every check (to see if that file gets written).
EDIT: Are event handlers enabled (set to 1)?
Code: Select all
grep event /usr/local/nagios/etc/nagios.cfg
Re: Event handler
Posted: Wed Aug 21, 2013 3:24 am
by lord_hypnos
abrist wrote:lord_hypnos wrote:and i used it

Also i can run this code via ./reset_tomcat.sh
Can you run it as the "nagios" user though?
Code: Select all
ls -la /usr/local/nagios/libexec/reset_tomcat.sh
I have only root account at this moment. And i ran this script as root.
abrist wrote:
Now that you have logging setup, check the XI Event Log for "external" commands or "events", or just tail/grep the nagios.log.
While testing, it may be advantageous to turn on "volatile" for the service so that the handler is run every check (to see if that file gets written).
Ok it's look like now event handler work properly but still nothing write to /tmp/eventhandler.tmp file. I dont have idea why.
Code: Select all
Event Handler2013-08-13 08:44:05SERVICE EVENT HANDLER: xxx.xxx.xx;HTTP check document;CRITICAL;HARD;5;reset_tomcat
Event Handler2013-08-13 08:44:05GLOBAL SERVICE EVENT HANDLER: xxx.xxx.xx;HTTP check document;CRITICAL;HARD;5;xi_service_event_handler
Service Critical2013-08-13 08:44:05SERVICE ALERT: xxx.xxx.xx;HTTP check document;CRITICAL;HARD;5;Connection refused
Event Handler2013-08-13 08:43:15SERVICE EVENT HANDLER: xxx.xxx.xx;check tomcat session;UNKNOWN;HARD;3;reset_tomcat
Event Handler2013-08-13 08:43:15GLOBAL SERVICE EVENT HANDLER: xxx.xxx.xx;check tomcat session;UNKNOWN;HARD;3;xi_service_event_handler
Service Unknown2013-08-13 08:43:15SERVICE ALERT: xxx.xxx.xx;check tomcat session;UNKNOWN;HARD;3;Tomcat sessions edmsdirect UNKNOWN:
Event Handler2013-08-13 08:43:05SERVICE EVENT HANDLER: xxx.xxx.xx;HTTP check document;CRITICAL;SOFT;4;reset_tomcat
Event Handler2013-08-13 08:43:05GLOBAL SERVICE EVENT HANDLER: xxx.xxx.xx;HTTP check document;CRITICAL;SOFT;4;xi_service_event_handler
Service Critical2013-08-13 08:43:05SERVICE ALERT: xxx.xxx.xx;HTTP check document;CRITICAL;SOFT;4;Connection refused
abrist wrote:
EDIT: Are event handlers enabled (set to 1)?
Code: Select all
grep event /usr/local/nagios/etc/nagios.cfg
Code: Select all
grep event /usr/local/nagios/etc/nagios.cfg
OUTPUT:
Code: Select all
log_event_handlers=1
global_host_event_handler=xi_host_event_handler
global_service_event_handler=xi_service_event_handler
enable_event_handlers=1
event_broker_options=-1
event_handler_timeout=30
EDIT:
All works. Script is triggering now. Thank You so much for help! Again:)
Re: Event handler
Posted: Wed Aug 21, 2013 9:41 am
by slansing
Awesome!