#!/bin/sh
###############################################################################
# Event handler script for enabling/disabling active
# checks on services depending on the host status
#
# Create a command called "event_host_change" and set to this:
#   $USER1$/event_host_change.sh $HOSTSTATE$ $HOSTSTATETYPE$ $HOSTNAME$
#
# Put this script in /usr/local/nagios/libexec/event_host_change.sh
# Set the event handler on the host/host template to the one created
###############################################################################
# Adjust as desired and your printf folder may be different
###############################################################################
# Written by BanditBBS (www.bandits-home-on-the-web.com) Version 1.01 01/29/2015
###############################################################################
now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

case "$1" in

UP)
        # The host came back up, enable notifications
        /usr/bin/printf "[%lu] ENABLE_HOST_SVC_CHECKS;$3\n" $now > $commandfile
        ;;

DOWN)
        case "$2" in
        SOFT)
                # Do nothing
                ;;
        HARD)
                /usr/bin/printf "[%lu] DISABLE_HOST_SVC_CHECKS;$3\n" $now > $commandfile
                ;;
        esac
        ;;

UNREACHABLE)
        case "$2" in
        SOFT)
                # Do nothing
                ;;
        HARD)
                /usr/bin/printf "[%lu] DISABLE_HOST_SVC_CHECKS;$3\n" $now > $commandfile
                ;;
        esac
        ;;
esac
exit 0