#! /bin/sh # # Author: Juergen Vigna # # Plugin which first checks if a host is up and then launches the # check of another pluging. If the host is down it will return OK # as status with the message that the host is not reachable. # export HOME=/tmp PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin PROGNAME=`basename $0` PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` REVISION=`echo '$Revision: 1.1 $' | sed -e 's/[^0-9.]//g'` TMPFILE=/tmp/cwp$$.tmp trap 'rm -f $TMPFILE; exit 10' 1 2 15 trap 'rm -f $TMPFILE' 0 . $PROGPATH/utils.sh print_usage() { echo "Usage: $PROGNAME [-m ] -H " } print_help() { print_revision $PROGNAME $REVISION echo "" print_usage echo "" echo "Plugin which first checks if a host is up and then launches the" echo "check of another pluging. If the host is down it will return OK" echo "as status with the message that the host is not reachable." echo "" echo "-m default: ping. Possible values: ping, nrpe, nt[]" echo "-H the host to check to see if it's up" echo " the default check_nt port is 12489" echo "At last specify the plugin to launch with all it's parameters, if" echo "the plugin has no absolute path we try to find it on best effort." exit 0 } resetParam() { if [ $1 != "HOST" ] then PHOST="" fi if [ $1 != "MODE" ] then PMODE="" fi } if [ $# -lt 2 ] then print_help exit $STATE_UNKNOWN fi for param in $* do case "$param" in --help) print_help exit 0 ;; -h) print_help exit 0 ;; --version) print_revision $PROGNAME $REVISION exit 0 ;; -V) print_revision $PROGNAME $REVISION exit 0 ;; -H) PHOST="-" shift resetParam HOST ;; -m) PMODE="-" shift resetParam MODE ;; *) # if value is "-", than then current parameter if [ "$PHOST" == "-" ] then HOST="$param" PHOST="" shift elif [ "$PMODE" == "-" ] then MODE=$param PMODE="" shift else break fi ;; esac done if [ -z "$HOST" ] then echo "UNKNOWN - forgot to specify HOST in commandline" exit $STATE_UNKNOWN fi CMD=$1 shift if [ -z "$CMD" ] then echo "UNKNOWN - forgot to specify the plugin command with options" exit $STATE_UNKNOWN fi if [ -z "$MODE" -o "$MODE" = "ping" ] then MODE=ping CHECKCMD=check_ping CHECKARG="-H $HOST -p 1 -w 100%,3000,5000 -c 100%,3000,5000" elif [ "$MODE" = "nrpe" ] then CHECKCMD=check_nrpe CHECKARG="-H $HOST" elif [ "`echo $MODE | cut -c1-2`" = "nt" ] then CHECKCMD=check_nt port="`echo $MODE | cut -c3-`" if [ -z "$port" ] then CHECKARG="-p 12489 -H $HOST -v CLIENTVERSION" else CHECKARG="-p $port -H $HOST -v CLIENTVERSION" fi fi if [ -x /usr/lib/nagios/plugins/$CHECKCMD ] then CHECKEXE="/usr/lib/nagios/plugins/$CHECKCMD $CHECKARG" elif [ -x $PROGPATH/$CHECKCMD ] then CHECKEXE="$PROGPATH/$CHECKCMD $CHECKARG" else echo "UNKNOWN - check command $CHECKCMD of mode $MODE not found" exit $STATE_UNKNOWN fi if [ ! -x $CMD ] then BCMD=`basename $CMD` if [ -x /usr/lib/nagios/plugins/$BCMD ] then EXE="/usr/lib/nagios/plugins/$BCMD" elif [ -x $PROGPATH/$BCMD ] then EXE="$PROGPATH/$BCMD" else echo "UNKNOWN - plugin command $CMD not found" exit $STATE_UNKNOWN fi else EXE=$CMD fi $CHECKEXE >/dev/null 2>&1 RET=$? if [ $RET -ne 0 ] then echo "OK - Host $HOST is down or $MODE not reachable" exit $STATE_OK fi $EXE $* exit $?