#!/bin/bash # Dave Love , 2005-07-15 # modified for UFZ access check by 2015-02-26 REVISION=1.0 PROGNAME=$(/usr/bin/readlink -f $(type -p "$0" || echo "$0")) PROGPATH=$(/usr/bin/dirname "$PROGNAME") [ -f "$PROGPATH/utils.sh" ] && . "$PROGPATH/utils.sh" usage () { echo "\ Monitoring plugin to check if the host my.ufz.de responds with a login mask Usage: $PROGNAME -H $PROGNAME --help $PROGNAME --version " } help () { print_revision echo; usage; echo; support } if [ $# -lt 1 ] || [ $# -gt 2 ]; then usage exit $STATE_UNKNOWN fi while test -n "$1"; do case "$1" in --help | -h) help exit $STATE_OK ;; --version | -V) print_revision $PROGNAME $REVISION exit $STATE_OK ;; -H) shift host=$1 ;; *) usage exit $STATE_UNKNOWN;; esac shift done [ -z "$host" ] && host='my.ufz.de' if [ -z "$host" ]; then usage exit fi # get a name for a temporary file FINA=$(mktemp) # get the content to check and store it inside the temporary file USERAGENT='Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0' # use either wget or curl, see what we have if [ -x /usr/bin/wget ]; then /usr/bin/wget -q "https://$host/+CSCOE+/logon.html" --no-check-certificate -U "$USERAGENT" -O "$FINA" elif [ -x /usr/bin/curl ]; then /usr/bin/curl -1 -k -L -s -A "$USERAGENT" -o "$FINA" "https://$host/+CSCOE+/logon.html" fi # how long is the answer? FISIZE=$(/usr/bin/stat -c %s "$FINA") # is it long enough? FISZ=0 [ $FISIZE -gt 2000 ] && FISZ=1 # does it contain the correct text? FIOK=0 grep -q 'id="username" name="username"' "$FINA" && FIOK=1 # remove the temporary file rm "$FINA" # OK, so let's look ath the results... if [ $FISZ -eq 0 ]; then # error, if the answer is too small echo "CRITICAL: only $FISZ bytes found (\> 2000 expected)" exit $STATE_CRITICAL elif [ $FIOK -eq 0 ]; then # warning, if the answer does not contain the expected text echo "WARNING: input field for username not found" exit $STATE_WARNING else # so, if both checks are OK, we can tell nagios so :-) FITEXT="answer size: $FISIZE bytes; input field for username found" echo "OK: $FITEXT" exit $STATE_OK fi