Initial commit

This commit is contained in:
Benjamin Renard 2012-10-09 13:24:55 +02:00 committed by root
commit 07d7c293ae
3 changed files with 157 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*~

35
check_sip_latency Executable file
View file

@ -0,0 +1,35 @@
#!/bin/bash
# Verifie la latence d'une connexion SIP Asterisk
PEER=$1
[ ! -n "$PEER" ] && echo "Usage : $0 [peer]" && exit 1
CRITICAL=100
WARNING=40
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
/bin/echo "SIP Latency UNKNOWN"
exit 3
fi
details="Latency : $latency ms"
if [ $latency -gt $CRITICAL ]
then
nstatus="CRITICAL"
exitcode=2
elif [ $latency -gt $WARNING ]
then
nstatus="WARNING"
exitcode=1
else
nstatus="OK"
exitcode=0
fi
/bin/echo "SIP Latency ${nstatus} : $details | latency=${latency}ms"
exit $exitcode

121
check_sip_peers Executable file
View file

@ -0,0 +1,121 @@
#!/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 checkPeer() {
PEER=$1
state=$( /usr/bin/sudo -u root /usr/sbin/rasterisk -rnx "sip show peer $PEER"|grep "Status"|cut -d ":" -f 2 )
if [ ! -n "$state" ]
then
export MSG="$PEER : not found"
return 3
fi
ok=$( echo $state|grep -c OK )
if [ $ok -eq 0 ]
then
export MSG="$PEER :$state"
return 3
else
latency=$( echo "$state"|sed 's/.*(\([0-9]*\) ms.*/\1/g' )
[ $DEBUG -eq 1 ] && echo "Peer $PEER latency : $latency ms"
if [ $latency -gt $CRITICAL_LATENCY ]
then
st='CRITICAL LATENCY'
ec=2
elif [ $latency -gt $WARNING_LATENCY ]
then
st='WARNING LATENCY'
ec=1
else
st=OK
ec=0
fi
MSG="$PEER : $st (Latency : $latency ms)"
return $ec
fi
}
states=""
peers=""
nbok=0
nbcrit=0
nbwarn=0
nbunk=0
nbpeers=O
PEERS=""
DEBUG=0
for arg in $@
do
if [ $( echo $arg|egrep -c '^-[cwCWd][0-9]*$' ) -gt 0 ]
then
a=$( echo $arg|sed 's/^-\([cwCWd]\).*$/\1/' )
v=$( echo $arg|sed 's/^-[cwCWd]//' )
case $a in
c)
CRITICAL_PEER_NUMBER=$v
;;
w)
WARNING_PEER_NUMBER=$v
;;
C)
CRITICAL_LATENCY=$v
;;
W)
WARNING_LATENCY=$v
;;
d)
DEBUG=1
;;
esac
else
PEERS="$PEERS $arg"
fi
done
for PEER in $PEERS
do
let nbpeers=nbpeers+1
checkPeer "$PEER"
res=$?
states="$states - $MSG"
case $res in
0)
let nbok=nbok+1
;;
1)
let nbwarn=nbwarn+1
;;
2)
let nbcrit=nbcrit+1
;;
3)
let nbunk=nbunk+1
;;
esac
peers="$peers $PEER"
done
STATE=OK
MSG="$nbok peer(s) OK of $nbpeers peers $states|'available peers':$nbok;$WARNING_PEER_NUMBER;$CRITICAL_PEER_NUMBER;0;$nbpeers 'critical peers':$nbcrit;$WARNING_PEER_NUMBER;$CRITICAL_PEER_NUMBER;0;$nbpeers 'unknown peers':$nbunk;$WARNING_PEER_NUMBER;$CRITICAL_PEER_NUMBER;0;$nbpeers 'warning peers':$nbwarn;$WARNING_PEER_NUMBER;$CRITICAL_PEER_NUMBER;0;$nbpeers"
EXITC=0
if [ $nbok -le $CRITICAL_PEER_NUMBER ]
then
STATE=CRITICAL
EXITC=2
elif [ $nbok -le $WARNING_PEER_NUMBER ]
then
STATE=WARNING
EXITC=1
fi
echo "$STATE - $MSG"
exit $EXITC