Script - check_radmind

Revised: 2009-06-03 richard

Download Scripts – ZIP-File, 2.6 KB

check_radmind
# Add lines to radmind.hook so it logs the successes or failures.
# We then check the log and return to Nagios accordingly.

# Search the included radmind.nagios.hook for /var/log/radmind.log
# if you need to add them to your own radmind.hook

# This script only returns 0 - OK or 1 - Warning values
# If you need a critical on a radmind problem change the
# return codes accordingly

#!/usr/bin/perl
use strict;

$_ = `cat /var/log/radmind.log | tail -1`;
chomp;

if(m/Update Complete/){
    print "Radmind OK: $_\n";
    exit 0;
}
elsif(m/No updates./){
    print "Radmind OK: $_\n";
    exit 0;
}
elsif(m/No changes/){
    print "Radmind OK: $_\n";
    exit 0;
}elsif(m/error/){
    print "Radmind: $_\n";
    exit 1;
}
elsif(m/Bypassing/){
    print "Radmind: $_\n";
    exit 1;
}
else
{
    print "Radmind: No radmind session detected.";
    exit 1;
}

radmind.nagios.hook
#! /bin/sh

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

echo %CANCEL ENABLE
echo %WINDOWSIZE 640 480
echo %SHOWTIMER
echo %TITLE "Radmind update"
echo %WINDOWZOOM ENABLE
echo %BACKGROUND /etc/hooks/Fine_Arts_stacked.gif
echo %BECOMEKEY    
echo %UIMODE AUTOCRATIC    
echo %WINDOWLEVEL HIGH

trap "exit 0" 15

if [ -f /var/radmind/client/.DoNotRadmind ]; then
    echo Bypassing radmind. `date` >> /var/log/radmind.log
    sleep 2
    exit 0   
fi    

# Source config file to get default values
. /etc/radmind.defaults

if [ -f /var/radmind/client/.RadmindWithChecksums ]; then
    # force use of checksums
    CHECKSUM="-c sha1"
fi

cd /

echo %BEGINPOLE
echo Checking for changes on the server...

ktcheck -c sha1 -w ${TLSLEVEL} -h ${SERVER} 1>&2

rc="$?"

case "$rc" in
    0)
        echo No updates. `date` >> /var/log/radmind.log
        sleep 2

        if [ -f /var/radmind/client/.RadmindRunning ]; then
            echo Continuing with Radmind session...
        sleep 1
        else  
        exit 0
    fi
        ;;

    1)
        echo Updates found.
        sleep 5
        ;;

    *)
        echo An error occurred while checking for updates. `date`  >> /var/log/radmind.log
        exit $rc
        ;;
esac

echo %CANCEL REMOVE

# Touch a file to indicate that the radmind session has begun.
touch /var/radmind/client/.RadmindRunning

# Create a temp file that fsdiff will use for its output.
template="${RMTMPDIR}/diff.T.$$.XXXXXX"
FSDIFFOUTPUT=`mktemp -q ${template}`

while true; do

    echo Examining the filesystem for differences...

    fsdiff ${CHECKSUM} -o ${FSDIFFOUTPUT} -v -A ${FSDIFFPATH}

    case "$?" in
        0)
            ;;

        *)
            echo An error occurred while checking for filesystem differences. `date` >> /var/log/radmind.log
            exit 1
            ;;
    esac

    # Check the output file size. If 0, skip the lapply step.
    if [ -s ${FSDIFFOUTPUT} ]; then
    echo %70
        echo Applying changes from server...
        lapply -F ${CHECKSUM} -h ${SERVER} -w ${TLSLEVEL} ${FSDIFFOUTPUT} 1>&2

        case "$?" in
        0)
            break
            ;;

        1)
            echo Attempting to apply changes returned an error. No changes made. `date` >> /var/log/radmind.log
            exit 1
            ;;
        2)
            echo An error occurred while applying changes. Trying again... `date` >> /var/log/radmind.log
            echo %OPENDRAWER
            sleep 2
            echo %BEGINPOLE
            echo Checking for changes on the server...
            ktcheck -c sha1 -w ${TLSLEVEL} -h ${SERVER} 1>&2
            continue
            ;;

        esac
    else
        echo No changes necessary. `date` >> /var/log/radmind.log
        break
    fi
done

# remove the temporary file we used with fsdiff
rm -f ${FSDIFFOUTPUT}

logger -i -s -t RadmindHook Radmind update complete at `date`
echo Update Complete @ `date` >> /var/log/radmind.log
echo %100
echo Update complete, rebooting the system.
sleep 2

# Remove the flag to indicate that the radmind session is complete.
rm -f /var/radmind/client/.RadmindRunning
rm -f /var/radmind/client/.RadmindWithChecksums

# Remove the Extensions caches, if necessary
if [ -f /System/Library/Extensions.mkext \
             -a -n "`find /System/Library/Extensions \
                        -newer /System/Library/Extensions.mkext`" ]; then
    rm -f /System/Library/Extensions.mkext
    rm -f /System/Library/Extensions.kextcache
fi

# Remove the various caches

rm -rf /Library/Caches/*
rm -rf /System/Library/Caches/*

/bin/sync; /bin/sync; /bin/sync
/sbin/reboot