Nagios3 is running on CentOS6.5. in /usr/lib64/nagios/plugins/eventhandlers folder I have a script with a name - asteriks-host-phone-call .
As you can see from the script if host is DOWN, SOFT, 3 (for now) email should be sent (later on we are going initiate asteriks phone call instead)
If I call this script from CLI like: /usr/lib64/nagios/plugins/asteriks-host-phone-call DOWN SOFT 3 I'm getting email, that means script itself and mail programme work properly (I'm receiving standard notificatios for the host also)
Code: Select all
#!/bin/bash
# This script is initiated by host-event-handler
#what state of host?
case "$1" in
OK)
# The host just came back up, don't do anything
;;
UNREACHABLE)
# we don't really know what might be causing an unknown error, don't do anything
;;
DOWN)
# the host has real problem - we need to do something depends of state
# is this a HARD or SOFT state?
case "$2" in
SOFT)
#what check attempt? we don't whant to make a call immediately, so we skip SOFT 1 and 2
case "$3" in
3)
# 3 -means after 3-d check make a call, of course we can change this number
touch ./callismade.txt
sudo echo "THIS MESSAGE FROM EVENTHANDLER" | /bin/mail -s "EVENTHANDLER MESSAGE" [email protected]
#instead of echo command we gonna use linphone command here
;;
esac
;;
HARD)
echo -n "We can place another command here or make another call"
;;
esac
;;
esac
exit 0
Code: Select all
define host {
host_name test-condor-site
alias test-condor-site
address 172.16.37.44
hostgroups condor-site
check_command check-host-alive
max_check_attempts 4
check_interval 1
retry_interval 1
active_checks_enabled 1
check_period 24x7
contact_groups admins
contacts vassiliy;mike,lukasz,frank
notification_interval 2
notification_period 24x7
notification_options d
notifications_enabled 1
event_handler asteriks-host-phone-call
event_handler_enabled 1
}
define service {
host_name test-condor-site
service_description check-host-alive-or-not
check_command check-host-alive
max_check_attempts 4
check_interval 1
retry_interval 1
active_checks_enabled 1
check_period 24x7
contact_groups admins
contacts vassiliy;mike,lukasz,frank
notification_interval 60
notification_period 24x7
notification_options w,u,r,c
notifications_enabled 1
#event_handler asteriks-service-phone-call
#event_handler_enabled 1
}
this is a part of my commands.cfg
I simulate that host is unpingable , using address for host 172.16.37.244 (no host with IP)define command {
command_name asteriks-service-phone-call
command_line /usr/lib64/nagios/plugins/eventhandlers/asteriks-service-phone-call $SERVICESTATE $SERVICESTATETYPE $SERVICEATTEMPT
}
define command {
command_name asteriks-host-phone-call
command_line /usr/lib64/nagios/plugins/eventhandlers/asteriks-host-phone-call $HOSTSTATE $HOSTSTATETYPE $HOSTATTEMPT
}
in my /var/log/messages I have
according to my script on the last line I have to receive email initiated by event_handler, but nothing comesMar 21 13:23:50 callme-crt-billing nagios: INITIAL SERVICE STATE: test-condor-site;check-host-alive-or-not;OK;HARD;1;PING OK - Packet loss = 0%, RTA = 4.71 ms
Mar 21 13:24:40 callme-crt-billing nagios: SERVICE ALERT: test-condor-site;check-host-alive-or-not;CRITICAL;SOFT;1;PING CRITICAL - Packet loss = 100%
Mar 21 13:24:50 callme-crt-billing nagios: HOST ALERT: test-condor-site;DOWN;SOFT;1;PING CRITICAL - Packet loss = 100%
Mar 21 13:24:50 callme-crt-billing nagios: GLOBAL HOST EVENT HANDLER: test-condor-site;DOWN;SOFT;1;asteriks-host-phone-call
Mar 21 13:24:50 callme-crt-billing nagios: HOST EVENT HANDLER: test-condor-site;DOWN;SOFT;1;asteriks-host-phone-call
Mar 21 13:25:40 callme-crt-billing nagios: SERVICE ALERT: test-condor-site;check-host-alive-or-not;CRITICAL;HARD;2;PING CRITICAL - Packet loss = 100%
Mar 21 13:26:10 callme-crt-billing nagios: HOST ALERT: test-condor-site;DOWN;SOFT;2;PING CRITICAL - Packet loss = 100%
Mar 21 13:26:10 callme-crt-billing nagios: GLOBAL HOST EVENT HANDLER: test-condor-site;DOWN;SOFT;2;asteriks-host-phone-call
Mar 21 13:26:10 callme-crt-billing nagios: HOST EVENT HANDLER: test-condor-site;DOWN;SOFT;2;asteriks-host-phone-call
Mar 21 13:27:30 callme-crt-billing nagios: HOST ALERT: test-condor-site;DOWN;SOFT;3;PING CRITICAL - Packet loss = 100%
Mar 21 13:27:30 callme-crt-billing nagios: GLOBAL HOST EVENT HANDLER: test-condor-site;DOWN;SOFT;3;asteriks-host-phone-call
Mar 21 13:27:30 callme-crt-billing nagios: HOST EVENT HANDLER: test-condor-site;DOWN;SOFT;3;asteriks-host-phone-call
On the next check email comes from - notify-host-by-email - command
in my nagios.cfg i have:
Code: Select all
global_host_event_handler=asteriks-host-phone-call
#global_service_event_handler=somecommand
enable_notifications=1
enable_event_handlers=1
All other features of nagios work just perfectly (web-interface, check-commands and so on)