#!/bin/sh # # Event handler script for calling a NRPE handler which executes a command indicated within parameters # # Note: This script will only restart the service if the service is in state # CRITICAL and falls into a "hard" error state. # #There are 4 required arguents to be passed: # $1 Hostname/Host IP # $2 Status of severity of Nagios service/host check value: CRITICAL/WARNING # Command: $SERVICESTATE$ # $3 Type of service/host non-ok: HARD/SOFT # Command: $SERVICESTATETYPE$ # $4 NRPE command to call on HOST # $n > 4 Parameters to give the NRPE handler as $ARG1$ if [ $# -lt 4 ] then echo " " echo "Plese call the script with the required arguments" echo " " echo "Usage:" echo "eventhandler-nrpe []" echo " " exit 3 fi ALLARGS="$*" HOST=$1 shift STATE=$1 shift TYPE=$1 shift NRPECMD=$1 shift logfile=/dev/null if [ "$1" = "-v" ] then shift logfile="/var/log/nagios/eventhandler-nrpe.log" touch $logfile 2>/dev/null if [ ! -w "$logfile" ] then logfile=/var/tmp/eventhandler-nrpe.log touch $logfile 2>/dev/null if [ ! -w "$logfile" ] then logfile=/dev/null fi fi fi ARGS="$*" echo "`date +"%Y/%m/%d %H:%M:%S"`: This is the call of event handler: $ALLARGS" >>$logfile # What state is the service in? case "$STATE" in #OK) # # The service just came back up, so don't do anything... # ;; #WARNING) # # We don't really care about warning states, since the service is probably still running... # ;; #UNKNOWN) # # We don't know what might be causing an unknown error, so don't do anything... # ;; CRITICAL) # Is this a "soft" or a "hard" state? case "$TYPE" in #SOFT) #;; HARD) # Call the the NRPE command with argumets echo "Calling NRPE command ($NRPECMD) with arguments ($ARGS)" >>$logfile /usr/lib/nagios/plugins/check_nrpe -H $HOST -c $NRPECMD -a " $ARGS" >>$logfile exit $? ;; esac ;; esac exit 0