Compare commits

...

2 commits

Author SHA1 Message Date
Benjamin Renard fd9559312e Add README.md file 2022-05-19 11:37:00 +02:00
Benjamin Renard 3d388be5e6 Add check_sip_zombie_channels 2022-05-19 11:36:51 +02:00
2 changed files with 160 additions and 0 deletions

32
README.md Normal file
View file

@ -0,0 +1,32 @@
# Icinga/Nagios plugins to check an Asterisk
This repository provide a collection of scripts could be used as Icinga/Nagios check plugins to check an Asterisk installation.
## Installation
```
git clone https://gitea.zionetrix.net/bn8/check_asterisk.git /usr/local/src/check_asterisk
mkdir -p /usr/local/lib/nagios/plugins
cd /usr/local/src/check_asterisk
for i in /usr/local/src/check_asterisk/check_*; do ln -s $(realpath $i) /usr/local/lib/nagios/plugins/$(basename $i); done
```
## Copyright
Copyright (c) 2022 Benjamin Renard
## License
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

128
check_sip_zombie_channels Executable file
View file

@ -0,0 +1,128 @@
#!/bin/bash
DEBUG=0
WARNING_HOURS=3
CRITICAL_HOURS=6
function usage() {
[ -n "$1" ] && echo "$1" && echo
echo "Usage : $0 [-cX] [-wX] [-d]"
echo " -h Show this help message"
echo " -d Enable debug mode"
echo " -c[X] Specify critical call duration threshold"
echo " -w[X] Specify warning call duration threshold"
}
function debug() {
[ $DEBUG -eq 1 ] && echo -e "$( date "+%Y/%m/%d %H:%M:%S" ) - $1"
}
CRITICAL=10
WARNING=8
DEBUG=0
for arg in $@
do
if [ $( echo $arg|egrep -c '^-[cwdh][0-9]*$' ) -gt 0 ]
then
a=$( echo $arg|sed 's/^-\([cwdh]\).*$/\1/' )
v=$( echo $arg|sed 's/^-[cwdh]//' )
case $a in
c)
CRITICAL_HOURS=$v
;;
w)
WARNING_HOURS=$v
;;
d)
DEBUG=1
;;
h)
usage
exit 0
;;
esac
else
usage "Invalid argument '$arg'"
fi
done
let WARNING_SECONDS=WARNING_HOURS*3600
let CRITICAL_SECONDS=CRITICAL_HOURS*3600
STATE=OK
EXITCODE=
CRITICAL=0
CRITICAL_CHANNELS=""
WARNING=0
WARNING_CHANNELS=""
OK=0
debug "Retreive current channels info using rasterisk..."
## Output example for asterisk cli commande 'core show channels concise' :
## format :
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14
## chanid!context!exten!prio!state!app!appdata!callerid![?]![?]![?]!duration!bridgedtochan![?]
## SIP/trunk-00010bc5!incoming!02XXXXXX19!1!Down!AppDial!(Outgoing Line)!02XXXXXX19!!!3!0!(None)!1447335911.168247
## SIP/trunk-00010bc0!macro-callqueue!s!4!Up!Queue!natlrecouvrement,,,,120!09XXXXXX68!!!3!19!(None)!1447335892.168238
CURRENT_CHANNELS=$( /usr/bin/sudo -u root /usr/sbin/rasterisk -rnx 'core show channels concise' | grep -v '^CBAnn/' | grep -Ev "^Setting\s+max\s+files")
debug "Current channels:\n$CURRENT_CHANNELS"
IFS="
"
for line in $CURRENT_CHANNELS
do
if [ $(echo $line | grep -c "^Message/ast_msg_queue") -eq 1 ]
then
debug "Info Message/ast_msg_queue channel (line: $line)"
continue
fi
channel=$( echo -e "$line"|cut -d'!' -f1 )
duration=$( echo -e "$line"|cut -d'!' -f12 )
debug "Channel '$channel' duration: '$duration'"
if [ $duration -gt $CRITICAL_SECONDS ]
then
debug "Channel '$channel' duration is CRITICAL"
let CRITICAL=CRITICAL+1
CRITICAL_CHANNELS="$CRITICAL_CHANNELS $channel"
elif [ $duration -gt $WARNING_SECONDS ]
then
debug "Channel '$channel' duration is WARNING"
let WARNING=WARNING+1
WARNING_CHANNELS="$WARNING_CHANNELS $channel"
else
debug "Channel '$channel' duration is OK"
let OK=OK+1
fi
done
debug "Critical channels count: $CRITICAL ($CRITICAL_CHANNELS)"
debug "Warning channels count: $WARNING ($WARNING_CHANNELS)"
debug "OK channels count: $OK"
if [ $CRITICAL -gt 0 ]
then
STATE=CRITICAL
EXITCODE=2
MSG="$CRITICAL channels open since more than $CRITICAL_HOURS hours"
elif [ $WARNING -gt 0 ]
then
STATE=WARNING
EXITCODE=1
MSG="$WARNING channels open since more than $WARNING_HOURS hours"
else
STATE=OK
EXITCODE=0
MSG="$OK channels open since less than $WARNING_HOURS hours"
fi
echo "$STATE - $MSG|ok=$OK,warning=$WARNING,critical=$CRITICAL"
[ -n "$CRITICAL_CHANNELS" ] && echo "Critical channels :$CRITICAL_CHANNELS"
[ -n "$WARNING_CHANNELS" ] && echo "Warning channels :$WARNING_CHANNELS"
exit $EXITCODE