2012-10-09 13:24:55 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# Verifie la latence d'une connexion SIP Asterisk
|
|
|
|
|
2018-11-05 18:40:15 +01:00
|
|
|
DEBUG=0
|
|
|
|
PEER=""
|
|
|
|
CRITICAL_LATENCY=100
|
|
|
|
WARNING_LATENCY=40
|
2012-10-09 13:24:55 +02:00
|
|
|
|
|
|
|
|
2018-11-05 18:40:15 +01:00
|
|
|
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
|
2012-10-09 13:24:55 +02:00
|
|
|
|
|
|
|
latency=`/usr/bin/sudo -u root /usr/sbin/rasterisk -rnx "sip show peer $PEER"|grep Status|sed 's/.*(\([0-9]*\) ms.*/\1/g'`
|
|
|
|
|
|
|
|
if [ ! -n "$latency" ]
|
|
|
|
then
|
2022-05-19 12:13:29 +02:00
|
|
|
echo "UNKNOWN - SIP peer $PEER unknown"
|
2012-10-09 13:24:55 +02:00
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
|
2018-11-05 18:40:15 +01:00
|
|
|
debug "Latency of peer $PEER : $latency ms"
|
|
|
|
|
2012-10-09 13:24:55 +02:00
|
|
|
details="Latency : $latency ms"
|
|
|
|
|
2018-11-05 18:40:15 +01:00
|
|
|
if [ $latency -gt $CRITICAL_LATENCY ]
|
2012-10-09 13:24:55 +02:00
|
|
|
then
|
|
|
|
nstatus="CRITICAL"
|
|
|
|
exitcode=2
|
2018-11-05 18:40:15 +01:00
|
|
|
elif [ $latency -gt $WARNING_LATENCY ]
|
2012-10-09 13:24:55 +02:00
|
|
|
then
|
|
|
|
nstatus="WARNING"
|
|
|
|
exitcode=1
|
|
|
|
else
|
|
|
|
nstatus="OK"
|
|
|
|
exitcode=0
|
|
|
|
fi
|
|
|
|
|
2022-05-19 12:13:29 +02:00
|
|
|
echo "${nstatus} - SIP Latency is ${nstatus}: $details | latency=${latency}ms"
|
2012-10-09 13:24:55 +02:00
|
|
|
exit $exitcode
|