#!/bin/bash
# Nagios shoutcast plug-in
# By Rafael Padilha ([email protected])
# AND Juliano Jeziorny ([email protected])
# Rev 0.1
# 01/12/2015
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/status-json.xsl -A Mozilla/4.0 -s -m 5`
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, -f21 |cut -d: -f2` # cut out current listenens
MAX=`echo $STR |cut -d, -f20 |cut -d: -f2` # 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