event-handler

Jasmine jasmine.chua at securecirt.com
Tue Jul 1 12:32:22 CEST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi 

I want to be able to schedule downtime automatically between 9-7am everyday, 
as this particular host will go down during this time. 
I am wondering why my event-handler is not working. If anyone can point out 
where did I go wrong or improve on my scripts, it will be most helpful for 
me! 

In my nagios.log shows the following and that's it:

[1057051481] HOST ALERT: hostABC;DOWN;SOFT;1;PING CRITICAL - Packet loss=100%
[1057051481]HOSTEVENTHANDLER:hostABC;DOWN;SOFT;1;check-handle-host-downtime-event
[1057051495] HOST ALERT: hostABC;DOWN;SOFT;2;PING CRITICAL - Packet loss =100%
[1057051495]HOSTEVENTHANDLER:hostABC;DOWN;SOFT;2;check-handle-host-downtime-event
[1057051509] HOST ALERT: hostABC;DOWN;HARD;3;PING CRITICAL - Packet loss =100%
[1057051509] HOST NOTIFICATION: admin;hostABC;DOWN;host-notify-by-email;PING\ 
CRITICAL - Packet loss = 100%
[1057051510]HOSTEVENTHANDLERhostABC;DOWN;HARD;3;check-handle-host-downtime-event

When executing the script manually :
/usr/nagios/libexec/handle-host-downtime-event DOWN HARD 

It will put this into nagios.log:

[1057052632] Warning: Unrecognized external command -> EXTERNAL COMMAND: 
SCHEDULE_HOST_DOWNTIME; hostABC;1057052631;105708863
1;600;36000;nagios;The modem and firewall are switched from 9-7 am everyday!

These are the permissions of my scripts.
# ls -l /usr/nagios/libexec/handle-host-downtime-event
- -rwxr-xr-x    1 nagios   nagios        296 Jul1 09:29
handle-host-downtime-event

# handle-host-downtime-event
#!/bin/sh

# Location of the event handlers
eventhandlerdir="/usr/nagios/libexec/eventhandlers"
# Only take action on hard host states...
case "$2" in
HARD)
        case "$1" in
        DOWN)
                # The host has been scheduled downtime!
                `$eventhandlerdir/enable_downtime.sh`

        ;;
        esac
;;
esac
exit 0

# ls -l /usr/nagios/libexec/eventhandlers/enable_downtime.sh
- -rwxr-xr-x    1 nagios   nagios        721 Jul  1 09:31 
eventhandlers/enable_downtime.sh


#!/bin/sh

echocmd="/bin/echo"
CommandFile="/var/nagios/rw/nagios.cmd"

# get the current date/time since UNIX epoch and add till the downtime ends 
#(seconds).
currentsecs=`date +%s`
secs=`date +%s`
let "secs += 36000"

# get the localtime current hour
currenthour=`date +%s | perl -pe 's/(\d+)/localtime($1)/e' | cut -f 5 -d " "|\ 
cut -f 1 -d ":"`

# create the command line to add to the downtime file
cmdline="[$currentsecs] EXTERNAL COMMAND: SCHEDULE_HOST_DOWNTIME;\ 
hostABC;$currentsecs;$secs;600;36000;nagios;The modem and firewall are\ 
switched from 9-7 am everyday!"

# grab the hour to check if it is 9pm and append the commandfile
if [ "$currenthour" == 09 ]; then `$echocmd $cmdline >> $CommandFile`; fi



My Nagios Configuration are as follows:

commands.cfg:

define command{
        command_name    check-handle-host-downtime-event
        command_line $USER1$/handle-host-downtime-event $HOSTSTATE$\
$STATETYPE$
        }

hosts.cfg:

# 'HostABC' host definition
define host{
        host_name               			hostABC
        alias                   				hostABC
        address                 				xxx.xxx.xxx.xxx
        check_command           			check-host-alive
        max_check_attempts      			3
        event_handler           			check-handle-host-downtime-event
        event_handler_enabled   		1
        notification_interval   			0
        notification_period     			24x7
        notification_options    			d,u,r
        }


Nagios.cfg:

check_external_commands=1
command_check_interval=-1
command_file=/var/nagios/rw/nagios.cmd
log_event_handlers=1
log_external_commands=1
log_passive_service_checks=1
enable_notifications=1
enable_event_handlers=1


Thanks 
Jasmine Chua
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/AWM/NgvTa7Hj2AURAu7WAJ9Dot7oAa58ULcXDtGlMpgMk73vvgCffUxU
mvo+gTaBxC6M5B0OPcLye2w=
=6uR5
-----END PGP SIGNATURE-----



-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list