summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrincewind <rincewind@vulgrim.de>2021-07-02 18:01:47 +0200
committerrincewind <rincewind@vulgrim.de>2021-07-02 18:01:47 +0200
commitc2aa1a5fa2dd96c7186704901d33721a63b9cd03 (patch)
treee1f725ca8274d56c743c27ad93ed175cc2260b5b
parent14e1d7f6af409c28dab4732357a2b355a1ada85a (diff)
downloadmonitoring-plugins-c2aa1a5.tar.gz
Add extended and perl regex
-rwxr-xr-xplugins-scripts/check_log.sh34
1 files changed, 32 insertions, 2 deletions
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh
index 8a79704a..6e9fbca5 100755
--- a/plugins-scripts/check_log.sh
+++ b/plugins-scripts/check_log.sh
@@ -145,6 +145,22 @@ while test -n "$1"; do
145 exitstatus=$2 145 exitstatus=$2
146 shift 146 shift
147 ;; 147 ;;
148 --extended-regex)
149 ERE=1
150 shift
151 ;;
152 -e)
153 ERE=1
154 shift
155 ;;
156 --perl-regex)
157 PRE=1
158 shift
159 ;;
160 -p)
161 PRE=1
162 shift
163 ;;
148 *) 164 *)
149 echo "Unknown argument: $1" 165 echo "Unknown argument: $1"
150 print_usage 166 print_usage
@@ -154,6 +170,20 @@ while test -n "$1"; do
154 shift 170 shift
155done 171done
156 172
173# Parameter sanity check
174if [ $ERE ] && [ $PRE ] ; then
175 echo "Can not use extended and perl regex at the same time"
176 exit "$STATE_UNKNOWN"
177fi
178
179if [ $ERE ]; then
180 GREP="grep -E"
181fi
182
183if [ $PRE ]; then
184 GREP="grep -P"
185fi
186
157# If the source log file doesn't exist, exit 187# If the source log file doesn't exist, exit
158 188
159if [ ! -e "$logfile" ]; then 189if [ ! -e "$logfile" ]; then
@@ -190,10 +220,10 @@ fi
190diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" 220diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff"
191 221
192# Count the number of matching log entries we have 222# Count the number of matching log entries we have
193count=$(grep -c "$query" "$tempdiff") 223count=$($GREP -c "$query" "$tempdiff")
194 224
195# Get the last matching entry in the diff file 225# Get the last matching entry in the diff file
196lastentry=$(grep "$query" "$tempdiff" | tail -1) 226lastentry=$($GREP "$query" "$tempdiff" | tail -1)
197 227
198rm -f "$tempdiff" 228rm -f "$tempdiff"
199cat "$logfile" > "$oldlog" 229cat "$logfile" > "$oldlog"