[monitoring-plugins] Add extended and perl regex

rincewind git at monitoring-plugins.org
Sun Nov 28 14:40:10 CET 2021


 Module: monitoring-plugins
 Branch: master
 Commit: c2aa1a5fa2dd96c7186704901d33721a63b9cd03
 Author: rincewind <rincewind at vulgrim.de>
   Date: Fri Jul  2 18:01:47 2021 +0200
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=c2aa1a5

Add extended and perl regex

---

 plugins-scripts/check_log.sh | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
index 8a79704..6e9fbca 100755
--- a/plugins-scripts/check_log.sh
+++ b/plugins-scripts/check_log.sh
@@ -145,6 +145,22 @@ while test -n "$1"; do
             exitstatus=$2
             shift
             ;;
+        --extended-regex)
+            ERE=1
+            shift
+            ;;
+        -e)
+            ERE=1
+            shift
+            ;;
+        --perl-regex)
+            PRE=1
+            shift
+            ;;
+        -p)
+            PRE=1
+            shift
+            ;;
         *)
             echo "Unknown argument: $1"
             print_usage
@@ -154,6 +170,20 @@ while test -n "$1"; do
     shift
 done
 
+# Parameter sanity check
+if [ $ERE ] && [ $PRE ] ; then
+	echo "Can not use extended and perl regex at the same time"
+	exit "$STATE_UNKNOWN"
+fi
+
+if [ $ERE ]; then
+	GREP="grep -E"
+fi
+
+if [ $PRE ]; then
+	GREP="grep -P"
+fi
+
 # If the source log file doesn't exist, exit
 
 if [ ! -e "$logfile" ]; then
@@ -190,10 +220,10 @@ fi
 diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff"
 
 # Count the number of matching log entries we have
-count=$(grep -c "$query" "$tempdiff")
+count=$($GREP -c "$query" "$tempdiff")
 
 # Get the last matching entry in the diff file
-lastentry=$(grep "$query" "$tempdiff" | tail -1)
+lastentry=$($GREP "$query" "$tempdiff" | tail -1)
 
 rm -f "$tempdiff"
 cat "$logfile" > "$oldlog"



More information about the Commits mailing list