diff options
author | rincewind <rincewind@vulgrim.de> | 2021-07-02 18:01:47 +0200 |
---|---|---|
committer | rincewind <rincewind@vulgrim.de> | 2021-07-02 18:01:47 +0200 |
commit | c2aa1a5fa2dd96c7186704901d33721a63b9cd03 (patch) | |
tree | e1f725ca8274d56c743c27ad93ed175cc2260b5b | |
parent | 14e1d7f6af409c28dab4732357a2b355a1ada85a (diff) | |
download | monitoring-plugins-c2aa1a5.tar.gz |
Add extended and perl regex
-rwxr-xr-x | plugins-scripts/check_log.sh | 34 |
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 |
155 | done | 171 | done |
156 | 172 | ||
173 | # Parameter sanity check | ||
174 | if [ $ERE ] && [ $PRE ] ; then | ||
175 | echo "Can not use extended and perl regex at the same time" | ||
176 | exit "$STATE_UNKNOWN" | ||
177 | fi | ||
178 | |||
179 | if [ $ERE ]; then | ||
180 | GREP="grep -E" | ||
181 | fi | ||
182 | |||
183 | if [ $PRE ]; then | ||
184 | GREP="grep -P" | ||
185 | fi | ||
186 | |||
157 | # If the source log file doesn't exist, exit | 187 | # If the source log file doesn't exist, exit |
158 | 188 | ||
159 | if [ ! -e "$logfile" ]; then | 189 | if [ ! -e "$logfile" ]; then |
@@ -190,10 +220,10 @@ fi | |||
190 | diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" | 220 | diff "$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 |
193 | count=$(grep -c "$query" "$tempdiff") | 223 | count=$($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 |
196 | lastentry=$(grep "$query" "$tempdiff" | tail -1) | 226 | lastentry=$($GREP "$query" "$tempdiff" | tail -1) |
197 | 227 | ||
198 | rm -f "$tempdiff" | 228 | rm -f "$tempdiff" |
199 | cat "$logfile" > "$oldlog" | 229 | cat "$logfile" > "$oldlog" |