[Nagiosplug-devel] Patch for check_log: ignore patterns

Benjamin Stier benjamin.stier at ub.uni-tuebingen.de
Fri Feb 26 10:12:37 CET 2010


Hi list,

I wrote a small patch for the check_log plugin. This patch allows to specify a
regexp via --ignore which you don't want to be checked. My intention for this
was, that I only check for crashing processes with "exited with signal". But 
some programs crash everytime, especially when building ports 
(conftest, apr and stuff).
I would like to know if this patch can be put upstream, so I wouldn't have
to patch it for myself on every update.

Here's the patch:
==============================================================================

--- /usr/local/libexec/nagios/check_log 2009-07-03 20:13:05.000000000 +0200
+++ check_log   2010-02-26 00:18:40.000000000 +0100
@@ -76,7 +76,7 @@
 . $PROGPATH/utils.sh
 
 print_usage() {
-    echo "Usage: $PROGNAME -F logfile -O oldlog -q query"
+    echo "Usage: $PROGNAME -F logfile -O oldlog -q query [-i ignoreregexp]"
     echo "Usage: $PROGNAME --help"
     echo "Usage: $PROGNAME --version"
 }
@@ -139,6 +139,14 @@
             oldlog=$2
             shift
             ;;
+        -i)
+            nomatch=$2
+            shift
+            ;;
+        --ignore)
+            nomatch=$2
+            shift
+            ;;
         --query)
             query=$2
             shift
@@ -174,6 +182,14 @@
     exit $STATE_UNKNOWN
 fi
 
+# Maybe we want to ignore something
+# It's a simple egrep to discard this regexp
+if [ ! -z $nomatch ]; then
+    nomatch="|($nomatch)"
+else
+    nomatch=''
+fi
+
 # If the old log file doesn't exist, this must be the first time
 # we're running this test, so copy the original log file over to
 # the old diff file and exit
@@ -197,7 +213,7 @@
     $CHMOD 600 $tempdiff
 fi
 
-$DIFF $logfile $oldlog | $GREP -v "^>" > $tempdiff
+$DIFF $logfile $oldlog | $GREP -v "^>$nomatch" > $tempdiff
 
 # Count the number of matching log entries we have
 count=`$GREP -c "$query" $tempdiff`

==============================================================================

Kind regards,

	Benjamin




More information about the Devel mailing list