Sfoglia il codice sorgente

Update check_log.sh

Added perf return code
Added a parameter -w (--max_warning) defining upper value to return a warning code. Otherwise will return critical
*Note: it wont change the functionality of the script, unless you use -w or --max_warning parameter!
arvanus 11 anni fa
parent
commit
d36a5a7432
1 ha cambiato i file con 18 aggiunte e 3 eliminazioni
  1. 18 3
      plugins-scripts/check_log.sh

+ 18 - 3
plugins-scripts/check_log.sh

@@ -80,6 +80,9 @@ print_usage() {
     echo "Usage: $PROGNAME -F logfile -O oldlog -q query"
     echo "Usage: $PROGNAME --help"
     echo "Usage: $PROGNAME --version"
+    echo "     Aditional parameter:"
+    echo "        -w (--max_warning) If used, determines the maximum matching value to return as warning, when finding more matching lines than this parameter will return as critical. If not used, will consider as default 0 (any matching will consider as critical)"
+
 }
 
 print_help() {
@@ -140,6 +143,14 @@ while test -n "$1"; do
             oldlog=$2
             shift
             ;;
+        --max_warning)
+            MAX_WARNING=$2
+            shift
+            ;;
+        -w)
+            MAX_WARNING=$2
+            shift
+            ;;
         --query)
             query=$2
             shift
@@ -210,11 +221,15 @@ $RM -f $tempdiff
 $CAT $logfile > $oldlog
 
 if [ "$count" = "0" ]; then # no matches, exit with no error
-    echo "Log check ok - 0 pattern matches found"
+    echo "Log check ok - 0 pattern matches found|match=$count;;;0"
     exitstatus=$STATE_OK
 else # Print total matche count and the last entry we found
-    echo "($count) $lastentry"
-    exitstatus=$STATE_CRITICAL
+    echo "($count) $lastentry|match=$count;;;0"
+    if [ $MAX_WARNING ] && [ $count -le $MAX_WARNING ] ; then
+        exitstatus=$STATE_WARNING
+    else
+        exitstatus=$STATE_CRITICAL
+    fi
 fi
 
 exit $exitstatus