75 lines
1.6 KiB
Bash
Executable file
75 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
function usage() {
|
|
[ -n "$1" ] && echo "$1" && echo
|
|
echo "Usage : $0 [-cX] [-wX] [-d] [peer]"
|
|
echo " -h Show this help message"
|
|
echo " -d Enable debug mode"
|
|
echo " -c[X] Specify critical number of simultaneous channels"
|
|
echo " -w[X] Specify warning number of simultaneous channels"
|
|
echo " [peer] Specify the peer name"
|
|
}
|
|
|
|
function debug() {
|
|
[ $DEBUG -eq 1 ] && echo -e "$( date "+%Y/%m/%d %H:%M:%S" ) - $1"
|
|
}
|
|
|
|
CRITICAL=10
|
|
WARNING=8
|
|
PEER=""
|
|
DEBUG=0
|
|
|
|
for arg in $@
|
|
do
|
|
if [ $( echo $arg|egrep -c '^-[cwdh][0-9]*$' ) -gt 0 ]
|
|
then
|
|
a=$( echo $arg|sed 's/^-\([cwdh]\).*$/\1/' )
|
|
v=$( echo $arg|sed 's/^-[cwdh]//' )
|
|
case $a in
|
|
c)
|
|
CRITICAL=$v
|
|
;;
|
|
w)
|
|
WARNING=$v
|
|
;;
|
|
d)
|
|
DEBUG=1
|
|
;;
|
|
h)
|
|
usage
|
|
exit 0
|
|
;;
|
|
esac
|
|
else
|
|
PEER="$arg"
|
|
fi
|
|
done
|
|
|
|
[ -z "$PEER" ] && usage "You must specify peer name" && exit 1
|
|
|
|
debug "Parameters : Warning = $WARNING / Critical = $CRITICAL"
|
|
[ $WARNING -gt $CRITICAL ] && usage "Warning number of simultaneous channels must be lower than critical one" && exit 1
|
|
|
|
number=$( /usr/bin/sudo -u root /usr/sbin/rasterisk -rnx "core show channels concise"|cut -d'!' -f1|grep -Ec "^SIP/$PEER-" )
|
|
if [ ! -n "$number" ]
|
|
then
|
|
echo "UNKNOW - Fail to retreive number of simultaneous channels of SIP peer $PEER"
|
|
exit 3
|
|
fi
|
|
|
|
debug "Peer $PEER simultaneous channels : $number"
|
|
|
|
if [ $number -gt $CRITICAL ]
|
|
then
|
|
st='CRITICAL'
|
|
ec=2
|
|
elif [ $number -gt $WARNING ]
|
|
then
|
|
st='WARNING'
|
|
ec=1
|
|
else
|
|
st=OK
|
|
ec=0
|
|
fi
|
|
echo "$st - $number simultaneous channels with SIP peer $PEER|'simultaneous channels':$number;$WARNING;$CRITICAL;0;$"
|
|
exit $ec
|