Stale log files

Mark Snyder Mark.Snyder at worldgaming.com
Wed Oct 1 15:49:21 CEST 2003


I need to specify the WARN and CRIT values as seconds.  It looks like this script does the check of ODIFF and WARN or CRIT in seconds. If I change the text to read seconds instead of hours and remove the following lines

	WARN=`expr $WARN \* 60 \* 60`;
	CRIT=`expr $CRIT \* 60 \* 60`;

Should this work?

I will be testing it.  Just commenting on the script.

Mark Snyder


-----Original Message-----
From: Helmut Januschka [mailto:h.januschka at krone.at]
Sent: Wednesday, October 01, 2003 3:55 AM
To: Mark Snyder; nagios-users at lists.sourceforge.net
Subject: AW: [Nagios-users] Stale log files


hope outlook doesnt smash my script :)))

copy paste it into check_filemtime.sh

chmod +x it and run ./check_filemtime.sh -h



cu 
klewan
--------------------------
#!/bin/bash

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

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

. $PROGPATH/utils.sh

print_usage() {
        echo -e "File mTime Check Plugin $REVISION\nWritten by Helmut Januschka(klewan at chello.at)"
        echo -e "* Checks if Given FILE F has been written within last N Hours ";
        echo "---------------------Usage-----------------------------------------------"
        echo "-F File Def:/var/log/messages";
        echo "-w If not written in W hours WARN Def:2";
        echo "-c If not written in C hours CRITICAL Def:3";
        echo "-X Xtended Evaluate for FILE (e.g ls|grep new) Def:";
        echo "-Y Newest file from Directory -F (Must be a directory) Def:";
        echo "-h  Show This Help"
        echo "-------------------------------------------------------------------------"
        print_revision
}


#Seconds Converter

conv_sec() {
        SEC=$ODIFF;
        DAYS=`perl -e "print int($SEC/(24*60*60))"`;
        HOURS=`perl -e "print int(($SEC/(60*60))%24)"`;
        MINUTES=`perl -e "print int(($SEC/60)%60)"`;
        SECONDS=`perl -e "print int($SEC%60)"`;

        DIFF="$DAYS d $HOURS h $MINUTES m $SECONDS s";


}


#####


#Defs:
FILE=/var/log/messages
WARN=2
CRIT=3
YEST=0;


while getopts F:w:c:X:Y:h o
do
        case $o in
        F) FILE=$OPTARG;;
        w) WARN=$OPTARG;;
        c) CRIT=$OPTARG;;
        X) FILE=$FILE/`eval "$OPTARG"`;;
        Y) YEST=1;;
        h) print_usage; exit $STATE_UNKOWN;;

        esac


done
if [ $YEST = 1 ]; then
        # get neweset file from $FILE (wich is a directory)
        FILE=$FILE/`ls -t  $FILE|head -n 1`;
fi;

if [ -e $FILE ]; then
        #Fige is here
        FTIME=`stat -t $FILE|awk '{print $13}'`;
else
        echo "FileChecker($FILE, not found) [FigeNotFound] unkown `date`";
        exit $STATE_CRITICAL;
fi;

TNOW=`date +%s`
DIFF=`expr $TNOW \- $FTIME`
ODIFF=$DIFF;
EXT=""
WARN=`expr $WARN \* 60 \* 60`;
CRIT=`expr $CRIT \* 60 \* 60`;

conv_sec;

if [ $ODIFF -gt $CRIT ]; then #ahhh criticallll!!!
                echo "FileChecker($FILE, Differenc: $DIFF $EXT needed $CRIT seconds) [DiffCheck] critical `date`"
                exit $STATE_CRITICAL;
fi;

if [ $ODIFF -gt $WARN ]; then #then oooops we should warn :)

        echo "FileChecker($FILE, Differenc: $DIFF $EXT needed $WARN seconds) [DiffCheck] warning `date`"
        exit $STATE_WARNING;
                
fi;


echo "FileChecker($FILE, Differenc: $DIFF $EXT) [DiffCheck] ok `date`"



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list