#! /bin/sh # # Slave host checker # Written by Anarcat (anarcat@koumbit.org) # # Usage: ./check_slaves ... # # Description: # # This plugin will scan a directory for zone files and will check that the # slaves specified on the commandline properly answer SOA requests for the # domains. # Output: # # If all slaves respond properly, it will output OK: all slaves synced # # If one slaves responds badly, it will output WARNING: ... # # If more than one slave responds badly, it will output CRITICAL: ..., ... # # Notes: # # It is expected that you check all NS servers for the domains, since one # failure is not critical. If you check only the slave servers and not the # master, this would be a potential critical solution, so also check the # master. # # With a lot of domains, this plugin may timeout nagios. # # This will probably be ran from NRPE since it expects to find the domain files # locally. # # Examples: # # check_slaves ns0.example.com ns1.example.com # Paths to commands used in this script. These # may have to be modified to match your system setup. # TV: removed PATH restriction. Need to think more about what this means overall #PATH="" ECHO="/bin/echo" GREP="/bin/egrep" DIFF="/usr/bin/diff" TAIL="/usr/bin/tail" CAT="/bin/cat" RM="/bin/rm" CHMOD="/bin/chmod" TOUCH="/bin/touch" PROGNAME=`/usr/bin/basename $0` PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` REVISION=`echo '$Revision$' | sed -e 's/[^0-9.]//g'` if [ $PROGPATH = "." ]; then PROGPATH=/usr/lib/nagios/plugins fi . $PROGPATH/utils.sh print_usage() { echo "Usage: $PROGNAME [ -s ] [ -v ] [ -d ] [ ] [ ... ]" } print_help() { print_revision $PROGNAME $REVISION echo "" print_usage echo "" echo "Log file pattern detector plugin for Nagios" echo "" support } directory="/var/alternc/bind/zones" exitstatus=$STATE_WARNING #default args=`getopt vhd:s: $*` set -- $args for i; do case "$1" in -h) print_help exit $STATE_OK ;; -d) directory=$2 shift ;; -s) nsca=$2 shift ;; -v) verbose=1 ;; --) shift break ;; -*) echo "Unknown argument: $1" print_usage exit $STATE_UNKNOWN ;; esac shift done # Make sure the correct number of command line # arguments have been supplied if [ $# -lt 1 ]; then echo "Not enough arguments: $#" print_usage exit $STATE_UNKNOWN fi status=$STATE_OK status_r="OK" message="" for slave in $* do tmp_msg="" [ ! -z "$verbose" ] && echo "Checking slave $slave..." for domain in `ls $directory` do if [ -z "$verbose" ] ; then flag="-q" else flag="" fi if ! host -W 3 -t soa $domain $slave | grep $flag 'has SOA record'; then if [ $status -eq $STATE_OK ]; then status=$STATE_WARNING status_r="WARNING" else status=$STATE_CRITICAL status_r="CRITICAL" fi if [ -z "$tmp_msg" -a -z "$nsca" ] ; then tmp_msg="$slave:" fi tmp_msg="$tmp_msg $domain" fi done if [ ! -z "$tmp_msg" ] ; then if [ -z "$message" ] ; then message="$tmp_msg" else message="$message, $tmp_msg" fi fi if [ ! -z "$nsca" ] ; then if [ $status -eq $STATE_OK ] ; then printf "$slave\tDNS replication\t$status\t$status_r: all domains answered for properly\n" | /usr/sbin/send_nsca -H $nsca else printf "$slave\tDNS replication\t$status\t$status_r: no SOA response for domains $tmp_msg\n" | /usr/sbin/send_nsca -H $nsca fi fi done if [ -z "$nsca" ] ; then if [ $status -eq $STATE_OK ] ; then echo "nameservers OK: $*" else echo "nameservers $status_r $message" fi fi exit $status