diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-09-14 02:13:48 (GMT) |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-09-14 02:13:48 (GMT) |
commit | 4907426318fc394c3d11ba71a0694a0732cf8bf0 (patch) | |
tree | 610ad1077e3d46aa005f2f2be530f172d30c3f09 | |
parent | 2f496448dddd65ca1e1f6464fd63129ca0982477 (diff) | |
download | monitoring-plugins-4907426318fc394c3d11ba71a0694a0732cf8bf0.tar.gz |
patch from Matthew Peters <mattp@esec.com.au>, plus turned up a few bugs on my own
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@96 f882894a-f735-0410-b71e-b25c423dba1c
-rwxr-xr-x | plugins-scripts/check_log.sh | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/plugins-scripts/check_log.sh b/plugins-scripts/check_log.sh index 08e7fef..0f22156 100755 --- a/plugins-scripts/check_log.sh +++ b/plugins-scripts/check_log.sh | |||
@@ -74,27 +74,27 @@ REVISION=`echo '$Revision$' | /bin/sed -e 's/[^0-9.]//g'` | |||
74 | . $PROGPATH/utils.sh | 74 | . $PROGPATH/utils.sh |
75 | 75 | ||
76 | print_usage() { | 76 | print_usage() { |
77 | echo "Usage: $PROGNAME -F logfile -O oldlog -q query" | 77 | echo "Usage: $PROGNAME -F logfile -O oldlog -q query" |
78 | echo "Usage: $PROGNAME --help" | 78 | echo "Usage: $PROGNAME --help" |
79 | echo "Usage: $PROGNAME --version" | 79 | echo "Usage: $PROGNAME --version" |
80 | } | 80 | } |
81 | 81 | ||
82 | print_help() { | 82 | print_help() { |
83 | print_revision $PROGNAME $REVISION | 83 | print_revision $PROGNAME $REVISION |
84 | echo "" | 84 | echo "" |
85 | print_usage | 85 | print_usage |
86 | echo "" | 86 | echo "" |
87 | echo "Log file pattern detector plugin for Nagios" | 87 | echo "Log file pattern detector plugin for Nagios" |
88 | echo "" | 88 | echo "" |
89 | support | 89 | support |
90 | } | 90 | } |
91 | 91 | ||
92 | # Make sure the correct number of command line | 92 | # Make sure the correct number of command line |
93 | # arguments have been supplied | 93 | # arguments have been supplied |
94 | 94 | ||
95 | if [ $# -lt 1 ]; then | 95 | if [ $# -lt 1 ]; then |
96 | print_usage | 96 | print_usage |
97 | exit $STATE_UNKNOWN | 97 | exit $STATE_UNKNOWN |
98 | fi | 98 | fi |
99 | 99 | ||
100 | # Grab the command line arguments | 100 | # Grab the command line arguments |
@@ -104,69 +104,69 @@ fi | |||
104 | #query=$3 | 104 | #query=$3 |
105 | exitstatus=$STATE_WARNING #default | 105 | exitstatus=$STATE_WARNING #default |
106 | while test -n "$1"; do | 106 | while test -n "$1"; do |
107 | case "$1" in | 107 | case "$1" in |
108 | --help) | 108 | --help) |
109 | print_help | 109 | print_help |
110 | exit $STATE_OK | 110 | exit $STATE_OK |
111 | ;; | 111 | ;; |
112 | -h) | 112 | -h) |
113 | print_help | 113 | print_help |
114 | exit $STATE_OK | 114 | exit $STATE_OK |
115 | ;; | 115 | ;; |
116 | --version) | 116 | --version) |
117 | print_revision $PROGNAME $VERSION | 117 | print_revision $PROGNAME $VERSION |
118 | exit $STATE_OK | 118 | exit $STATE_OK |
119 | ;; | 119 | ;; |
120 | -V) | 120 | -V) |
121 | print_revision $PROGNAME $VERSION | 121 | print_revision $PROGNAME $VERSION |
122 | exit $STATE_OK | 122 | exit $STATE_OK |
123 | ;; | 123 | ;; |
124 | --filename) | 124 | --filename) |
125 | logfile=$2 | 125 | logfile=$2 |
126 | shift | 126 | shift |
127 | ;; | 127 | ;; |
128 | -F) | 128 | -F) |
129 | logfile=$2 | 129 | logfile=$2 |
130 | shift | 130 | shift |
131 | ;; | 131 | ;; |
132 | --oldlog) | 132 | --oldlog) |
133 | oldlog=$2 | 133 | oldlog=$2 |
134 | shift | 134 | shift |
135 | ;; | 135 | ;; |
136 | -O) | 136 | -O) |
137 | oldlog=$2 | 137 | oldlog=$2 |
138 | shift | 138 | shift |
139 | ;; | 139 | ;; |
140 | --query) | 140 | --query) |
141 | query=$2 | 141 | query=$2 |
142 | shift | 142 | shift |
143 | ;; | 143 | ;; |
144 | -q) | 144 | -q) |
145 | query=$2 | 145 | query=$2 |
146 | shift | 146 | shift |
147 | ;; | 147 | ;; |
148 | -x) | 148 | -x) |
149 | exitstatus=$2 | 149 | exitstatus=$2 |
150 | shift | 150 | shift |
151 | ;; | 151 | ;; |
152 | --exitstatus) | 152 | --exitstatus) |
153 | exitstatus=$2 | 153 | exitstatus=$2 |
154 | shift | 154 | shift |
155 | ;; | 155 | ;; |
156 | *) | 156 | *) |
157 | echo "Unknown argument: $1" | 157 | echo "Unknown argument: $1" |
158 | print_usage | 158 | print_usage |
159 | exit $STATE_UNKNOWN | 159 | exit $STATE_UNKNOWN |
160 | ;; | 160 | ;; |
161 | esac | 161 | esac |
162 | shift | 162 | shift |
163 | done | 163 | done |
164 | 164 | ||
165 | # If the source log file doesn't exist, exit | 165 | # If the source log file doesn't exist, exit |
166 | 166 | ||
167 | if [ ! -e $logfile ]; then | 167 | if [ ! -e $logfile ]; then |
168 | $ECHO "Log check error: Log file $logfile does not exist!\n" | 168 | $ECHO "Log check error: Log file $logfile does not exist!\n" |
169 | exit 2 | 169 | exit $STATE_UNKNOWN |
170 | fi | 170 | fi |
171 | 171 | ||
172 | # If the old log file doesn't exist, this must be the first time | 172 | # If the old log file doesn't exist, this must be the first time |
@@ -174,21 +174,22 @@ fi | |||
174 | # the old diff file and exit | 174 | # the old diff file and exit |
175 | 175 | ||
176 | if [ ! -e $oldlog ]; then | 176 | if [ ! -e $oldlog ]; then |
177 | $CAT $logfile > $oldlog | 177 | $CAT $logfile > $oldlog |
178 | $ECHO "Log check data initialized...\n" | 178 | $ECHO "Log check data initialized...\n" |
179 | exit 0 | 179 | exit $STATE_OK |
180 | fi | 180 | fi |
181 | 181 | ||
182 | # The old log file exists, so compare it to the original log now | 182 | # The old log file exists, so compare it to the original log now |
183 | 183 | ||
184 | # The temporary file that the script should use while | 184 | # The temporary file that the script should use while |
185 | # processing the log file. | 185 | # processing the log file. |
186 | if [-x /bin/mktemp]; then | 186 | if [ -x /bin/mktemp ]; then |
187 | tempdiff="/bin/mktemp /tmp/check_log.XXXXXXXXXX" | 187 | tempdiff=`/bin/mktemp /tmp/check_log.XXXXXXXXXX` |
188 | else | 188 | else |
189 | tempdiff="/tmp/check_log.`/bin/date '+%H%M%S'`" | 189 | tempdiff=`/bin/date '+%H%M%S'` |
190 | /bin/touch $tempdiff | 190 | tempdiff="/tmp/check_log.${tempdiff}" |
191 | chmod 600 $tempdiff | 191 | /bin/touch $tempdiff |
192 | chmod 600 $tempdiff | ||
192 | fi | 193 | fi |
193 | 194 | ||
194 | $DIFF $logfile $oldlog > $tempdiff | 195 | $DIFF $logfile $oldlog > $tempdiff |
@@ -203,12 +204,11 @@ $RM -f $tempdiff | |||
203 | $CAT $logfile > $oldlog | 204 | $CAT $logfile > $oldlog |
204 | 205 | ||
205 | if [ "$count" = "0" ]; then # no matches, exit with no error | 206 | if [ "$count" = "0" ]; then # no matches, exit with no error |
206 | $ECHO "Log check ok - 0 pattern matches found\n" | 207 | $ECHO "Log check ok - 0 pattern matches found\n" |
207 | exitstatus=0 | 208 | exitstatus=$STATE_OK |
208 | else # Print total matche count and the last entry we found | 209 | else # Print total matche count and the last entry we found |
209 | $ECHO "($count) $lastentry" | 210 | $ECHO "($count) $lastentry" |
211 | exitstatus=$STATE_CRITICAL | ||
210 | fi | 212 | fi |
211 | 213 | ||
212 | exit exitstatus | 214 | exit $exitstatus |
213 | |||
214 | |||