Improve check_sip_peers

This commit is contained in:
Benjamin Renard 2018-11-05 18:50:42 +01:00
parent a96e883282
commit 1017b27c1c

View file

@ -1,13 +1,20 @@
#!/bin/bash
[ ! -n "$1" ] && echo "Usage : $0 [-cX] [-wX] [-d] [peer1] [peer2]" && exit 1
CRITICAL_LATENCY=100
WARNING_LATENCY=70
CRITICAL_PEER_NUMBER=1
WARNING_PEER_NUMBER=2
function usage() {
[ -n "$1" ] && echo "$1" && echo
echo "Usage : $0 [-cX] [-wX] [-CX] [-WX] [-d] [peer1] [peer2] ..."
echo " -h Show this help message"
echo " -d Enable debug mode"
echo " -c[X] Specify critical number of connected peers"
echo " -w[X] Specify warning number of connected peers"
echo " -C[X] Specify critical latency of connected peers (in ms)"
echo " -W[X] Specify warning latency of connected peers (in ms)"
echo " [peer] Specify the peers name"
}
function debug() {
[ $DEBUG -eq 1 ] && echo -e "$( date "+%Y/%m/%d %H:%M:%S" ) - $1"
}
function checkPeer() {
PEER=$1
@ -18,6 +25,8 @@ function checkPeer() {
return 3
fi
debug "Peer $PEER state : $state"
ok=$( echo $state|grep -c OK )
@ -27,7 +36,7 @@ function checkPeer() {
return 3
else
latency=$( echo "$state"|sed 's/.*(\([0-9]*\) ms.*/\1/g' )
[ $DEBUG -eq 1 ] && echo "Peer $PEER latency : $latency ms"
debug "Peer $PEER latency : $latency ms"
if [ $latency -gt $CRITICAL_LATENCY ]
then
st='CRITICAL LATENCY'
@ -45,22 +54,21 @@ function checkPeer() {
fi
}
states=""
peers=""
nbok=0
nbcrit=0
nbwarn=0
nbunk=0
nbpeers=O
CRITICAL_LATENCY=100
WARNING_LATENCY=70
CRITICAL_PEER_NUMBER=1
WARNING_PEER_NUMBER=2
PEERS=""
DEBUG=0
for arg in $@
do
if [ $( echo $arg|egrep -c '^-[cwCWd][0-9]*$' ) -gt 0 ]
if [ $( echo $arg|egrep -c '^-[cwCWdh][0-9]*$' ) -gt 0 ]
then
a=$( echo $arg|sed 's/^-\([cwCWd]\).*$/\1/' )
v=$( echo $arg|sed 's/^-[cwCWd]//' )
a=$( echo $arg|sed 's/^-\([cwCWdh]\).*$/\1/' )
v=$( echo $arg|sed 's/^-[cwCWdh]//' )
case $a in
c)
CRITICAL_PEER_NUMBER=$v
@ -77,12 +85,33 @@ do
d)
DEBUG=1
;;
h)
usage
exit 0
;;
esac
else
PEERS="$PEERS $arg"
fi
done
[ -z "$PEERS" ] && usage "You must specify at least one peer name" && exit 1
debug "Specified peers name : $PEERS"
debug "Warning/Critical latency : $WARNING_LATENCY / $CRITICAL_LATENCY"
[ $WARNING_LATENCY -gt $CRITICAL_LATENCY ] && usage "Warning latency must be lower than critical one" && exit 1
debug "Warning/Critical peers : $WARNING_PEER_NUMBER / $CRITICAL_PEER_NUMBER"
[ $WARNING_LATENCY -gt $CRITICAL_LATENCY ] && usage "Warning peers number must be lower than critical one" && exit 1
states=""
peers=""
nbok=0
nbcrit=0
nbwarn=0
nbunk=0
nbpeers=O
for PEER in $PEERS
do
let nbpeers=nbpeers+1