#!/bin/sh # Nagios shoutcast plug-in # By Juliano Jeziorny (djkadu@gmail.com) # Rev 0.1 # 23/11/2010 WARN=90 # default Warning threshold if none is specified ALER=75 # default Alert thresshold if none is specified CURL=`which curl` # you can also specify the full path to curl [[ -z $CURL ]] && exit 3 # if curl is not present exit with unknown error while getopts ":H:p:w:a:" OPT; do # check supplied arguments case $OPT in H ) HOST=$OPTARG;; p ) PORT=$OPTARG;; w ) WARN=$OPTARG;; a ) ALER=$OPTARG;; esac done if [[ -n $HOST && -n $PORT ]] # test if minimum required arguments are present then STR=`$CURL http://$HOST:$PORT/7.html -A Mozilla/4.0 -s -m 5` # access 7.html on the specified host and port case $? in 0 ) ;; 6 ) echo "Invalid Host"; exit 1;; 7 ) echo "SHOUTCAST ALERT - Failed to connect to host on port $PORT"; exit 2;; * ) echo "SHOUTCAST UNKNOWN - Unknown error"; exit 3;; esac CUR=`echo $STR |cut -d\> -f5 |cut -d, -f1` # cut out current listenens MAX=`echo $STR |cut -d\> -f5 |cut -d, -f4` # cut out maximum listeners LEVEL="OK" && EXIT=0 # if we got to this point with no error assume level is OK [[ "$CUR" -ge "$WARN" ]] && LEVEL="WARNING" && EXIT=1 # check if current listeners is higher than warning theashold [[ "$CUR" -ge "$ALER"-1 ]] && LEVEL="ALERT" && EXIT=2 # check if current listeners is higher than alarm threshold echo "SHOUTCAST $LEVEL - $CUR out of $MAX listeners on port $PORT" exit $EXIT fi echo "Usage: check_shoutcast -H -p [-w warning level (default 75 listeners)] [-a alert level (default 90 listeners)]"