diff options
Diffstat (limited to 'plugins-scripts/check_log.sh')
-rwxr-xr-x | plugins-scripts/check_log.sh | 58 |
1 files changed, 25 insertions, 33 deletions
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index a1bfb486..8653a5e1 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | # | 2 | # |
3 | # Log file pattern detector plugin for Nagios | 3 | # Log file pattern detector plugin for monitoring |
4 | # Written by Ethan Galstad (nagios@nagios.org) | 4 | # Written by Ethan Galstad (nagios@nagios.org) |
5 | # Last Modified: 07-31-1999 | 5 | # Last Modified: 07-31-1999 |
6 | # | 6 | # |
@@ -29,15 +29,15 @@ | |||
29 | # | 29 | # |
30 | # If you use this plugin make sure to keep the following in mind: | 30 | # If you use this plugin make sure to keep the following in mind: |
31 | # | 31 | # |
32 | # 1. The "max_attempts" value for the service should be 1, as this | 32 | # 1. The "max_attempts" value for the service should be 1, as this will |
33 | # will prevent Nagios from retrying the service check (the | 33 | # prevent the monitoring system from retrying the service check (the |
34 | # next time the check is run it will not produce the same results). | 34 | # next time the check is run it will not produce the same results). |
35 | # | 35 | # |
36 | # 2. The "notify_recovery" value for the service should be 0, so that | 36 | # 2. The "notify_recovery" value for the service should be 0, so that the |
37 | # Nagios does not notify you of "recoveries" for the check. Since | 37 | # monitoring system does not notify you of "recoveries" for the check. |
38 | # pattern matches in the log file will only be reported once and not | 38 | # Since pattern matches in the log file will only be reported once and |
39 | # the next time, there will always be "recoveries" for the service, even | 39 | # not the next time, there will always be "recoveries" for the service, |
40 | # though recoveries really don't apply to this type of check. | 40 | # even though recoveries really don't apply to this type of check. |
41 | # | 41 | # |
42 | # 3. You *must* supply a different <old_file_log> for each service that | 42 | # 3. You *must* supply a different <old_file_log> for each service that |
43 | # you define to use this plugin script - even if the different services | 43 | # you define to use this plugin script - even if the different services |
@@ -57,21 +57,13 @@ | |||
57 | 57 | ||
58 | # Paths to commands used in this script. These | 58 | # Paths to commands used in this script. These |
59 | # may have to be modified to match your system setup. | 59 | # may have to be modified to match your system setup. |
60 | # TV: removed PATH restriction. Need to think more about what this means overall | ||
61 | #PATH="" | ||
62 | |||
63 | ECHO="/bin/echo" | ||
64 | GREP="/bin/egrep" | ||
65 | DIFF="/bin/diff" | ||
66 | TAIL="/bin/tail" | ||
67 | CAT="/bin/cat" | ||
68 | RM="/bin/rm" | ||
69 | CHMOD="/bin/chmod" | ||
70 | TOUCH="/bin/touch" | ||
71 | 60 | ||
72 | PROGNAME=`/bin/basename $0` | 61 | PROGNAME=`/bin/basename $0` |
73 | PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` | 62 | PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` |
74 | REVISION="@NP_VERSION@" | 63 | REVISION="@NP_VERSION@" |
64 | PATH="@TRUSTED_PATH@" | ||
65 | |||
66 | export PATH | ||
75 | 67 | ||
76 | . $PROGPATH/utils.sh | 68 | . $PROGPATH/utils.sh |
77 | 69 | ||
@@ -86,7 +78,7 @@ print_help() { | |||
86 | echo "" | 78 | echo "" |
87 | print_usage | 79 | print_usage |
88 | echo "" | 80 | echo "" |
89 | echo "Log file pattern detector plugin for Nagios" | 81 | echo "Log file pattern detector plugin for monitoring" |
90 | echo "" | 82 | echo "" |
91 | support | 83 | support |
92 | } | 84 | } |
@@ -167,10 +159,10 @@ done | |||
167 | # If the source log file doesn't exist, exit | 159 | # If the source log file doesn't exist, exit |
168 | 160 | ||
169 | if [ ! -e $logfile ]; then | 161 | if [ ! -e $logfile ]; then |
170 | $ECHO "Log check error: Log file $logfile does not exist!\n" | 162 | echo "Log check error: Log file $logfile does not exist!" |
171 | exit $STATE_UNKNOWN | 163 | exit $STATE_UNKNOWN |
172 | elif [ ! -r $logfile ] ; then | 164 | elif [ ! -r $logfile ] ; then |
173 | $ECHO "Log check error: Log file $logfile is not readable!\n" | 165 | echo "Log check error: Log file $logfile is not readable!" |
174 | exit $STATE_UNKNOWN | 166 | exit $STATE_UNKNOWN |
175 | fi | 167 | fi |
176 | 168 | ||
@@ -179,8 +171,8 @@ fi | |||
179 | # the old diff file and exit | 171 | # the old diff file and exit |
180 | 172 | ||
181 | if [ ! -e $oldlog ]; then | 173 | if [ ! -e $oldlog ]; then |
182 | $CAT $logfile > $oldlog | 174 | cat $logfile > $oldlog |
183 | $ECHO "Log check data initialized...\n" | 175 | echo "Log check data initialized..." |
184 | exit $STATE_OK | 176 | exit $STATE_OK |
185 | fi | 177 | fi |
186 | 178 | ||
@@ -193,26 +185,26 @@ if [ -x /bin/mktemp ]; then | |||
193 | else | 185 | else |
194 | tempdiff=`/bin/date '+%H%M%S'` | 186 | tempdiff=`/bin/date '+%H%M%S'` |
195 | tempdiff="/tmp/check_log.${tempdiff}" | 187 | tempdiff="/tmp/check_log.${tempdiff}" |
196 | $TOUCH $tempdiff | 188 | touch $tempdiff |
197 | $CHMOD 600 $tempdiff | 189 | chmod 600 $tempdiff |
198 | fi | 190 | fi |
199 | 191 | ||
200 | $DIFF $logfile $oldlog | $GREP -v "^>" > $tempdiff | 192 | diff $logfile $oldlog | grep -v "^>" > $tempdiff |
201 | 193 | ||
202 | # Count the number of matching log entries we have | 194 | # Count the number of matching log entries we have |
203 | count=`$GREP -c "$query" $tempdiff` | 195 | count=`grep -c "$query" $tempdiff` |
204 | 196 | ||
205 | # Get the last matching entry in the diff file | 197 | # Get the last matching entry in the diff file |
206 | lastentry=`$GREP "$query" $tempdiff | $TAIL -1` | 198 | lastentry=`grep "$query" $tempdiff | tail -1` |
207 | 199 | ||
208 | $RM -f $tempdiff | 200 | rm -f $tempdiff |
209 | $CAT $logfile > $oldlog | 201 | cat $logfile > $oldlog |
210 | 202 | ||
211 | if [ "$count" = "0" ]; then # no matches, exit with no error | 203 | if [ "$count" = "0" ]; then # no matches, exit with no error |
212 | $ECHO "Log check ok - 0 pattern matches found\n" | 204 | echo "Log check ok - 0 pattern matches found" |
213 | exitstatus=$STATE_OK | 205 | exitstatus=$STATE_OK |
214 | else # Print total matche count and the last entry we found | 206 | else # Print total matche count and the last entry we found |
215 | $ECHO "($count) $lastentry" | 207 | echo "($count) $lastentry" |
216 | exitstatus=$STATE_CRITICAL | 208 | exitstatus=$STATE_CRITICAL |
217 | fi | 209 | fi |
218 | 210 | ||