Page 1 of 1

Nagios Event handling not working

Posted: Thu Sep 11, 2014 12:22 am
by arushgiri
Hi ,
I am trying to handle the event when ever the CRITICAL alert is generated as per disk_space

I have done following configurations on Nagios core Monitoring server:

I have set enable_event_handlers=1

contents of hosts.cfg file:

define host{
name linux-box ; Name of this template
use generic-host ; Inherit default values
check_period 24x7
check_interval 1
retry_interval 1
max_check_attempts 3
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
register 0 ; DONT REGISTER THIS - ITS A TEMPLATE
}

the host which i am monitoring through nagios core:

define host{
use linux-box ; Inherit default values from a template
host_name eej758 ; The name we're giving to this server
alias eej758 ; A longer name for the server
address 192.168.219.58 ; IP address of Remote Linux host
}

content of command.cfg :

define command{
command_name myhandler
command_line /usr/local/nagios/libexec/eventhandlers/myhandler.sh $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
}

contents of services.cfg :

define service{
use generic-service ;Name of service template to use
host_name eej758
service_description Remote check disk
check_command check_nrpe!check_hda1!20%!10%!/
notifications_enabled 1
max_check_attempts 3
event_handler myhandler
}

Here myhandler.sh is the script which i have written , this script will execute on monitoring server once the CRITICAL Alert is received and will start the VM on remote host through ssh . this script will run when the CRITICAL alert will received 1st time , ie, servicestate=CRITICAL, servicestatetype=SOFT, serviceattempt=1

content of myhandler.sh:
#!/bin/sh
#event handler script to start VM

case "$1" in

OK)

;;
WARNING)

;;
UNKNOWN)

;;
CRITICAL)
case "$2" in

SOFT)

case "$3" in

1)

echo "Starting VM3 on 58 machine"
ssh 192.168.219.58 'mkdir /usr/local/nagios/vmstarted'
ssh 192.168.219.58 'virsh start EEJ758-Node3'
;;
esac

esac
esac
exit 0

After all this configuration event handling is not working. when i run this script manually , the script is working fine. Please help me regarding this issue.

Re: Nagios Event handling not working

Posted: Thu Sep 11, 2014 5:08 pm
by Box293
When you are running the script manually, are you doing this as the nagios user?

Code: Select all

su nagios
myhandler.sh blah blah blah