112 lines
2.4 KiB
Bash
112 lines
2.4 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
# This script's purpose is to launch check_drupal with URL and
|
||
|
# password stored in a listing file.
|
||
|
#
|
||
|
# memento :
|
||
|
# drush en nagios
|
||
|
# drush vset nagios_page_path NAGIOS_PATH
|
||
|
# drush vset nagios_ua NAGIOS_PASSWORD
|
||
|
|
||
|
# Default options
|
||
|
NAGIOS_PLUGIN="/usr/lib/nagios/plugins/check_drupal"
|
||
|
DATABASE="/etc/nagios-plugins/check_drupal_multi.lst"
|
||
|
|
||
|
# Par défaut, on arrête le script à la première erreur non "catchée"
|
||
|
set -e
|
||
|
|
||
|
PROGPATH=$( echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,' )
|
||
|
REVISION="0.1"
|
||
|
|
||
|
. $PROGPATH/utils.sh
|
||
|
|
||
|
# Fonctions
|
||
|
# affiche le message d'aide
|
||
|
usage() {
|
||
|
cat <<EOF
|
||
|
$0 [ -C check_drupal path] [ -d listing_file ] [ -H host_name ] [ -t default time_out_seconds ]
|
||
|
$0 -h
|
||
|
|
||
|
-h : ce message d'aide
|
||
|
|
||
|
Listing_file is a text file with 3 fields, separated by tabulation.
|
||
|
1 : hostname
|
||
|
2 : UID
|
||
|
3 : path (optional)
|
||
|
4 : timeout (optional)
|
||
|
Example :
|
||
|
www.localdomain.com xxxyyyzzz
|
||
|
www.otherdomain.com zzzyyyxxx hiddennagios 30
|
||
|
|
||
|
Default options :
|
||
|
Database : $DATABASE
|
||
|
check_drupal path : $NAGIOS_PLUGIN
|
||
|
EOF
|
||
|
}
|
||
|
|
||
|
|
||
|
# Début du code
|
||
|
# gestion des options de lancement
|
||
|
while getopts C:d:H:t:h f; do
|
||
|
case $f in
|
||
|
'C')
|
||
|
NAGIOS_PLUGIN="$OPTARG"
|
||
|
;;
|
||
|
|
||
|
'd')
|
||
|
DATABASE="$OPTARG"
|
||
|
;;
|
||
|
|
||
|
'H')
|
||
|
NAGIOS_HOST="$OPTARG"
|
||
|
;;
|
||
|
|
||
|
't')
|
||
|
NAGIOS_DEFAULT_TIMEOUT="$OPTARG"
|
||
|
;;
|
||
|
|
||
|
'h')
|
||
|
usage
|
||
|
exit 0
|
||
|
;;
|
||
|
|
||
|
\?)
|
||
|
usage >&2
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
#(code inutile, mais que je garde parce qu'on ne sait jamais)
|
||
|
#shift $( expr $OPTIND - 1 )
|
||
|
#DATA="$1"
|
||
|
|
||
|
# Petite vérif.
|
||
|
if [ ! -f "$DATABASE" ]; then
|
||
|
echo "UNKNOWN: no check_drupal_multi listing found."
|
||
|
exit $STATE_UNKNOWN
|
||
|
fi
|
||
|
if [ ! -f "$NAGIOS_PLUGIN" ]; then
|
||
|
echo "UNKNOWN: check_drupal could not be found."
|
||
|
exit $STATE_UNKNOWN
|
||
|
fi
|
||
|
|
||
|
# Lookup for host in database
|
||
|
DATABASE_LINE="$( grep -w "^$NAGIOS_HOST" "$DATABASE" | head -n 1 )"
|
||
|
NAGIOS_DRUPAL_UID="$( printf "$DATABASE_LINE" | cut -f 2 )"
|
||
|
NAGIOS_DRUPALPATH="$( printf "$DATABASE_LINE" | cut -f 3 )"
|
||
|
NAGIOS_TIMEOUT="$( printf "$DATABASE_LINE" | cut -f 4 )"
|
||
|
if [ -z "$NAGIOS_TIMEOUT" ]; then
|
||
|
NAGIOS_TIMEOUT="$NAGIOS_DEFAULT_TIMEOUT"
|
||
|
fi
|
||
|
|
||
|
# Check we actually got a host
|
||
|
if [ -z "$NAGIOS_DRUPAL_UID" ]; then
|
||
|
echo "UNKNOWN: Host not found in listing file."
|
||
|
exit $STATE_UNKNOWN
|
||
|
fi
|
||
|
|
||
|
# Launch the actual plugin with config
|
||
|
$NAGIOS_PLUGIN -H "$NAGIOS_HOST" -U "$NAGIOS_DRUPAL_UID" \
|
||
|
$( test -n "$NAGIOS_DRUPALPATH" && printf "%s %s" "-P" "$NAGIOS_DRUPALPATH" ) \
|
||
|
$( test -n "$NAGIOS_TIMEOUT" && printf "%s %s" "-t" "$NAGIOS_TIMEOUT" )
|