[Nagiosplug-devel] changes to check_log
Brian S Queen
bqueen at nas.nasa.gov
Fri Jul 25 15:03:02 CEST 2003
I changed check_log a bit, because I didn't want it to make copies of my
massive log files. It still writes small diff files to tmp, but it no
longer keeps a copy of the log file. I think it would be pretty easy to
eliminate the tmp file too. Here is a patch (is this a useful patch?):
--- ./check_log Fri Jul 25 14:44:10 2003
+++ /usr/local/nagios/libexec/check_log Fri Jul 25 11:24:51 2003
@@ -66,6 +66,9 @@
TAIL="/usr/bin/tail"
CAT="/bin/cat"
RM="/bin/rm"
+WC="/usr/bin/wc"
+AWK="/bin/awk"
+SED="/bin/sed"
PROGNAME=`/bin/basename $0`
PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
@@ -173,12 +176,24 @@
# we're running this test, so copy the original log file over to
# the old diff file and exit
+new_offset_line=`$WC -l $logfile`
if [ ! -e $oldlog ]; then
- $CAT $logfile > $oldlog
+ $ECHO '%s %s\n' $new_offset_line > $oldlog
$ECHO "Log check data initialized...\n"
exit $STATE_OK
fi
+#grab the offset
+#this program secretly use printf not echo
+new_offset_count=`$ECHO '%s %s\n' $new_offset_line | $AWK '{print $1}'`
+
+offset_count=`$CAT $oldlog | $AWK '{print $1}' `
+
+if [ "$offset_count" = "0" ]; then # no new data
+ $ECHO "Log check ok - no data found"
+ exitstatus=$STATE_OK
+fi
+
# The old log file exists, so compare it to the original log now
# The temporary file that the script should use while
@@ -192,7 +207,10 @@
chmod 600 $tempdiff
fi
-$DIFF $logfile $oldlog > $tempdiff
+#start at the NEXT line
+offset_count=$[$offset_count + 1]
+
More information about the Devel
mailing list