#!/bin/sh


PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"

ECHO="/bin/echo"
GREP="/bin/grep"
DIFF="/usr/bin/diff"
TAIL="/bin/tail"
CAT="/bin/cat"
RM="/bin/rm"

COMMAND_FILE="/usr/local/nagios/libexec/raid.commands"
GOOD_CONFIG_FILE="/usr/local/nagios/libexec/raid.good.config"

PROGNAME=`/bin/basename $0`
PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1.3 $' | /bin/sed -e 's/[^0-9.]//g'`

. $PROGPATH/utils.sh



   
print_usage() {
    echo "Usage: $PROGNAME --help"
    echo "Usage: $PROGNAME --version"
    echo "Usage: $PROGNAME --execute"
}

print_help() {
    print_revision $PROGNAME $REVISION
    echo ""
    print_usage
    echo ""
    support
}

# Make sure the correct number of command line
# arguments have been supplied

if [ $# -lt 1 ]; then
    print_usage
    exit $STATE_UNKNOWN
fi

# Grab the command line arguments

#logfile=$1
#oldlog=$2
#query=$3
exitstatus=$STATE_WARNING #default
while test -n "$1"; do
    case "$1" in
        --help)
            print_help
            exit $STATE_OK
            ;;
        -h)
            print_help
            exit $STATE_OK
            ;;
        --version)
            print_revision $PROGNAME $VERSION
            exit $STATE_OK
            ;;
        -V)
            print_revision $PROGNAME $VERSION
            exit $STATE_OK
            ;;
        --execute)
            ;;
        *)
            echo "Unknown argument: $1"
            print_usage
            exit $STATE_UNKNOWN
            ;;
    esac
    shift
done

if [ ! -e $COMMAND_FILE ]; then
    $ECHO "RAID check : $COMMAND_FILE not found\n"
    exit $STATE_UNKNOWN
fi

if [ ! -e $GOOD_CONFIG_FILE ]; then
    $ECHO "RAID check : $GOOD_CONFIG_FILE not found\n"
    exit $STATE_UNKNOWN
fi


cd /usr/local/nagios/libexec/
$RM -f raid.current.config
/usr/sbin/afacli < $COMMAND_FILE > /dev/null
curdiff=`$DIFF raid.current.config $GOOD_CONFIG_FILE`
raiderr=`$CAT raid.current.config`

if [ "$curdiff" != "" ]
then
        $ECHO "RAID check CRITICAL\n"
        exit $STATE_CRITICAL
else
        $ECHO "RAID check OK\n"
        exit $STATE_OK
fi

