#!/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 </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