89 lines
1.7 KiB
Bash
89 lines
1.7 KiB
Bash
#!/bin/sh
|
|
|
|
WARNING_RANGE="4:4"
|
|
CRITICAL_RANGE="3:5"
|
|
|
|
|
|
# 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 status" 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/^.\{41\}[[:space:]]*\([^[:space:]]\+\)[[:space:]]\+.*/\1/' | grep -c "OK" )"
|
|
|
|
|
|
# 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
|