diff options
author | rincewind <rincewind@vulgrim.de> | 2021-07-02 16:38:12 (GMT) |
---|---|---|
committer | rincewind <rincewind@vulgrim.de> | 2021-07-02 16:38:12 (GMT) |
commit | 53b77dee91f780b4d78839f881c642189b829e3c (patch) | |
tree | 6ea73d3ef108051a6840fa9841b4bbbac62b37e6 /plugins-scripts | |
parent | c2aa1a5fa2dd96c7186704901d33721a63b9cd03 (diff) | |
download | monitoring-plugins-53b77dee91f780b4d78839f881c642189b829e3c.tar.gz |
Add -a option to print all matching lines and -p and -e options for perl and extended RE
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-x | plugins-scripts/check_log.sh | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 6e9fbca..8af07b5 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh | |||
@@ -69,6 +69,11 @@ print_usage() { | |||
69 | echo "Usage: $PROGNAME -F logfile -O oldlog -q query" | 69 | echo "Usage: $PROGNAME -F logfile -O oldlog -q query" |
70 | echo "Usage: $PROGNAME --help" | 70 | echo "Usage: $PROGNAME --help" |
71 | echo "Usage: $PROGNAME --version" | 71 | echo "Usage: $PROGNAME --version" |
72 | echo "" | ||
73 | echo "Other parameters:" | ||
74 | echo " -a|--all : Print all matching lines" | ||
75 | echo " -p|--perl-regex : Use perl style regular expressions in the query" | ||
76 | echo " -e|--extended-regex : Use extended style regular expressions in the query (not necessary for GNU grep)" | ||
72 | } | 77 | } |
73 | 78 | ||
74 | print_help() { | 79 | print_help() { |
@@ -115,35 +120,35 @@ while test -n "$1"; do | |||
115 | ;; | 120 | ;; |
116 | --filename) | 121 | --filename) |
117 | logfile=$2 | 122 | logfile=$2 |
118 | shift | 123 | shift 2 |
119 | ;; | 124 | ;; |
120 | -F) | 125 | -F) |
121 | logfile=$2 | 126 | logfile=$2 |
122 | shift | 127 | shift 2 |
123 | ;; | 128 | ;; |
124 | --oldlog) | 129 | --oldlog) |
125 | oldlog=$2 | 130 | oldlog=$2 |
126 | shift | 131 | shift 2 |
127 | ;; | 132 | ;; |
128 | -O) | 133 | -O) |
129 | oldlog=$2 | 134 | oldlog=$2 |
130 | shift | 135 | shift 2 |
131 | ;; | 136 | ;; |
132 | --query) | 137 | --query) |
133 | query=$2 | 138 | query=$2 |
134 | shift | 139 | shift 2 |
135 | ;; | 140 | ;; |
136 | -q) | 141 | -q) |
137 | query=$2 | 142 | query=$2 |
138 | shift | 143 | shift 2 |
139 | ;; | 144 | ;; |
140 | -x) | 145 | -x) |
141 | exitstatus=$2 | 146 | exitstatus=$2 |
142 | shift | 147 | shift 2 |
143 | ;; | 148 | ;; |
144 | --exitstatus) | 149 | --exitstatus) |
145 | exitstatus=$2 | 150 | exitstatus=$2 |
146 | shift | 151 | shift 2 |
147 | ;; | 152 | ;; |
148 | --extended-regex) | 153 | --extended-regex) |
149 | ERE=1 | 154 | ERE=1 |
@@ -161,13 +166,20 @@ while test -n "$1"; do | |||
161 | PRE=1 | 166 | PRE=1 |
162 | shift | 167 | shift |
163 | ;; | 168 | ;; |
169 | --all) | ||
170 | ALL=1 | ||
171 | shift | ||
172 | ;; | ||
173 | -a) | ||
174 | ALL=1 | ||
175 | shift | ||
176 | ;; | ||
164 | *) | 177 | *) |
165 | echo "Unknown argument: $1" | 178 | echo "Unknown argument: $1" |
166 | print_usage | 179 | print_usage |
167 | exit "$STATE_UNKNOWN" | 180 | exit "$STATE_UNKNOWN" |
168 | ;; | 181 | ;; |
169 | esac | 182 | esac |
170 | shift | ||
171 | done | 183 | done |
172 | 184 | ||
173 | # Parameter sanity check | 185 | # Parameter sanity check |
@@ -176,6 +188,8 @@ if [ $ERE ] && [ $PRE ] ; then | |||
176 | exit "$STATE_UNKNOWN" | 188 | exit "$STATE_UNKNOWN" |
177 | fi | 189 | fi |
178 | 190 | ||
191 | GREP="grep" | ||
192 | |||
179 | if [ $ERE ]; then | 193 | if [ $ERE ]; then |
180 | GREP="grep -E" | 194 | GREP="grep -E" |
181 | fi | 195 | fi |
@@ -219,11 +233,20 @@ fi | |||
219 | 233 | ||
220 | diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" | 234 | diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" |
221 | 235 | ||
222 | # Count the number of matching log entries we have | 236 | if [ $ALL ]; then |
223 | count=$($GREP -c "$query" "$tempdiff") | 237 | # Get the last matching entry in the diff file |
238 | entry=$($GREP "$query" "$tempdiff") | ||
224 | 239 | ||
225 | # Get the last matching entry in the diff file | 240 | # Count the number of matching log entries we have |
226 | lastentry=$($GREP "$query" "$tempdiff" | tail -1) | 241 | count=$(echo "$entry" | wc -l) |
242 | |||
243 | else | ||
244 | # Count the number of matching log entries we have | ||
245 | count=$($GREP -c "$query" "$tempdiff") | ||
246 | |||
247 | # Get the last matching entry in the diff file | ||
248 | entry=$($GREP "$query" "$tempdiff" | tail -1) | ||
249 | fi | ||
227 | 250 | ||
228 | rm -f "$tempdiff" | 251 | rm -f "$tempdiff" |
229 | cat "$logfile" > "$oldlog" | 252 | cat "$logfile" > "$oldlog" |
@@ -232,7 +255,7 @@ if [ "$count" = "0" ]; then # no matches, exit with no error | |||
232 | echo "Log check ok - 0 pattern matches found" | 255 | echo "Log check ok - 0 pattern matches found" |
233 | exitstatus=$STATE_OK | 256 | exitstatus=$STATE_OK |
234 | else # Print total matche count and the last entry we found | 257 | else # Print total matche count and the last entry we found |
235 | echo "($count) $lastentry" | 258 | echo "($count) $entry" |
236 | exitstatus=$STATE_CRITICAL | 259 | exitstatus=$STATE_CRITICAL |
237 | fi | 260 | fi |
238 | 261 | ||