Improve check_sip_latency

This commit is contained in:
Benjamin Renard 2018-11-05 18:40:15 +01:00
parent fb8c61c9ec
commit a96e883282

View file

@ -1,12 +1,61 @@
#!/bin/bash
# Verifie la latence d'une connexion SIP Asterisk
PEER=$1
DEBUG=0
PEER=""
CRITICAL_LATENCY=100
WARNING_LATENCY=40
[ ! -n "$PEER" ] && echo "Usage : $0 [peer]" && exit 1
CRITICAL=100
WARNING=40
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 latency of peer (in ms)"
echo " -w[X] Specify warning latency of peer (in ms)"
echo " [peer] Specify the peer name"
}
function debug() {
[ $DEBUG -eq 1 ] && echo -e "$( date "+%Y/%m/%d %H:%M:%S" ) - $1"
}
# Parse arguments
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_LATENCY=$v
;;
w)
WARNING_LATENCY=$v
;;
d)
DEBUG=1
;;
h)
usage
exit 0;
;;
esac
elif [ -z "$PEER" ]
then
PEER="$arg"
else
echo "Only one peer can be specified (or invalid '$arg' parameter)"
fi
done
[ -z "$PEER" ] && usage "You must specify peer name" && exit 1
debug "Specified peer name : $PEER"
debug "Warning/Critical latency : $WARNING_LATENCY / $CRITICAL_LATENCY"
[ $WARNING_LATENCY -gt $CRITICAL_LATENCY ] && usage "Warning latency must be lower than critical one" && exit 1
latency=`/usr/bin/sudo -u root /usr/sbin/rasterisk -rnx "sip show peer $PEER"|grep Status|sed 's/.*(\([0-9]*\) ms.*/\1/g'`
@ -16,13 +65,15 @@ then
exit 3
fi
debug "Latency of peer $PEER : $latency ms"
details="Latency : $latency ms"
if [ $latency -gt $CRITICAL ]
if [ $latency -gt $CRITICAL_LATENCY ]
then
nstatus="CRITICAL"
exitcode=2
elif [ $latency -gt $WARNING ]
elif [ $latency -gt $WARNING_LATENCY ]
then
nstatus="WARNING"
exitcode=1