#!/bin/sh # Nagios tracert check # Version: 1.0 # Author : Thomas Forrer # Description: This plugin will check with tracert if the network path to a # specific internet host/domain goes through one of the specified # routers/ip's. VERSION="1.0" PROGNAME=`basename $0` PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'` # To enable debugging set a value of 1 DEBUG=0 STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 # ---------------------------------------------------------------- # Initialized used variables TIMEOUT=15 CDIR="/tmp" TMPFILE="/tmp/tracertcheck$$.tmp" trap 'rm -f $TMPFILE; exit 10' 1 2 15 trap 'rm -f $TMPFILE' 0 PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'` if [ -f $PROGPATH/utils.sh ]; then . $PROGPATH/utils.sh fi print_header() { echo $PROGNAME $VERSION echo "" echo "This plugin will check with tracert if the network path to a" echo "specific internet host/domain goes through one of the specified" echo "routers/ip's." echo "" } print_usage() { echo "Usage: $PROGNAME " echo " -h, --help : this help" echo " -V, -version : program version" echo " -D, -domain : target domain to check" echo " default: www.google.com" echo " -r, -routers : comma separated list of routers to check for" echo " example: 123.123.123.11,123.123.123.22,123.123.123.33" } print_help() { print_header print_usage echo "" #support } if [ $DEBUG == 1 ]; then echo "parameters count: $#" echo "parameters: $*" fi # # If we have arguments, process them. # exitstatus=$STATE_OK #default for parameter in $*; do case "$parameter" in --help) print_help exit $STATE_OK ;; -h) print_help exit $STATE_OK ;; --version) print_revision $PROGNAME $VERSION exit $STATE_OK ;; -V) print_revision $PROGNAME $VERSION exit $STATE_OK ;; -D) DOMAIN="-" ;; -domain) # TIMEOUT VALUE override DOMAIN="-" ;; -r) ROUTERS="-" ;; -routers) # CDIR VALUE override ROUTERS="-" ROUTERS=`echo $ROUTERS | sed -e 's/,/|/g'` ;; *) # if value is "-", than then current parameter if [ "$ROUTERS" == "-" ]; then ROUTERS=$parameter; elif [ "$DOMAIN" == "-" ]; then DOMAIN=$parameter; elif [ $DEBUG == 1 ]; then echo "Parameter \"$parameter\" ignored!" fi ;; esac done if [ $DEBUG == 1 ]; then echo echo "DOMAIN : $DOMAIN" echo "ROUTERS: $ROUTERS" fi if [ ! "${ROUTERS}" ] ; then echo "[-] the -r parameter is mandatory." exit $STATE_UNKNOWN else ROUTERS=`echo $ROUTERS | sed -e 's/,/|/g'` fi if [ ! "${DOMAIN}" ] ; then if [ $DEBUG == 1 ] ; then echo "[*] using default domain (www.google.it)" fi DOMAIN="www.google.it" fi if [ $DEBUG == 1 ] ; then echo "[*] begin tracert" fi ROUTERS_IN_PATH="" tracert $DOMAIN | grep -E "$ROUTERS" > $TMPFILE if [ "$?" -eq "0" ] ; then if [ $DEBUG == 1 ] ; then echo "[+] tracert completed" fi for r in `echo $ROUTERS | sed -e 's/|/ /g'`; do if grep $r $TMPFILE >/dev/null ; then if [ $DEBUG == 1 ] ; then echo "[+] tracert completed" fi ROUTERS_IN_PATH=$ROUTERS_IN_PATH$r" " fi done echo "OK - path goes through router(s) "$ROUTERS_IN_PATH exit $STATE_OK else echo "WARNING - path goes not through routers" exit $STATE_WARNING fi