Benjamin Renard commited on 2012-10-09 11:25:13
Showing 3 changed files, with 157 additions and 0 deletions.
... | ... |
@@ -0,0 +1 @@ |
1 |
+*~ |
... | ... |
@@ -0,0 +1,35 @@ |
1 |
+#!/bin/bash |
|
2 |
+# Verifie la latence d'une connexion SIP Asterisk |
|
3 |
+ |
|
4 |
+PEER=$1 |
|
5 |
+ |
|
6 |
+[ ! -n "$PEER" ] && echo "Usage : $0 [peer]" && exit 1 |
|
7 |
+ |
|
8 |
+CRITICAL=100 |
|
9 |
+WARNING=40 |
|
10 |
+ |
|
11 |
+latency=`/usr/bin/sudo -u root /usr/sbin/rasterisk -rnx "sip show peer $PEER"|grep Status|sed 's/.*(\([0-9]*\) ms.*/\1/g'` |
|
12 |
+ |
|
13 |
+if [ ! -n "$latency" ] |
|
14 |
+then |
|
15 |
+ /bin/echo "SIP Latency UNKNOWN" |
|
16 |
+ exit 3 |
|
17 |
+fi |
|
18 |
+ |
|
19 |
+details="Latency : $latency ms" |
|
20 |
+ |
|
21 |
+if [ $latency -gt $CRITICAL ] |
|
22 |
+then |
|
23 |
+ nstatus="CRITICAL" |
|
24 |
+ exitcode=2 |
|
25 |
+elif [ $latency -gt $WARNING ] |
|
26 |
+then |
|
27 |
+ nstatus="WARNING" |
|
28 |
+ exitcode=1 |
|
29 |
+else |
|
30 |
+ nstatus="OK" |
|
31 |
+ exitcode=0 |
|
32 |
+fi |
|
33 |
+ |
|
34 |
+/bin/echo "SIP Latency ${nstatus} : $details | latency=${latency}ms" |
|
35 |
+exit $exitcode |
... | ... |
@@ -0,0 +1,121 @@ |
1 |
+#!/bin/bash |
|
2 |
+ |
|
3 |
+[ ! -n "$1" ] && echo "Usage : $0 [-cX] [-wX] [-d] [peer1] [peer2]" && exit 1 |
|
4 |
+ |
|
5 |
+CRITICAL_LATENCY=100 |
|
6 |
+WARNING_LATENCY=70 |
|
7 |
+ |
|
8 |
+CRITICAL_PEER_NUMBER=1 |
|
9 |
+WARNING_PEER_NUMBER=2 |
|
10 |
+ |
|
11 |
+ |
|
12 |
+function checkPeer() { |
|
13 |
+ PEER=$1 |
|
14 |
+ state=$( /usr/bin/sudo -u root /usr/sbin/rasterisk -rnx "sip show peer $PEER"|grep "Status"|cut -d ":" -f 2 ) |
|
15 |
+ if [ ! -n "$state" ] |
|
16 |
+ then |
|
17 |
+ export MSG="$PEER : not found" |
|
18 |
+ return 3 |
|
19 |
+ fi |
|
20 |
+ |
|
21 |
+ ok=$( echo $state|grep -c OK ) |
|
22 |
+ |
|
23 |
+ |
|
24 |
+ if [ $ok -eq 0 ] |
|
25 |
+ then |
|
26 |
+ export MSG="$PEER :$state" |
|
27 |
+ return 3 |
|
28 |
+ else |
|
29 |
+ latency=$( echo "$state"|sed 's/.*(\([0-9]*\) ms.*/\1/g' ) |
|
30 |
+ [ $DEBUG -eq 1 ] && echo "Peer $PEER latency : $latency ms" |
|
31 |
+ if [ $latency -gt $CRITICAL_LATENCY ] |
|
32 |
+ then |
|
33 |
+ st='CRITICAL LATENCY' |
|
34 |
+ ec=2 |
|
35 |
+ elif [ $latency -gt $WARNING_LATENCY ] |
|
36 |
+ then |
|
37 |
+ st='WARNING LATENCY' |
|
38 |
+ ec=1 |
|
39 |
+ else |
|
40 |
+ st=OK |
|
41 |
+ ec=0 |
|
42 |
+ fi |
|
43 |
+ MSG="$PEER : $st (Latency : $latency ms)" |
|
44 |
+ return $ec |
|
45 |
+ fi |
|
46 |
+} |
|
47 |
+ |
|
48 |
+states="" |
|
49 |
+peers="" |
|
50 |
+nbok=0 |
|
51 |
+nbcrit=0 |
|
52 |
+nbwarn=0 |
|
53 |
+nbunk=0 |
|
54 |
+nbpeers=O |
|
55 |
+PEERS="" |
|
56 |
+DEBUG=0 |
|
57 |
+ |
|
58 |
+for arg in $@ |
|
59 |
+do |
|
60 |
+ if [ $( echo $arg|egrep -c '^-[cwCWd][0-9]*$' ) -gt 0 ] |
|
61 |
+ then |
|
62 |
+ a=$( echo $arg|sed 's/^-\([cwCWd]\).*$/\1/' ) |
|
63 |
+ v=$( echo $arg|sed 's/^-[cwCWd]//' ) |
|
64 |
+ case $a in |
|
65 |
+ c) |
|
66 |
+ CRITICAL_PEER_NUMBER=$v |
|
67 |
+ ;; |
|
68 |
+ w) |
|
69 |
+ WARNING_PEER_NUMBER=$v |
|
70 |
+ ;; |
|
71 |
+ C) |
|
72 |
+ CRITICAL_LATENCY=$v |
|
73 |
+ ;; |
|
74 |
+ W) |
|
75 |
+ WARNING_LATENCY=$v |
|
76 |
+ ;; |
|
77 |
+ d) |
|
78 |
+ DEBUG=1 |
|
79 |
+ ;; |
|
80 |
+ esac |
|
81 |
+ else |
|
82 |
+ PEERS="$PEERS $arg" |
|
83 |
+ fi |
|
84 |
+done |
|
85 |
+ |
|
86 |
+for PEER in $PEERS |
|
87 |
+do |
|
88 |
+ let nbpeers=nbpeers+1 |
|
89 |
+ checkPeer "$PEER" |
|
90 |
+ res=$? |
|
91 |
+ states="$states - $MSG" |
|
92 |
+ case $res in |
|
93 |
+ 0) |
|
94 |
+ let nbok=nbok+1 |
|
95 |
+ ;; |
|
96 |
+ 1) |
|
97 |
+ let nbwarn=nbwarn+1 |
|
98 |
+ ;; |
|
99 |
+ 2) |
|
100 |
+ let nbcrit=nbcrit+1 |
|
101 |
+ ;; |
|
102 |
+ 3) |
|
103 |
+ let nbunk=nbunk+1 |
|
104 |
+ ;; |
|
105 |
+ esac |
|
106 |
+ peers="$peers $PEER" |
|
107 |
+done |
|
108 |
+STATE=OK |
|
109 |
+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" |
|
110 |
+EXITC=0 |
|
111 |
+if [ $nbok -le $CRITICAL_PEER_NUMBER ] |
|
112 |
+then |
|
113 |
+ STATE=CRITICAL |
|
114 |
+ EXITC=2 |
|
115 |
+elif [ $nbok -le $WARNING_PEER_NUMBER ] |
|
116 |
+then |
|
117 |
+ STATE=WARNING |
|
118 |
+ EXITC=1 |
|
119 |
+fi |
|
120 |
+echo "$STATE - $MSG" |
|
121 |
+exit $EXITC |
|
0 | 122 |