24 августа 2012 г.

nagios - Проверка на конфликт ip адресов

/usr/local/etc/nrpe.d/check_using_myip.cfg:
command[check_using_myip]=/usr/local/libexec/nagios/check_using_myip -F $ARG1$ -e "$ARG2$"

/usr/local/libexec/nagios/check_using_myip:

#!/bin/sh
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
TMP=/var/tmp/

. /usr/local/libexec/nagios/utils.sh

print_usage() {
    echo "Usage: $PROGNAME -F logfile -e pattern"
    echo "Usage: $PROGNAME --help"
}
print_help() {
    echo ""
    print_usage
    echo ""
    echo "Log file pattern detector plugin for Nagios"
    echo ""
    support
}
if [ $# -lt 2 ]; then
    print_usage
    exit $STATE_UNKNOWN
fi
while test -n "$1"; do
    case "$1" in
        --help)
            print_help
            exit $STATE_OK
            ;;
        -F)
            logfile=$2
            shift
            ;;
        -e)
            pattern=`echo $2`
            shift
            ;;
        *)
            echo "Unknown argument: $1"
            print_usage
            exit $STATE_UNKNOWN
            ;;
    esac
    shift
done
if [ ! -e $logfile ]; then
    $ECHO "Log check error: Log file $logfile does not exist!"
    exit $STATE_UNKNOWN
fi
offset=`basename $logfile`.offset
lines=`/usr/local/sbin/logtail -f $logfile -o${TMP}/$offset | grep -e "$pattern" | awk '{print $7}'`

if [ -z $lines ]; then
        $ECHO "OK: Nobody is using my ip address"
        exit $STATE_OK
else
        $ECHO "CRITICAL: Is using my IP address: $lines"
        exit $STATE_CRITICAL
fi

exit $STATE_UNKNOWN