1
0
Fork 0
scripts-admin-quickndirty-p.../nagios/check_differences_via_rsync.sh

132 lines
2.6 KiB
Bash
Executable file

#!/bin/sh
# Petit script custom pour vérifier que, dans une
# architecture maître-esclave, certains fichiers de conf.
# ou certaines arborescences ont bien été déployées
# sur les 2
# GPL v3+
# Default values
RSYNC_OPTIONS="-n -aHAX --delete --out-format %n"
SERVERS_LIST=""
DEBUG_MODE=""
# Output
OUTPUT_EXIT_STATUS=0
OUTPUT_DETAIL_WARNING=""
OUTPUT_DETAIL_CRITICAL=""
OUTPUT_PERFDATA=""
PROGPATH=$( echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,' )
REVISION="0.1"
# Stop at the first non-catched error
set -e
# Include check_range()
. $PROGPATH/utils.sh
#
# Fonction d'aide
#
usage() {
cat <<EOF
Usage :
$0 -s srv1 [-s srv2] [-s ...] rep1/ rep2/ file3 ...
Returns OK ($STATE_OK) if rsync doesn't find any file to transfer,
CRITICAL ($STATE_CRITICAL) if it does.
No soft warning. Soft warnings are for pussies.
Wildcards can be used (or any rsync/bash trick, at your own risk...)
Don't forget the final '/' for directories.
For example :
$0 -s slave1.example.com -s slave2.example.com /etc/apache/ /etc/crontab /etc/libapache2-mod-jk/workers.properties
The options used for rsync are :
$RSYNC_OPTIONS
EOF
}
check_range_syntax() {
check_range 0 "$1" >/dev/null 2>&1
if [ "$?" -eq "2" ]; then
return 1
fi
return 0
}
# Some early checks
if ! which find >/dev/null 2>&1 ; then
echo "UNKNOWN 'find' not found."
exit 1
fi
#
# Gestion des paramètres
#
while getopts hs:v f; do
case "$f" in
'h')
usage
exit
;;
's')
# Yeah, I don't manage server name with space in it... Sorry...
# If you find a elegant way to do it, please mail !
SERVERS_LIST="$SERVERS_LIST $OPTARG"
;;
'v')
DEBUG_MODE="-v"
;;
\?)
usage
exit 1
;;
esac
done
shift $( expr $OPTIND - 1 )
TARGETS_LIST="$@"
if [ -z "$SERVERS_LIST" ]; then
OUTPUT_EXIT_STATUS=$STATE_UNKNOWN
OUTPUT_DETAIL_UNKNOWN="$OUTPUT_DETAIL_UNKNOWN (no server specified)"
else
for SERVER in $SERVERS_LIST; do
for TARGET in $TARGETS_LIST; do
if [ $( rsync $RSYNC_OPTIONS "$TARGET" "$SERVER:$TARGET" 2>&1 | wc -l ) -gt 0 ]; then
OUTPUT_EXIT_STATUS=$STATE_CRITICAL
OUTPUT_DETAIL_CRITICAL="$OUTPUT_DETAIL_CRITICAL $SERVER:$TARGET"
if [ -n "$DEBUG_MODE" ]; then
echo rsync $RSYNC_OPTIONS "$TARGET" "$SERVER:$TARGET"
rsync $RSYNC_OPTIONS "$TARGET" "$SERVER:$TARGET"
fi
fi
done
done
fi
case "$OUTPUT_EXIT_STATUS" in
'0')
printf "OK"
;;
'1')
printf "WARNING %s" "$OUTPUT_DETAIL_WARNING"
;;
'2')
printf "CRITICAL %s" "$OUTPUT_DETAIL_CRITICAL"
;;
*)
printf "UNKNOWN %s" "$OUTPUT_DETAIL_UNKNOWN"
;;
esac
# (pas de perfdata dans ce script)
#printf "|%s\n" "$OUTPUT_PERFDATA"
printf "\n"
# on supprime les retours à la ligne
exit $OUTPUT_EXIT_STATUS