Improve check_sip_peers
This commit is contained in:
parent
a96e883282
commit
1017b27c1c
1 changed files with 47 additions and 18 deletions
|
@ -1,13 +1,20 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
[ ! -n "$1" ] && echo "Usage : $0 [-cX] [-wX] [-d] [peer1] [peer2]" && exit 1
|
function usage() {
|
||||||
|
[ -n "$1" ] && echo "$1" && echo
|
||||||
CRITICAL_LATENCY=100
|
echo "Usage : $0 [-cX] [-wX] [-CX] [-WX] [-d] [peer1] [peer2] ..."
|
||||||
WARNING_LATENCY=70
|
echo " -h Show this help message"
|
||||||
|
echo " -d Enable debug mode"
|
||||||
CRITICAL_PEER_NUMBER=1
|
echo " -c[X] Specify critical number of connected peers"
|
||||||
WARNING_PEER_NUMBER=2
|
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() {
|
function checkPeer() {
|
||||||
PEER=$1
|
PEER=$1
|
||||||
|
@ -18,6 +25,8 @@ function checkPeer() {
|
||||||
return 3
|
return 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
debug "Peer $PEER state : $state"
|
||||||
|
|
||||||
ok=$( echo $state|grep -c OK )
|
ok=$( echo $state|grep -c OK )
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +36,7 @@ function checkPeer() {
|
||||||
return 3
|
return 3
|
||||||
else
|
else
|
||||||
latency=$( echo "$state"|sed 's/.*(\([0-9]*\) ms.*/\1/g' )
|
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 ]
|
if [ $latency -gt $CRITICAL_LATENCY ]
|
||||||
then
|
then
|
||||||
st='CRITICAL LATENCY'
|
st='CRITICAL LATENCY'
|
||||||
|
@ -45,22 +54,21 @@ function checkPeer() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
states=""
|
CRITICAL_LATENCY=100
|
||||||
peers=""
|
WARNING_LATENCY=70
|
||||||
nbok=0
|
|
||||||
nbcrit=0
|
CRITICAL_PEER_NUMBER=1
|
||||||
nbwarn=0
|
WARNING_PEER_NUMBER=2
|
||||||
nbunk=0
|
|
||||||
nbpeers=O
|
|
||||||
PEERS=""
|
PEERS=""
|
||||||
DEBUG=0
|
DEBUG=0
|
||||||
|
|
||||||
for arg in $@
|
for arg in $@
|
||||||
do
|
do
|
||||||
if [ $( echo $arg|egrep -c '^-[cwCWd][0-9]*$' ) -gt 0 ]
|
if [ $( echo $arg|egrep -c '^-[cwCWdh][0-9]*$' ) -gt 0 ]
|
||||||
then
|
then
|
||||||
a=$( echo $arg|sed 's/^-\([cwCWd]\).*$/\1/' )
|
a=$( echo $arg|sed 's/^-\([cwCWdh]\).*$/\1/' )
|
||||||
v=$( echo $arg|sed 's/^-[cwCWd]//' )
|
v=$( echo $arg|sed 's/^-[cwCWdh]//' )
|
||||||
case $a in
|
case $a in
|
||||||
c)
|
c)
|
||||||
CRITICAL_PEER_NUMBER=$v
|
CRITICAL_PEER_NUMBER=$v
|
||||||
|
@ -77,12 +85,33 @@ do
|
||||||
d)
|
d)
|
||||||
DEBUG=1
|
DEBUG=1
|
||||||
;;
|
;;
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
PEERS="$PEERS $arg"
|
PEERS="$PEERS $arg"
|
||||||
fi
|
fi
|
||||||
done
|
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
|
for PEER in $PEERS
|
||||||
do
|
do
|
||||||
let nbpeers=nbpeers+1
|
let nbpeers=nbpeers+1
|
||||||
|
|
Loading…
Reference in a new issue