diff options
author | Kristian Schuster <116557017+KriSchu@users.noreply.github.com> | 2023-02-19 23:49:18 +0100 |
---|---|---|
committer | Kristian Schuster <116557017+KriSchu@users.noreply.github.com> | 2023-02-19 23:49:18 +0100 |
commit | a0d42777217296c0a7bdb1e1be8d8f6de1b24dd7 (patch) | |
tree | 8effe94c57b2f9796ba36090b07551baa8f1e1cb /plugins-scripts/check_log.sh | |
parent | ca3d59cd6918c9e2739e783b721d4c1122640fd3 (diff) | |
parent | c07206f2ccc2356aa74bc6813a94c2190017d44e (diff) | |
download | monitoring-plugins-a0d4277.tar.gz |
Merge remote-tracking branch 'origin/master' into feature_check_disk_add_ignore_missing_option
Diffstat (limited to 'plugins-scripts/check_log.sh')
-rwxr-xr-x | plugins-scripts/check_log.sh | 99 |
1 files changed, 35 insertions, 64 deletions
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index fdb57416..c623a8d6 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh | |||
@@ -18,7 +18,7 @@ | |||
18 | # On the first run of the plugin, it will return an OK state with a message | 18 | # On the first run of the plugin, it will return an OK state with a message |
19 | # of "Log check data initialized". On successive runs, it will return an OK | 19 | # of "Log check data initialized". On successive runs, it will return an OK |
20 | # state if *no* pattern matches have been found in the *difference* between the | 20 | # state if *no* pattern matches have been found in the *difference* between the |
21 | # log file and the older copy of the log file. If the plugin detects any | 21 | # log file and the older copy of the log file. If the plugin detects any |
22 | # pattern matches in the log diff, it will return a CRITICAL state and print | 22 | # pattern matches in the log diff, it will return a CRITICAL state and print |
23 | # out a message is the following format: "(x) last_match", where "x" is the | 23 | # out a message is the following format: "(x) last_match", where "x" is the |
24 | # total number of pattern matches found in the file and "last_match" is the | 24 | # total number of pattern matches found in the file and "last_match" is the |
@@ -76,6 +76,7 @@ print_usage() { | |||
76 | echo "" | 76 | echo "" |
77 | echo "Other parameters:" | 77 | echo "Other parameters:" |
78 | echo " -a|--all : Print all matching lines" | 78 | echo " -a|--all : Print all matching lines" |
79 | echo " --exclude: Exclude a pattern (-p or -e also applies here when used)" | ||
79 | echo " -p|--perl-regex : Use perl style regular expressions in the query" | 80 | echo " -p|--perl-regex : Use perl style regular expressions in the query" |
80 | echo " -e|--extended-regex : Use extended style regular expressions in the query (not necessary for GNU grep)" | 81 | echo " -e|--extended-regex : Use extended style regular expressions in the query (not necessary for GNU grep)" |
81 | } | 82 | } |
@@ -99,82 +100,46 @@ if [ $# -lt 1 ]; then | |||
99 | fi | 100 | fi |
100 | 101 | ||
101 | # Grab the command line arguments | 102 | # Grab the command line arguments |
102 | |||
103 | #logfile=$1 | ||
104 | #oldlog=$2 | ||
105 | #query=$3 | ||
106 | exitstatus=$STATE_WARNING #default | 103 | exitstatus=$STATE_WARNING #default |
107 | while test -n "$1"; do | 104 | while test -n "$1"; do |
108 | case "$1" in | 105 | case "$1" in |
109 | --help) | 106 | -h | --help) |
110 | print_help | ||
111 | exit "$STATE_OK" | ||
112 | ;; | ||
113 | -h) | ||
114 | print_help | 107 | print_help |
115 | exit "$STATE_OK" | 108 | exit "$STATE_OK" |
116 | ;; | 109 | ;; |
117 | --version) | 110 | -V | --version) |
118 | print_revision "$PROGNAME" "$REVISION" | 111 | print_revision "$PROGNAME" "$REVISION" |
119 | exit "$STATE_OK" | 112 | exit "$STATE_OK" |
120 | ;; | 113 | ;; |
121 | -V) | 114 | -F | --filename) |
122 | print_revision "$PROGNAME" "$REVISION" | ||
123 | exit "$STATE_OK" | ||
124 | ;; | ||
125 | --filename) | ||
126 | logfile=$2 | 115 | logfile=$2 |
127 | shift 2 | 116 | shift 2 |
128 | ;; | 117 | ;; |
129 | -F) | 118 | -O | --oldlog) |
130 | logfile=$2 | ||
131 | shift 2 | ||
132 | ;; | ||
133 | --oldlog) | ||
134 | oldlog=$2 | 119 | oldlog=$2 |
135 | shift 2 | 120 | shift 2 |
136 | ;; | 121 | ;; |
137 | -O) | 122 | -q | --query) |
138 | oldlog=$2 | ||
139 | shift 2 | ||
140 | ;; | ||
141 | --query) | ||
142 | query=$2 | 123 | query=$2 |
143 | shift 2 | 124 | shift 2 |
144 | ;; | 125 | ;; |
145 | -q) | 126 | --exclude) |
146 | query=$2 | 127 | exclude=$2 |
147 | shift 2 | 128 | shift 2 |
148 | ;; | 129 | ;; |
149 | -x) | 130 | -x | --exitstatus) |
150 | exitstatus=$2 | 131 | exitstatus=$2 |
151 | shift 2 | 132 | shift 2 |
152 | ;; | 133 | ;; |
153 | --exitstatus) | 134 | -e | --extended-regex) |
154 | exitstatus=$2 | ||
155 | shift 2 | ||
156 | ;; | ||
157 | --extended-regex) | ||
158 | ERE=1 | 135 | ERE=1 |
159 | shift | 136 | shift |
160 | ;; | 137 | ;; |
161 | -e) | 138 | -p | --perl-regex) |
162 | ERE=1 | ||
163 | shift | ||
164 | ;; | ||
165 | --perl-regex) | ||
166 | PRE=1 | ||
167 | shift | ||
168 | ;; | ||
169 | -p) | ||
170 | PRE=1 | 139 | PRE=1 |
171 | shift | 140 | shift |
172 | ;; | 141 | ;; |
173 | --all) | 142 | -a | --all) |
174 | ALL=1 | ||
175 | shift | ||
176 | ;; | ||
177 | -a) | ||
178 | ALL=1 | 143 | ALL=1 |
179 | shift | 144 | shift |
180 | ;; | 145 | ;; |
@@ -188,18 +153,18 @@ done | |||
188 | 153 | ||
189 | # Parameter sanity check | 154 | # Parameter sanity check |
190 | if [ $ERE ] && [ $PRE ] ; then | 155 | if [ $ERE ] && [ $PRE ] ; then |
191 | echo "Can not use extended and perl regex at the same time" | 156 | echo "Can not use extended and perl regex at the same time" |
192 | exit "$STATE_UNKNOWN" | 157 | exit "$STATE_UNKNOWN" |
193 | fi | 158 | fi |
194 | 159 | ||
195 | GREP="grep" | 160 | GREP="grep" |
196 | 161 | ||
197 | if [ $ERE ]; then | 162 | if [ $ERE ]; then |
198 | GREP="grep -E" | 163 | GREP="grep -E" |
199 | fi | 164 | fi |
200 | 165 | ||
201 | if [ $PRE ]; then | 166 | if [ $PRE ]; then |
202 | GREP="grep -P" | 167 | GREP="grep -P" |
203 | fi | 168 | fi |
204 | 169 | ||
205 | # If the source log file doesn't exist, exit | 170 | # If the source log file doesn't exist, exit |
@@ -213,8 +178,8 @@ elif [ ! -r "$logfile" ] ; then | |||
213 | fi | 178 | fi |
214 | # If no oldlog was given this can not work properly, abort then | 179 | # If no oldlog was given this can not work properly, abort then |
215 | if [ -z "$oldlog" ]; then | 180 | if [ -z "$oldlog" ]; then |
216 | echo "Oldlog parameter is needed" | 181 | echo "Oldlog parameter is needed" |
217 | exit $STATE_UNKNOWN | 182 | exit $STATE_UNKNOWN |
218 | fi | 183 | fi |
219 | 184 | ||
220 | # If the old log file doesn't exist, this must be the first time | 185 | # If the old log file doesn't exist, this must be the first time |
@@ -245,18 +210,24 @@ diff "$logfile" "$oldlog" | grep -v "^>" > "$tempdiff" | |||
245 | 210 | ||
246 | 211 | ||
247 | if [ $ALL ]; then | 212 | if [ $ALL ]; then |
248 | # Get the last matching entry in the diff file | 213 | # Get all matching entries in the diff file |
249 | entry=$($GREP "$query" "$tempdiff") | 214 | if [ -n "$exclude" ]; then |
250 | 215 | entry=$($GREP "$query" "$tempdiff" | $GREP -v "$exclude") | |
251 | # Count the number of matching log entries we have | 216 | count=$($GREP "$query" "$tempdiff" | $GREP -vc "$exclude") |
252 | count=$(echo "$entry" | wc -l) | 217 | else |
218 | entry=$($GREP "$query" "$tempdiff") | ||
219 | count=$($GREP -c "$query" "$tempdiff") | ||
220 | fi | ||
253 | 221 | ||
254 | else | 222 | else |
255 | # Count the number of matching log entries we have | 223 | # Get the last matching entry in the diff file |
256 | count=$($GREP -c "$query" "$tempdiff") | 224 | if [ -n "$exclude" ]; then |
257 | 225 | entry=$($GREP "$query" "$tempdiff" | $GREP -v "$exclude" | tail -1) | |
258 | # Get the last matching entry in the diff file | 226 | count=$($GREP "$query" "$tempdiff" | $GREP -vc "$exclude") |
259 | entry=$($GREP "$query" "$tempdiff" | tail -1) | 227 | else |
228 | entry=$($GREP "$query" "$tempdiff" | tail -1) | ||
229 | count=$($GREP -c "$query" "$tempdiff") | ||
230 | fi | ||
260 | fi | 231 | fi |
261 | 232 | ||
262 | rm -f "$tempdiff" | 233 | rm -f "$tempdiff" |