PRTG Check Script

#!/bin/sh
smconsole="sudo /opt/Avaya/contrib/bin/sm console"
if [ $1 = "callcount" ];then
callcountSM="${smconsole} GET AllCallCountSM"
calls=`$callcountSM`
echo 0:`echo $calls|sed -r "s/.*\=A\=([0-9]{1,3}).*/\1/g"`:Active Calls Session Manager 1
elif [ $1 = "health" ];then
healthSM1="${smconsole} GET SMHealth 1"
healthSM2="${smconsole} GET SMHealth 2"
echo `$healthSM1` | sed -r "s/.*name=\"(.*)\".*status=(\w{1,10}),?.*smHealth=(.*)/\1:\2 Health:\3/g"
echo `$healthSM2` | sed -r "s/.*name=\"(.*)\".*status=(\w{1,10}),?.*smHealth=(.*)/\1:\2 Health:\3/g"
elif [ $1 = "sipentities" ];then
sipentities=`${smconsole} MONITOR Summary`
#echo ${sipentities}
status=`echo ${sipentities} | egrep 'INITIALIZING: \[\w.*\]|PARTIALLYUP: \[\w.*\]|DOWN: \[\w.*\]|DENY: \[\w.*\]'`
if [ -z "$status" ];then
echo 0:0:All SIP Entities UP
else
down=`${smconsole} MONITOR Down`
count=`echo $down| grep -o "status=DOWN"|wc -l`
echo 1:$((count/2)):`echo ${sipentities} | egrep -o 'INITIALIZING: \[\w.*?\s?\] |PARTIALLYUP: \[\w.*?\s?\] |DOWN: \[\w.*?\s?\] |DENY: \[\w.*?\s?\]'`
fi
elif [ $1 = "registeredp" ];then
registeredSM=`${smconsole} GET RegistrationSummary`
echo 0:`echo $registeredSM | sed -r "s/.*Primary: ([0-9]{1,5}).*Secondary: ([0-9]{1,5}).*/\1/g"`:Primary Registrations
elif [ $1 = "registereds" ];then
registeredSM=`${smconsole} GET RegistrationSummary`
echo 0:`echo $registeredSM | sed -r "s/.*Primary: ([0-9]{1,5}).*Secondary: ([0-9]{1,5}).*/\2/g"`:Secondary Registrations
else
echo "wrong or missing argument!"
fi