diff options
-rwxr-xr-x | plugins-scripts/check_mailq.pl | 1015 |
1 files changed, 507 insertions, 508 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 26336b99..abdc7736 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl | |||
@@ -29,8 +29,8 @@ use POSIX; | |||
29 | use strict; | 29 | use strict; |
30 | use Getopt::Long; | 30 | use Getopt::Long; |
31 | use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s $opt_d | 31 | use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s $opt_d |
32 | $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq $mailq_args | 32 | $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq $mailq_args |
33 | @lines %srcdomains %dstdomains); | 33 | @lines %srcdomains %dstdomains); |
34 | use FindBin; | 34 | use FindBin; |
35 | use lib "$FindBin::Bin"; | 35 | use lib "$FindBin::Bin"; |
36 | use utils qw(%ERRORS &print_revision &support &usage ); | 36 | use utils qw(%ERRORS &print_revision &support &usage ); |
@@ -45,7 +45,7 @@ $ENV{'PATH'}='@TRUSTED_PATH@'; | |||
45 | $ENV{'BASH_ENV'}=''; | 45 | $ENV{'BASH_ENV'}=''; |
46 | $ENV{'ENV'}=''; | 46 | $ENV{'ENV'}=''; |
47 | $PROGNAME = "check_mailq"; | 47 | $PROGNAME = "check_mailq"; |
48 | $mailq = 'sendmail'; # default | 48 | $mailq = 'sendmail'; # default |
49 | $msg_q = 0 ; | 49 | $msg_q = 0 ; |
50 | $msg_p = 0 ; | 50 | $msg_p = 0 ; |
51 | # If appended, must start with a space | 51 | # If appended, must start with a space |
@@ -55,28 +55,28 @@ $state = $ERRORS{'UNKNOWN'}; | |||
55 | Getopt::Long::Configure('bundling'); | 55 | Getopt::Long::Configure('bundling'); |
56 | $status = process_arguments(); | 56 | $status = process_arguments(); |
57 | if ($status){ | 57 | if ($status){ |
58 | print "ERROR: processing arguments\n"; | 58 | print "ERROR: processing arguments\n"; |
59 | exit $ERRORS{"UNKNOWN"}; | 59 | exit $ERRORS{"UNKNOWN"}; |
60 | } | 60 | } |
61 | 61 | ||
62 | if ($opt_s) { | 62 | if ($opt_s) { |
63 | if (defined $utils::PATH_TO_SUDO && -x $utils::PATH_TO_SUDO) { | 63 | if (defined $utils::PATH_TO_SUDO && -x $utils::PATH_TO_SUDO) { |
64 | $sudo = $utils::PATH_TO_SUDO; | 64 | $sudo = $utils::PATH_TO_SUDO; |
65 | } else { | 65 | } else { |
66 | print "ERROR: Cannot execute sudo\n"; | 66 | print "ERROR: Cannot execute sudo\n"; |
67 | exit $ERRORS{'UNKNOWN'}; | 67 | exit $ERRORS{'UNKNOWN'}; |
68 | } | 68 | } |
69 | } else { | 69 | } else { |
70 | $sudo = ""; | 70 | $sudo = ""; |
71 | } | 71 | } |
72 | 72 | ||
73 | if ($opt_d) { | 73 | if ($opt_d) { |
74 | $mailq_args = $mailq_args . ' -C ' . $opt_d; | 74 | $mailq_args = $mailq_args . ' -C ' . $opt_d; |
75 | } | 75 | } |
76 | 76 | ||
77 | $SIG{'ALRM'} = sub { | 77 | $SIG{'ALRM'} = sub { |
78 | print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); | 78 | print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); |
79 | exit $ERRORS{"WARNING"}; | 79 | exit $ERRORS{"WARNING"}; |
80 | }; | 80 | }; |
81 | alarm($opt_t); | 81 | alarm($opt_t); |
82 | 82 | ||
@@ -84,21 +84,21 @@ alarm($opt_t); | |||
84 | 84 | ||
85 | if ($mailq eq "sendmail") { | 85 | if ($mailq eq "sendmail") { |
86 | 86 | ||
87 | ## open mailq | 87 | ## open mailq |
88 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 88 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
89 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { | 89 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { |
90 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | 90 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; |
91 | exit $ERRORS{'UNKNOWN'}; | 91 | exit $ERRORS{'UNKNOWN'}; |
92 | } | 92 | } |
93 | }elsif( defined $utils::PATH_TO_MAILQ){ | 93 | }elsif( defined $utils::PATH_TO_MAILQ){ |
94 | unless (-x $utils::PATH_TO_MAILQ) { | 94 | unless (-x $utils::PATH_TO_MAILQ) { |
95 | print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; | 95 | print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; |
96 | exit $ERRORS{'UNKNOWN'}; | 96 | exit $ERRORS{'UNKNOWN'}; |
97 | } | 97 | } |
98 | } else { | 98 | } else { |
99 | print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; | 99 | print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; |
100 | exit $ERRORS{'UNKNOWN'}; | 100 | exit $ERRORS{'UNKNOWN'}; |
101 | } | 101 | } |
102 | # single queue empty | 102 | # single queue empty |
103 | ##/var/spool/mqueue is empty | 103 | ##/var/spool/mqueue is empty |
104 | # single queue: 1 | 104 | # single queue: 1 |
@@ -168,190 +168,189 @@ if ($mailq eq "sendmail") { | |||
168 | ## /var/spool/mqueue is empty | 168 | ## /var/spool/mqueue is empty |
169 | ## Total requests: 0 | 169 | ## Total requests: 0 |
170 | 170 | ||
171 | my $this_msg_q = 0; | 171 | my $this_msg_q = 0; |
172 | while (<MAILQ>) { | 172 | while (<MAILQ>) { |
173 | 173 | ||
174 | # match email addr on queue listing | 174 | # match email addr on queue listing |
175 | if ( (/<.*@.*\.(\w+\.\w+)>/) || (/<.*@(\w+\.\w+)>/) ) { | 175 | if ( (/<.*@.*\.(\w+\.\w+)>/) || (/<.*@(\w+\.\w+)>/) ) { |
176 | my $domain = $1; | 176 | my $domain = $1; |
177 | if (/^\w+/) { | 177 | if (/^\w+/) { |
178 | print "$utils::PATH_TO_MAILQ = srcdomain = $domain \n" if $verbose ; | 178 | print "$utils::PATH_TO_MAILQ = srcdomain = $domain \n" if $verbose ; |
179 | $srcdomains{$domain} ++; | 179 | $srcdomains{$domain} ++; |
180 | } | 180 | } |
181 | next; | 181 | next; |
182 | } | 182 | } |
183 | 183 | ||
184 | # | 184 | # |
185 | # ... | 185 | # ... |
186 | # sendmail considers a message with more than one destiny, say N, to the same MX | 186 | # sendmail considers a message with more than one destiny, say N, to the same MX |
187 | # to have N messages in queue. | 187 | # to have N messages in queue. |
188 | # we will only consider one in this code | 188 | # we will only consider one in this code |
189 | if (( /\s\(reply:\sread\serror\sfrom\s.*\.(\w+\.\w+)\.$/ ) || ( /\s\(reply:\sread\serror\sfrom\s(\w+\.\w+)\.$/ ) || | 189 | if (( /\s\(reply:\sread\serror\sfrom\s.*\.(\w+\.\w+)\.$/ ) || ( /\s\(reply:\sread\serror\sfrom\s(\w+\.\w+)\.$/ ) || |
190 | ( /\s\(timeout\swriting\smessage\sto\s.*\.(\w+\.\w+)\.:/ ) || ( /\s\(timeout\swriting\smessage\sto\s(\w+\.\w+)\.:/ ) || | 190 | ( /\s\(timeout\swriting\smessage\sto\s.*\.(\w+\.\w+)\.:/ ) || ( /\s\(timeout\swriting\smessage\sto\s(\w+\.\w+)\.:/ ) || |
191 | ( /\s\(host\smap:\slookup\s\(.*\.(\w+\.\w+)\):/ ) || ( /\s\(host\smap:\slookup\s\((\w+\.\w+)\):/ ) || | 191 | ( /\s\(host\smap:\slookup\s\(.*\.(\w+\.\w+)\):/ ) || ( /\s\(host\smap:\slookup\s\((\w+\.\w+)\):/ ) || |
192 | ( /\s\(Deferred:\s.*\s.*\.(\w+\.\w+)\.\)/ ) || ( /\s\(Deferred:\s.*\s(\w+\.\w+)\.\)/ ) ) { | 192 | ( /\s\(Deferred:\s.*\s.*\.(\w+\.\w+)\.\)/ ) || ( /\s\(Deferred:\s.*\s(\w+\.\w+)\.\)/ ) ) { |
193 | 193 | ||
194 | print "$utils::PATH_TO_MAILQ = dstdomain = $1 \n" if $verbose ; | 194 | print "$utils::PATH_TO_MAILQ = dstdomain = $1 \n" if $verbose ; |
195 | $dstdomains{$1} ++; | 195 | $dstdomains{$1} ++; |
196 | } | 196 | } |
197 | 197 | ||
198 | if (/\s+\(I\/O\serror\)/) { | 198 | if (/\s+\(I\/O\serror\)/) { |
199 | print "$utils::PATH_TO_MAILQ = dstdomain = UNKNOWN \n" if $verbose ; | 199 | print "$utils::PATH_TO_MAILQ = dstdomain = UNKNOWN \n" if $verbose ; |
200 | $dstdomains{'UNKNOWN'} ++; | 200 | $dstdomains{'UNKNOWN'} ++; |
201 | } | 201 | } |
202 | 202 | ||
203 | # Finally look at the overall queue length | 203 | # Finally look at the overall queue length |
204 | # | 204 | # |
205 | if (/mqueue/) { | 205 | if (/mqueue/) { |
206 | print "$utils::PATH_TO_MAILQ = $_ "if $verbose ; | 206 | print "$utils::PATH_TO_MAILQ = $_ "if $verbose ; |
207 | if (/ \((\d+) request/) { | 207 | if (/ \((\d+) request/) { |
208 | # | 208 | # |
209 | # single queue: first line | 209 | # single queue: first line |
210 | # multi queue: one for each queue. overwrite on multi queue below | 210 | # multi queue: one for each queue. overwrite on multi queue below |
211 | $this_msg_q = $1 ; | 211 | $this_msg_q = $1 ; |
212 | $msg_q += $1 ; | 212 | $msg_q += $1 ; |
213 | } | 213 | } |
214 | } elsif (/^\s+Total\sRequests:\s(\d+)$/i) { | 214 | } elsif (/^\s+Total\sRequests:\s(\d+)$/i) { |
215 | if ($this_msg_q) { | 215 | if ($this_msg_q) { |
216 | $this_msg_q = 0 ; | 216 | $this_msg_q = 0 ; |
217 | } else { | 217 | } else { |
218 | print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ; | 218 | print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ; |
219 | # | 219 | # |
220 | # multi queue: last line | 220 | # multi queue: last line |
221 | $msg_q += $1 ; | 221 | $msg_q += $1 ; |
222 | } | 222 | } |
223 | } | 223 | } |
224 | 224 | ||
225 | } | 225 | } |
226 | 226 | ||
227 | 227 | ||
228 | ## close mailq | 228 | ## close mailq |
229 | 229 | close (MAILQ); | |
230 | close (MAILQ); | 230 | |
231 | 231 | if ( $? ) { | |
232 | if ( $? ) { | 232 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; |
233 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; | 233 | exit $ERRORS{CRITICAL}; |
234 | exit $ERRORS{CRITICAL}; | 234 | } |
235 | } | 235 | |
236 | 236 | ## shut off the alarm | |
237 | ## shut off the alarm | 237 | alarm(0); |
238 | alarm(0); | 238 | |
239 | 239 | ||
240 | 240 | ||
241 | 241 | ## now check the queue length(s) | |
242 | ## now check the queue length(s) | 242 | |
243 | 243 | if ($msg_q == 0) { | |
244 | if ($msg_q == 0) { | 244 | $msg = "OK: $mailq mailq is empty"; |
245 | $msg = "OK: $mailq mailq is empty"; | 245 | $state = $ERRORS{'OK'}; |
246 | $state = $ERRORS{'OK'}; | 246 | } else { |
247 | } else { | 247 | print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; |
248 | print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; | 248 | |
249 | 249 | # overall queue length | |
250 | # overall queue length | 250 | if ($msg_q < $opt_w) { |
251 | if ($msg_q < $opt_w) { | 251 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; |
252 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; | 252 | $state = $ERRORS{'OK'}; |
253 | $state = $ERRORS{'OK'}; | 253 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { |
254 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { | 254 | $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; |
255 | $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; | 255 | $state = $ERRORS{'WARNING'}; |
256 | $state = $ERRORS{'WARNING'}; | 256 | }else { |
257 | }else { | 257 | $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; |
258 | $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; | 258 | $state = $ERRORS{'CRITICAL'}; |
259 | $state = $ERRORS{'CRITICAL'}; | 259 | } |
260 | } | 260 | |
261 | 261 | # check for domain specific queue lengths if requested | |
262 | # check for domain specific queue lengths if requested | 262 | if (defined $opt_W) { |
263 | if (defined $opt_W) { | 263 | |
264 | 264 | # Apply threshold to queue lengths FROM domain | |
265 | # Apply threshold to queue lengths FROM domain | 265 | my @srckeys = sort { $srcdomains{$b} <=> $srcdomains{$a} } keys %srcdomains; |
266 | my @srckeys = sort { $srcdomains{$b} <=> $srcdomains{$a} } keys %srcdomains; | 266 | my $srcmaxkey = $srckeys[0]; |
267 | my $srcmaxkey = $srckeys[0]; | 267 | print "src max is $srcmaxkey with $srcdomains{$srcmaxkey} messages\n" if $verbose; |
268 | print "src max is $srcmaxkey with $srcdomains{$srcmaxkey} messages\n" if $verbose; | 268 | |
269 | 269 | if ($srcdomains{$srcmaxkey} >= $opt_W && $srcdomains{$srcmaxkey} < $opt_C) { | |
270 | if ($srcdomains{$srcmaxkey} >= $opt_W && $srcdomains{$srcmaxkey} < $opt_C) { | 270 | if ($state == $ERRORS{'OK'}) { |
271 | if ($state == $ERRORS{'OK'}) { | 271 | $msg = "WARNING: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)"; |
272 | $msg = "WARNING: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)"; | 272 | $state = $ERRORS{'WARNING'}; |
273 | $state = $ERRORS{'WARNING'}; | 273 | } elsif (($state == $ERRORS{'WARNING'}) || ($state == $ERRORS{'CRITICAL'})){ |
274 | } elsif (($state == $ERRORS{'WARNING'}) || ($state == $ERRORS{'CRITICAL'})){ | 274 | $msg .= " -and- $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)"; |
275 | $msg .= " -and- $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)"; | 275 | } else { |
276 | } else { | 276 | $msg = "WARNING: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)"; |
277 | $msg = "WARNING: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)"; | 277 | $state = $ERRORS{'WARNING'}; |
278 | $state = $ERRORS{'WARNING'}; | 278 | } |
279 | } | 279 | } elsif ($srcdomains{$srcmaxkey} >= $opt_C) { |
280 | } elsif ($srcdomains{$srcmaxkey} >= $opt_C) { | 280 | if ($state == $ERRORS{'OK'}) { |
281 | if ($state == $ERRORS{'OK'}) { | 281 | $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold C = $opt_C)"; |
282 | $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold C = $opt_C)"; | 282 | $state = $ERRORS{'CRITICAL'}; |
283 | $state = $ERRORS{'CRITICAL'}; | 283 | } elsif ($state == $ERRORS{'WARNING'}) { |
284 | } elsif ($state == $ERRORS{'WARNING'}) { | 284 | $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold C = $opt_C) -and- " . $msg; |
285 | $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold C = $opt_C) -and- " . $msg; | 285 | $msg =~ s/WARNING: //; |
286 | $msg =~ s/WARNING: //; | 286 | } elsif ($state == $ERRORS{'CRITICAL'}) { |
287 | } elsif ($state == $ERRORS{'CRITICAL'}) { | 287 | $msg .= " -and- $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)"; |
288 | $msg .= " -and- $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)"; | 288 | } else { |
289 | } else { | 289 | $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)"; |
290 | $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)"; | 290 | $state = $ERRORS{'CRITICAL'}; |
291 | $state = $ERRORS{'CRITICAL'}; | 291 | } |
292 | } | 292 | } else { |
293 | } else { | 293 | if ($srcdomains{$srcmaxkey} > 0) { |
294 | if ($srcdomains{$srcmaxkey} > 0) { | 294 | $msg .= " $srcdomains{$srcmaxkey} msgs. FROM $srcmaxkey is below threshold ($opt_W/$opt_C)"; |
295 | $msg .= " $srcdomains{$srcmaxkey} msgs. FROM $srcmaxkey is below threshold ($opt_W/$opt_C)"; | 295 | } |
296 | } | 296 | } |
297 | } | 297 | |
298 | 298 | # Apply threshold to queue lengths TO domain | |
299 | # Apply threshold to queue lengths TO domain | 299 | my @dstkeys = sort { $dstdomains{$b} <=> $dstdomains{$a} } keys %dstdomains; |
300 | my @dstkeys = sort { $dstdomains{$b} <=> $dstdomains{$a} } keys %dstdomains; | 300 | my $dstmaxkey = $dstkeys[0]; |
301 | my $dstmaxkey = $dstkeys[0]; | 301 | print "dst max is $dstmaxkey with $dstdomains{$dstmaxkey} messages\n" if $verbose; |
302 | print "dst max is $dstmaxkey with $dstdomains{$dstmaxkey} messages\n" if $verbose; | 302 | |
303 | 303 | if ($dstdomains{$dstmaxkey} >= $opt_W && $dstdomains{$dstmaxkey} < $opt_C) { | |
304 | if ($dstdomains{$dstmaxkey} >= $opt_W && $dstdomains{$dstmaxkey} < $opt_C) { | 304 | if ($state == $ERRORS{'OK'}) { |
305 | if ($state == $ERRORS{'OK'}) { | 305 | $msg = "WARNING: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)"; |
306 | $msg = "WARNING: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)"; | 306 | $state = $ERRORS{'WARNING'}; |
307 | $state = $ERRORS{'WARNING'}; | 307 | } elsif (($state == $ERRORS{'WARNING'}) || ($state == $ERRORS{'CRITICAL'})){ |
308 | } elsif (($state == $ERRORS{'WARNING'}) || ($state == $ERRORS{'CRITICAL'})){ | 308 | $msg .= " -and- $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)"; |
309 | $msg .= " -and- $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)"; | 309 | } else { |
310 | } else { | 310 | $msg = "WARNING: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)"; |
311 | $msg = "WARNING: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)"; | 311 | $state = $ERRORS{'WARNING'}; |
312 | $state = $ERRORS{'WARNING'}; | 312 | } |
313 | } | 313 | } elsif ($dstdomains{$dstmaxkey} >= $opt_C) { |
314 | } elsif ($dstdomains{$dstmaxkey} >= $opt_C) { | 314 | if ($state == $ERRORS{'OK'}) { |
315 | if ($state == $ERRORS{'OK'}) { | 315 | $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold C = $opt_C)"; |
316 | $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold C = $opt_C)"; | 316 | $state = $ERRORS{'CRITICAL'}; |
317 | $state = $ERRORS{'CRITICAL'}; | 317 | } elsif ($state == $ERRORS{'WARNING'}) { |
318 | } elsif ($state == $ERRORS{'WARNING'}) { | 318 | $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold C = $opt_C) -and- " . $msg; |
319 | $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold C = $opt_C) -and- " . $msg; | 319 | $msg =~ s/WARNING: //; |
320 | $msg =~ s/WARNING: //; | 320 | } elsif ($state == $ERRORS{'CRITICAL'}) { |
321 | } elsif ($state == $ERRORS{'CRITICAL'}) { | 321 | $msg .= " -and- $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)"; |
322 | $msg .= " -and- $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)"; | 322 | } else { |
323 | } else { | 323 | $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)"; |
324 | $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)"; | 324 | $state = $ERRORS{'CRITICAL'}; |
325 | $state = $ERRORS{'CRITICAL'}; | 325 | } |
326 | } | 326 | } else { |
327 | } else { | 327 | if ($dstdomains{$dstmaxkey} > 0) { |
328 | if ($dstdomains{$dstmaxkey} > 0) { | 328 | $msg .= " $dstdomains{$dstmaxkey} msgs. TO $dstmaxkey is below threshold ($opt_W/$opt_C)"; |
329 | $msg .= " $dstdomains{$dstmaxkey} msgs. TO $dstmaxkey is below threshold ($opt_W/$opt_C)"; | 329 | } |
330 | } | 330 | } |
331 | } | 331 | |
332 | 332 | } # End of queue length thresholds | |
333 | } # End of queue length thresholds | 333 | |
334 | 334 | } | |
335 | } | ||
336 | 335 | ||
337 | } # end of ($mailq eq "sendmail") | 336 | } # end of ($mailq eq "sendmail") |
338 | elsif ( $mailq eq "postfix" ) { | 337 | elsif ( $mailq eq "postfix" ) { |
339 | 338 | ||
340 | ## open mailq | 339 | ## open mailq |
341 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 340 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
342 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) { | 341 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) { |
343 | print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n"; | 342 | print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n"; |
344 | exit $ERRORS{'UNKNOWN'}; | 343 | exit $ERRORS{'UNKNOWN'}; |
345 | } | ||
346 | }elsif( defined $utils::PATH_TO_MAILQ){ | ||
347 | unless (-x $utils::PATH_TO_MAILQ) { | ||
348 | print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; | ||
349 | exit $ERRORS{'UNKNOWN'}; | ||
350 | } | ||
351 | } else { | ||
352 | print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; | ||
353 | exit $ERRORS{'UNKNOWN'}; | ||
354 | } | 344 | } |
345 | }elsif( defined $utils::PATH_TO_MAILQ){ | ||
346 | unless (-x $utils::PATH_TO_MAILQ) { | ||
347 | print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; | ||
348 | exit $ERRORS{'UNKNOWN'}; | ||
349 | } | ||
350 | } else { | ||
351 | print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; | ||
352 | exit $ERRORS{'UNKNOWN'}; | ||
353 | } | ||
355 | 354 | ||
356 | 355 | ||
357 | @lines = reverse <MAILQ>; | 356 | @lines = reverse <MAILQ>; |
@@ -360,8 +359,8 @@ elsif ( $mailq eq "postfix" ) { | |||
360 | close MAILQ; | 359 | close MAILQ; |
361 | 360 | ||
362 | if ( $? ) { | 361 | if ( $? ) { |
363 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ$mailq_args",$/; | 362 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ$mailq_args",$/; |
364 | exit $ERRORS{CRITICAL}; | 363 | exit $ERRORS{CRITICAL}; |
365 | } | 364 | } |
366 | 365 | ||
367 | ## shut off the alarm | 366 | ## shut off the alarm |
@@ -370,11 +369,11 @@ elsif ( $mailq eq "postfix" ) { | |||
370 | # check queue length | 369 | # check queue length |
371 | if ($lines[0]=~/Kbytes in (\d+)/) { | 370 | if ($lines[0]=~/Kbytes in (\d+)/) { |
372 | $msg_q = $1 ; | 371 | $msg_q = $1 ; |
373 | }elsif ($lines[0]=~/Mail queue is empty/) { | 372 | }elsif ($lines[0]=~/Mail queue is empty/) { |
374 | $msg_q = 0; | 373 | $msg_q = 0; |
375 | }else{ | 374 | }else{ |
376 | print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n"; | 375 | print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n"; |
377 | exit $ERRORS{'UNKNOWN'}; | 376 | exit $ERRORS{'UNKNOWN'}; |
378 | } | 377 | } |
379 | 378 | ||
380 | # check messages not processed | 379 | # check messages not processed |
@@ -390,194 +389,194 @@ elsif ( $mailq eq "postfix" ) { | |||
390 | $msg = "OK: $mailq mailq reports queue is empty"; | 389 | $msg = "OK: $mailq mailq reports queue is empty"; |
391 | $state = $ERRORS{'OK'}; | 390 | $state = $ERRORS{'OK'}; |
392 | } else { | 391 | } else { |
393 | print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; | 392 | print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; |
394 | 393 | ||
395 | # overall queue length | 394 | # overall queue length |
396 | if ($msg_q < $opt_w) { | 395 | if ($msg_q < $opt_w) { |
397 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; | 396 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; |
398 | $state = $ERRORS{'OK'}; | 397 | $state = $ERRORS{'OK'}; |
399 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { | 398 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { |
400 | $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; | 399 | $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; |
401 | $state = $ERRORS{'WARNING'}; | 400 | $state = $ERRORS{'WARNING'}; |
402 | }else { | 401 | }else { |
403 | $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; | 402 | $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; |
404 | $state = $ERRORS{'CRITICAL'}; | 403 | $state = $ERRORS{'CRITICAL'}; |
405 | } | 404 | } |
406 | 405 | ||
407 | # check messages not yet preprocessed (only compare is $opt_W and $opt_C | 406 | # check messages not yet preprocessed (only compare is $opt_W and $opt_C |
408 | # are defined) | 407 | # are defined) |
409 | 408 | ||
410 | #if (defined $opt_W) { | 409 | #if (defined $opt_W) { |
411 | # $msg .= "[Preprocessed = $msg_p]"; | 410 | # $msg .= "[Preprocessed = $msg_p]"; |
412 | # if ($msg_p >= $opt_W && $msg_p < $opt_C ) { | 411 | # if ($msg_p >= $opt_W && $msg_p < $opt_C ) { |
413 | # $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ; | 412 | # $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ; |
414 | # }elsif ($msg_p >= $opt_C ) { | 413 | # }elsif ($msg_p >= $opt_C ) { |
415 | # $state = $ERRORS{"CRITICAL"} ; | 414 | # $state = $ERRORS{"CRITICAL"} ; |
416 | # } | 415 | # } |
417 | #} | 416 | #} |
418 | } | 417 | } |
419 | } # end of ($mailq eq "postfix") | 418 | } # end of ($mailq eq "postfix") |
420 | elsif ( $mailq eq "qmail" ) { | 419 | elsif ( $mailq eq "qmail" ) { |
421 | 420 | ||
422 | # open qmail-qstat | 421 | # open qmail-qstat |
423 | if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) { | 422 | if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) { |
424 | if (! open (MAILQ, "$sudo $utils::PATH_TO_QMAIL_QSTAT | " ) ) { | 423 | if (! open (MAILQ, "$sudo $utils::PATH_TO_QMAIL_QSTAT | " ) ) { |
425 | print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n"; | 424 | print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n"; |
426 | exit $ERRORS{'UNKNOWN'}; | 425 | exit $ERRORS{'UNKNOWN'}; |
427 | } | 426 | } |
428 | }elsif( defined $utils::PATH_TO_QMAIL_QSTAT){ | 427 | }elsif( defined $utils::PATH_TO_QMAIL_QSTAT){ |
429 | unless (-x $utils::PATH_TO_QMAIL_QSTAT) { | 428 | unless (-x $utils::PATH_TO_QMAIL_QSTAT) { |
430 | print "ERROR: $utils::PATH_TO_QMAIL_QSTAT is not executable by (uid $>:gid($)))\n"; | 429 | print "ERROR: $utils::PATH_TO_QMAIL_QSTAT is not executable by (uid $>:gid($)))\n"; |
431 | exit $ERRORS{'UNKNOWN'}; | 430 | exit $ERRORS{'UNKNOWN'}; |
432 | } | 431 | } |
433 | } else { | 432 | } else { |
434 | print "ERROR: \$utils::PATH_TO_QMAIL_QSTAT is not defined\n"; | 433 | print "ERROR: \$utils::PATH_TO_QMAIL_QSTAT is not defined\n"; |
435 | exit $ERRORS{'UNKNOWN'}; | 434 | exit $ERRORS{'UNKNOWN'}; |
436 | } | 435 | } |
437 | 436 | ||
438 | @lines = <MAILQ>; | 437 | @lines = <MAILQ>; |
439 | 438 | ||
440 | # close qmail-qstat | 439 | # close qmail-qstat |
441 | close MAILQ; | 440 | close MAILQ; |
442 | 441 | ||
443 | if ( $? ) { | 442 | if ( $? ) { |
444 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; | 443 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; |
445 | exit $ERRORS{CRITICAL}; | 444 | exit $ERRORS{CRITICAL}; |
446 | } | 445 | } |
447 | 446 | ||
448 | ## shut off the alarm | 447 | ## shut off the alarm |
449 | alarm(0); | 448 | alarm(0); |
450 | 449 | ||
451 | # check queue length | 450 | # check queue length |
452 | if ($lines[0]=~/^messages in queue: (\d+)/) { | 451 | if ($lines[0]=~/^messages in queue: (\d+)/) { |
453 | $msg_q = $1 ; | 452 | $msg_q = $1 ; |
454 | }else{ | 453 | }else{ |
455 | print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n"; | 454 | print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n"; |
456 | exit $ERRORS{'UNKNOWN'}; | 455 | exit $ERRORS{'UNKNOWN'}; |
457 | } | 456 | } |
458 | 457 | ||
459 | # check messages not processed | 458 | # check messages not processed |
460 | if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) { | 459 | if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) { |
461 | my $msg_p = $1; | 460 | my $msg_p = $1; |
462 | }else{ | 461 | }else{ |
463 | print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n"; | 462 | print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n"; |
464 | exit $ERRORS{'UNKNOWN'}; | 463 | exit $ERRORS{'UNKNOWN'}; |
465 | } | 464 | } |
466 | 465 | ||
467 | 466 | ||
468 | # check queue length(s) | 467 | # check queue length(s) |
469 | if ($msg_q == 0){ | 468 | if ($msg_q == 0){ |
470 | $msg = "OK: qmail-qstat reports queue is empty"; | 469 | $msg = "OK: qmail-qstat reports queue is empty"; |
471 | $state = $ERRORS{'OK'}; | 470 | $state = $ERRORS{'OK'}; |
472 | } else { | 471 | } else { |
473 | print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; | 472 | print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; |
474 | 473 | ||
475 | # overall queue length | 474 | # overall queue length |
476 | if ($msg_q < $opt_w) { | 475 | if ($msg_q < $opt_w) { |
477 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; | 476 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; |
478 | $state = $ERRORS{'OK'}; | 477 | $state = $ERRORS{'OK'}; |
479 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { | 478 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { |
480 | $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; | 479 | $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; |
481 | $state = $ERRORS{'WARNING'}; | 480 | $state = $ERRORS{'WARNING'}; |
482 | }else { | 481 | }else { |
483 | $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; | 482 | $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; |
484 | $state = $ERRORS{'CRITICAL'}; | 483 | $state = $ERRORS{'CRITICAL'}; |
485 | } | 484 | } |
486 | 485 | ||
487 | # check messages not yet preprocessed (only compare is $opt_W and $opt_C | 486 | # check messages not yet preprocessed (only compare is $opt_W and $opt_C |
488 | # are defined) | 487 | # are defined) |
489 | 488 | ||
490 | if (defined $opt_W) { | 489 | if (defined $opt_W) { |
491 | $msg .= "[Preprocessed = $msg_p]"; | 490 | $msg .= "[Preprocessed = $msg_p]"; |
492 | if ($msg_p >= $opt_W && $msg_p < $opt_C ) { | 491 | if ($msg_p >= $opt_W && $msg_p < $opt_C ) { |
493 | $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ; | 492 | $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ; |
494 | }elsif ($msg_p >= $opt_C ) { | 493 | }elsif ($msg_p >= $opt_C ) { |
495 | $state = $ERRORS{"CRITICAL"} ; | 494 | $state = $ERRORS{"CRITICAL"} ; |
496 | } | 495 | } |
497 | } | 496 | } |
498 | } | 497 | } |
499 | 498 | ||
500 | 499 | ||
501 | 500 | ||
502 | } # end of ($mailq eq "qmail") | 501 | } # end of ($mailq eq "qmail") |
503 | elsif ( $mailq eq "exim" ) { | 502 | elsif ( $mailq eq "exim" ) { |
504 | ## open mailq | 503 | ## open mailq |
505 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 504 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
506 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { | 505 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { |
507 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | 506 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; |
508 | exit $ERRORS{'UNKNOWN'}; | 507 | exit $ERRORS{'UNKNOWN'}; |
509 | } | 508 | } |
510 | }elsif( defined $utils::PATH_TO_MAILQ){ | 509 | }elsif( defined $utils::PATH_TO_MAILQ){ |
511 | unless (-x $utils::PATH_TO_MAILQ) { | 510 | unless (-x $utils::PATH_TO_MAILQ) { |
512 | print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; | 511 | print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; |
513 | exit $ERRORS{'UNKNOWN'}; | 512 | exit $ERRORS{'UNKNOWN'}; |
514 | } | 513 | } |
515 | } else { | 514 | } else { |
516 | print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; | 515 | print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; |
517 | exit $ERRORS{'UNKNOWN'}; | 516 | exit $ERRORS{'UNKNOWN'}; |
518 | } | 517 | } |
519 | 518 | ||
520 | while (<MAILQ>) { | 519 | while (<MAILQ>) { |
521 | #22m 1.7K 19aEEr-0007hx-Dy <> *** frozen *** | 520 | #22m 1.7K 19aEEr-0007hx-Dy <> *** frozen *** |
522 | #root@exlixams.glups.fr | 521 | #root@exlixams.glups.fr |
523 | 522 | ||
524 | if (/\s[\w\d]{6}-[\w\d]{6}-[\w\d]{2}\s/) { # message id 19aEEr-0007hx-Dy | 523 | if (/\s[\w\d]{6}-[\w\d]{6}-[\w\d]{2}\s/) { # message id 19aEEr-0007hx-Dy |
525 | $msg_q++ ; | 524 | $msg_q++ ; |
526 | } | 525 | } |
527 | } | 526 | } |
528 | close(MAILQ) ; | 527 | close(MAILQ) ; |
529 | 528 | ||
530 | if ( $? ) { | 529 | if ( $? ) { |
531 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; | 530 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; |
532 | exit $ERRORS{CRITICAL}; | 531 | exit $ERRORS{CRITICAL}; |
533 | } | 532 | } |
534 | if ($msg_q < $opt_w) { | 533 | if ($msg_q < $opt_w) { |
535 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; | 534 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; |
536 | $state = $ERRORS{'OK'}; | 535 | $state = $ERRORS{'OK'}; |
537 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { | 536 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { |
538 | $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; | 537 | $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; |
539 | $state = $ERRORS{'WARNING'}; | 538 | $state = $ERRORS{'WARNING'}; |
540 | }else { | 539 | }else { |
541 | $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; | 540 | $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; |
542 | $state = $ERRORS{'CRITICAL'}; | 541 | $state = $ERRORS{'CRITICAL'}; |
543 | } | 542 | } |
544 | } # end of ($mailq eq "exim") | 543 | } # end of ($mailq eq "exim") |
545 | 544 | ||
546 | elsif ( $mailq eq "nullmailer" ) { | 545 | elsif ( $mailq eq "nullmailer" ) { |
547 | ## open mailq | 546 | ## open mailq |
548 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 547 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
549 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { | 548 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { |
550 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | 549 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; |
551 | exit $ERRORS{'UNKNOWN'}; | 550 | exit $ERRORS{'UNKNOWN'}; |
552 | } | 551 | } |
553 | }elsif( defined $utils::PATH_TO_MAILQ){ | 552 | }elsif( defined $utils::PATH_TO_MAILQ){ |
554 | unless (-x $utils::PATH_TO_MAILQ) { | 553 | unless (-x $utils::PATH_TO_MAILQ) { |
555 | print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; | 554 | print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; |
556 | exit $ERRORS{'UNKNOWN'}; | 555 | exit $ERRORS{'UNKNOWN'}; |
557 | } | 556 | } |
558 | } else { | 557 | } else { |
559 | print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; | 558 | print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; |
560 | exit $ERRORS{'UNKNOWN'}; | 559 | exit $ERRORS{'UNKNOWN'}; |
561 | } | 560 | } |
562 | 561 | ||
563 | while (<MAILQ>) { | 562 | while (<MAILQ>) { |
564 | #2022-08-25 01:30:40 502 bytes from <user@example.com> | 563 | #2022-08-25 01:30:40 502 bytes from <user@example.com> |
565 | 564 | ||
566 | if (/^\d{4}-\d{2}-\d{2}\s+\d{2}\:\d{2}\:\d{2}\s+\d+\sbytes/) { | 565 | if (/^\d{4}-\d{2}-\d{2}\s+\d{2}\:\d{2}\:\d{2}\s+\d+\sbytes/) { |
567 | $msg_q++ ; | 566 | $msg_q++ ; |
568 | } | 567 | } |
569 | } | 568 | } |
570 | close(MAILQ) ; | 569 | close(MAILQ) ; |
571 | if ($msg_q < $opt_w) { | 570 | if ($msg_q < $opt_w) { |
572 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; | 571 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; |
573 | $state = $ERRORS{'OK'}; | 572 | $state = $ERRORS{'OK'}; |
574 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { | 573 | }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { |
575 | $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; | 574 | $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; |
576 | $state = $ERRORS{'WARNING'}; | 575 | $state = $ERRORS{'WARNING'}; |
577 | }else { | 576 | }else { |
578 | $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; | 577 | $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; |
579 | $state = $ERRORS{'CRITICAL'}; | 578 | $state = $ERRORS{'CRITICAL'}; |
580 | } | 579 | } |
581 | } # end of ($mailq eq "nullmailer") | 580 | } # end of ($mailq eq "nullmailer") |
582 | 581 | ||
583 | # Perfdata support | 582 | # Perfdata support |
@@ -590,130 +589,130 @@ exit $state; | |||
590 | 589 | ||
591 | 590 | ||
592 | sub process_arguments(){ | 591 | sub process_arguments(){ |
593 | GetOptions | 592 | GetOptions |
594 | ("V" => \$opt_V, "version" => \$opt_V, | 593 | ("V" => \$opt_V, "version" => \$opt_V, |
595 | "v" => \$opt_v, "verbose" => \$opt_v, | 594 | "v" => \$opt_v, "verbose" => \$opt_v, |
596 | "h" => \$opt_h, "help" => \$opt_h, | 595 | "h" => \$opt_h, "help" => \$opt_h, |
597 | "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) | 596 | "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) |
598 | "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number | 597 | "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number |
599 | "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number | 598 | "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number |
600 | "W=i" => \$opt_W, "warning-domain=i" => \$opt_W, # Warning if above this number | 599 | "W=i" => \$opt_W, "warning-domain=i" => \$opt_W, # Warning if above this number |
601 | "C=i" => \$opt_C, "critical-domain=i" => \$opt_C, # Critical if above this number | 600 | "C=i" => \$opt_C, "critical-domain=i" => \$opt_C, # Critical if above this number |
602 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, | 601 | "t=i" => \$opt_t, "timeout=i" => \$opt_t, |
603 | "s" => \$opt_s, "sudo" => \$opt_s, | 602 | "s" => \$opt_s, "sudo" => \$opt_s, |
604 | "d:s" => \$opt_d, "configdir:s" => \$opt_d, | 603 | "d:s" => \$opt_d, "configdir:s" => \$opt_d, |
605 | ); | 604 | ); |
606 | 605 | ||
607 | if ($opt_V) { | 606 | if ($opt_V) { |
608 | print_revision($PROGNAME,'@NP_VERSION@'); | 607 | print_revision($PROGNAME,'@NP_VERSION@'); |
609 | exit $ERRORS{'UNKNOWN'}; | 608 | exit $ERRORS{'UNKNOWN'}; |
610 | } | 609 | } |
611 | 610 | ||
612 | if ($opt_h) { | 611 | if ($opt_h) { |
613 | print_help(); | 612 | print_help(); |
614 | exit $ERRORS{'UNKNOWN'}; | 613 | exit $ERRORS{'UNKNOWN'}; |
615 | } | 614 | } |
616 | 615 | ||
617 | if (defined $opt_v ){ | 616 | if (defined $opt_v ){ |
618 | $verbose = $opt_v; | 617 | $verbose = $opt_v; |
619 | } | 618 | } |
620 | 619 | ||
621 | unless (defined $opt_t) { | 620 | unless (defined $opt_t) { |
622 | $opt_t = $utils::TIMEOUT ; # default timeout | 621 | $opt_t = $utils::TIMEOUT ; # default timeout |
623 | } | 622 | } |
624 | 623 | ||
625 | unless ( defined $opt_w && defined $opt_c ) { | 624 | unless ( defined $opt_w && defined $opt_c ) { |
626 | print_usage(); | 625 | print_usage(); |
627 | exit $ERRORS{'UNKNOWN'}; | 626 | exit $ERRORS{'UNKNOWN'}; |
628 | } | 627 | } |
629 | 628 | ||
630 | if ( $opt_w >= $opt_c) { | 629 | if ( $opt_w >= $opt_c) { |
631 | print "Warning (-w) cannot be greater than Critical (-c)!\n"; | 630 | print "Warning (-w) cannot be greater than Critical (-c)!\n"; |
632 | exit $ERRORS{'UNKNOWN'}; | 631 | exit $ERRORS{'UNKNOWN'}; |
633 | } | 632 | } |
634 | 633 | ||
635 | if (defined $opt_W && ! defined !$opt_C) { | 634 | if (defined $opt_W && ! defined !$opt_C) { |
636 | print "Need -C if using -W\n"; | 635 | print "Need -C if using -W\n"; |
637 | exit $ERRORS{'UNKNOWN'}; | 636 | exit $ERRORS{'UNKNOWN'}; |
638 | }elsif(defined $opt_W && defined $opt_C) { | 637 | }elsif(defined $opt_W && defined $opt_C) { |
639 | if ($opt_W >= $opt_C) { | 638 | if ($opt_W >= $opt_C) { |
640 | print "Warning (-W) cannot be greater than Critical (-C)!\n"; | 639 | print "Warning (-W) cannot be greater than Critical (-C)!\n"; |
641 | exit $ERRORS{'UNKNOWN'}; | 640 | exit $ERRORS{'UNKNOWN'}; |
642 | } | 641 | } |
643 | } | 642 | } |
644 | 643 | ||
645 | if (defined $opt_M) { | 644 | if (defined $opt_M) { |
646 | if ($opt_M =~ /^(sendmail|qmail|postfix|exim|nullmailer)$/) { | 645 | if ($opt_M =~ /^(sendmail|qmail|postfix|exim|nullmailer)$/) { |
647 | $mailq = $opt_M ; | 646 | $mailq = $opt_M ; |
648 | }elsif( $opt_M eq ''){ | 647 | }elsif( $opt_M eq ''){ |
649 | $mailq = 'sendmail'; | 648 | $mailq = 'sendmail'; |
650 | }else{ | 649 | }else{ |
651 | print "-M: $opt_M is not supported\n"; | 650 | print "-M: $opt_M is not supported\n"; |
652 | exit $ERRORS{'UNKNOWN'}; | 651 | exit $ERRORS{'UNKNOWN'}; |
653 | } | 652 | } |
654 | }else{ | 653 | }else{ |
655 | if (defined $utils::PATH_TO_QMAIL_QSTAT | 654 | if (defined $utils::PATH_TO_QMAIL_QSTAT |
656 | && -x $utils::PATH_TO_QMAIL_QSTAT) | 655 | && -x $utils::PATH_TO_QMAIL_QSTAT) |
657 | { | 656 | { |
658 | $mailq = 'qmail'; | 657 | $mailq = 'qmail'; |
659 | } | 658 | } |
660 | elsif (-d '/var/lib/postfix' || -d '/var/local/lib/postfix' | 659 | elsif (-d '/var/lib/postfix' || -d '/var/local/lib/postfix' |
661 | || -e '/usr/sbin/postfix' || -e '/usr/local/sbin/postfix') | 660 | || -e '/usr/sbin/postfix' || -e '/usr/local/sbin/postfix') |
662 | { | 661 | { |
663 | $mailq = 'postfix'; | 662 | $mailq = 'postfix'; |
664 | } | 663 | } |
665 | elsif (-d '/usr/lib/exim4' || -d '/usr/local/lib/exim4' | 664 | elsif (-d '/usr/lib/exim4' || -d '/usr/local/lib/exim4' |
666 | || -e '/usr/sbin/exim' || -e '/usr/local/sbin/exim') | 665 | || -e '/usr/sbin/exim' || -e '/usr/local/sbin/exim') |
667 | { | 666 | { |
668 | $mailq = 'exim'; | 667 | $mailq = 'exim'; |
669 | } | 668 | } |
670 | elsif (-d '/usr/lib/nullmailer' || -d '/usr/local/lib/nullmailer' | 669 | elsif (-d '/usr/lib/nullmailer' || -d '/usr/local/lib/nullmailer' |
671 | || -e '/usr/sbin/nullmailer-send' | 670 | || -e '/usr/sbin/nullmailer-send' |
672 | || -e '/usr/local/sbin/nullmailer-send') | 671 | || -e '/usr/local/sbin/nullmailer-send') |
673 | { | 672 | { |
674 | $mailq = 'nullmailer'; | 673 | $mailq = 'nullmailer'; |
675 | } | 674 | } |
676 | else { | 675 | else { |
677 | $mailq = 'sendmail'; | 676 | $mailq = 'sendmail'; |
678 | } | 677 | } |
679 | } | 678 | } |
680 | 679 | ||
681 | return $ERRORS{'OK'}; | 680 | return $ERRORS{'OK'}; |
682 | } | 681 | } |
683 | 682 | ||
684 | sub print_usage () { | 683 | sub print_usage () { |
685 | print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n"; | 684 | print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n"; |
686 | } | 685 | } |
687 | 686 | ||
688 | sub print_help () { | 687 | sub print_help () { |
689 | print_revision($PROGNAME,'@NP_VERSION@'); | 688 | print_revision($PROGNAME,'@NP_VERSION@'); |
690 | print "Copyright (c) 2002 Subhendu Ghosh/Carlos Canau/Benjamin Schmid\n"; | 689 | print "Copyright (c) 2002 Subhendu Ghosh/Carlos Canau/Benjamin Schmid\n"; |
691 | print "\n"; | 690 | print "\n"; |
692 | print_usage(); | 691 | print_usage(); |
693 | print "\n"; | 692 | print "\n"; |
694 | print " Checks the number of messages in the mail queue (supports multiple sendmail queues, qmail)\n"; | 693 | print " Checks the number of messages in the mail queue (supports multiple sendmail queues, qmail)\n"; |
695 | print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; | 694 | print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; |
696 | print "-w (--warning) = Min. number of messages in queue to generate warning\n"; | 695 | print "-w (--warning) = Min. number of messages in queue to generate warning\n"; |
697 | print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; | 696 | print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; |
698 | print "-W (--warning-domain) = Min. number of messages for same domain in queue to generate warning\n"; | 697 | print "-W (--warning-domain) = Min. number of messages for same domain in queue to generate warning\n"; |
699 | print "-C (--critical-domain) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; | 698 | print "-C (--critical-domain) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; |
700 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; | 699 | print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; |
701 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; | 700 | print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; |
702 | print "-s (--sudo) = Use sudo to call the mailq command\n"; | 701 | print "-s (--sudo) = Use sudo to call the mailq command\n"; |
703 | print "-d (--configdir) = Config file or directory\n"; | 702 | print "-d (--configdir) = Config file or directory\n"; |
704 | print "-h (--help)\n"; | 703 | print "-h (--help)\n"; |
705 | print "-V (--version)\n"; | 704 | print "-V (--version)\n"; |
706 | print "-v (--verbose) = debugging output\n"; | 705 | print "-v (--verbose) = debugging output\n"; |
707 | print "\n\n"; | 706 | print "\n\n"; |
708 | print "Note: -w and -c are required arguments. -W and -C are optional.\n"; | 707 | print "Note: -w and -c are required arguments. -W and -C are optional.\n"; |
709 | print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n"; | 708 | print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n"; |
710 | print " -W and -C are applied message not yet preproccessed. (qmail)\n"; | 709 | print " -W and -C are applied message not yet preproccessed. (qmail)\n"; |
711 | print " This plugin tries to autodetect which mailserver you are running,\n"; | 710 | print " This plugin tries to autodetect which mailserver you are running,\n"; |
712 | print " you can override the autodetection with -M.\n"; | 711 | print " you can override the autodetection with -M.\n"; |
713 | print " This plugin uses the system mailq command (sendmail) or qmail-stat (qmail)\n"; | 712 | print " This plugin uses the system mailq command (sendmail) or qmail-stat (qmail)\n"; |
714 | print " to look at the queues. Mailq can usually only be accessed by root or \n"; | 713 | print " to look at the queues. Mailq can usually only be accessed by root or \n"; |
715 | print " a TrustedUser. You will have to set appropriate permissions for the plugin to work.\n"; | 714 | print " a TrustedUser. You will have to set appropriate permissions for the plugin to work.\n"; |
716 | print ""; | 715 | print ""; |
717 | print "\n\n"; | 716 | print "\n\n"; |
718 | support(); | 717 | support(); |
719 | } | 718 | } |