89 lines
1.6 KiB
Bash
Executable file
89 lines
1.6 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
WARNING_RANGE="9:9"
|
|
CRITICAL_RANGE="8:10"
|
|
|
|
|
|
# Note needed in this version of the script
|
|
#set -e
|
|
|
|
PROGPATH=$( echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,' )
|
|
REVISION="0.1"
|
|
|
|
. $PROGPATH/utils.sh
|
|
|
|
#
|
|
# Fonction d'aide
|
|
#
|
|
usage() {
|
|
cat <<EOF
|
|
Usage :
|
|
$0 -h
|
|
$0 [-w warning_range] [-c critical_range]
|
|
|
|
Valeurs par défaut:
|
|
warning_range: $WARNING_RANGE
|
|
critical_range: $CRITICAL_RANGE
|
|
EOF
|
|
}
|
|
|
|
#
|
|
# Gestion des paramètres
|
|
#
|
|
while getopts hw:c:W:C: f; do
|
|
case "$f" in
|
|
'h')
|
|
usage
|
|
exit
|
|
;;
|
|
|
|
'w')
|
|
WARNING_RANGE="$OPTARG"
|
|
;;
|
|
|
|
'c')
|
|
CRITICAL_RANGE="$OPTARG"
|
|
;;
|
|
|
|
\?)
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
|
|
#
|
|
# Lancement de la commande
|
|
#
|
|
# Note : on lance les traitements "sûrs" (décompte) ensuite pour
|
|
# bien capturer un éventuel échec de la commande
|
|
# principale.
|
|
# En outre, grep retourne un code d'erreur si aucune
|
|
# occurrence n'est trouvée.
|
|
RESULT="$( asterisk -rx "dahdi show channels" 2>&1 )"
|
|
|
|
# Si la commande ne s'est pas correctement executée,
|
|
# on renvoie unknown
|
|
if [ "$?" -ne 0 ]; then
|
|
echo "UNKNOWN : error at command launch : $RESULT"
|
|
exit $STATE_UNKNOWN
|
|
fi
|
|
# Décompte
|
|
RESULT="$( printf "%s" "$RESULT" | tail -n +2 | sed 's/^.\{77\}[[:space:]]*//' | grep -c "In Service" )"
|
|
|
|
|
|
# Ventilation selon valeur
|
|
RETURN_STATUS=$STATE_OK
|
|
RETURN_OUTPUT="OK"
|
|
if check_range "$RESULT" "$CRITICAL_RANGE"; then
|
|
RETURN_STATUS=$STATE_CRITICAL
|
|
RETURN_OUTPUT="CRITICAL"
|
|
elif check_range "$RESULT" "$WARNING_RANGE"; then
|
|
RETURN_STATUS=$STATE_WARNING
|
|
RETURN_OUTPUT="WARNING"
|
|
fi
|
|
|
|
# Affichage final
|
|
printf "%s | val=%d;%s;%s\n" "$RETURN_OUTPUT" "$RESULT" "$WARNING_RANGE" "$CRITICAL_RANGE"
|
|
exit $RETURN_STATUS
|