Zionetrix::Git
Repositories
Help
Report an Issue
check_asterisk
Code
Commits
Branches
Tags
Search
Tree:
07d7c29
Branches
Tags
master
check_asterisk
check_sip_peers
Initial commit
Benjamin Renard
commited
07d7c29
at 2012-10-09 11:25:13
check_sip_peers
Blame
History
Raw
#!/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