diff options
Diffstat (limited to 'plugins-scripts/check_mailq.pl')
-rwxr-xr-x | plugins-scripts/check_mailq.pl | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl index 49156af3..26336b99 100755 --- a/plugins-scripts/check_mailq.pl +++ b/plugins-scripts/check_mailq.pl | |||
@@ -1,7 +1,7 @@ | |||
1 | #!@PERL@ -w | 1 | #!@PERL@ -w |
2 | 2 | ||
3 | # check_mailq - check to see how many messages are in the smtp queue awating | 3 | # check_mailq - check to see how many messages are in the smtp queue awating |
4 | # transmittal. | 4 | # transmittal. |
5 | # | 5 | # |
6 | # Initial version support sendmail's mailq command | 6 | # Initial version support sendmail's mailq command |
7 | # Support for multiple sendmail queues (Carlos Canau) | 7 | # Support for multiple sendmail queues (Carlos Canau) |
@@ -42,7 +42,7 @@ sub print_usage (); | |||
42 | sub process_arguments (); | 42 | sub process_arguments (); |
43 | 43 | ||
44 | $ENV{'PATH'}='@TRUSTED_PATH@'; | 44 | $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 |
@@ -84,7 +84,7 @@ 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"; |
@@ -170,7 +170,7 @@ if ($mailq eq "sendmail") { | |||
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; |
@@ -180,21 +180,21 @@ if ($mailq eq "sendmail") { | |||
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'} ++; |
@@ -221,13 +221,13 @@ if ($mailq eq "sendmail") { | |||
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 | ||
230 | close (MAILQ); | 230 | close (MAILQ); |
231 | 231 | ||
232 | if ( $? ) { | 232 | if ( $? ) { |
233 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; | 233 | print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; |
@@ -246,7 +246,7 @@ if ($mailq eq "sendmail") { | |||
246 | $state = $ERRORS{'OK'}; | 246 | $state = $ERRORS{'OK'}; |
247 | } else { | 247 | } else { |
248 | 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; |
249 | 249 | ||
250 | # overall queue length | 250 | # overall queue length |
251 | if ($msg_q < $opt_w) { | 251 | if ($msg_q < $opt_w) { |
252 | $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)"; |
@@ -261,12 +261,12 @@ if ($mailq eq "sendmail") { | |||
261 | 261 | ||
262 | # check for domain specific queue lengths if requested | 262 | # check for domain specific queue lengths if requested |
263 | if (defined $opt_W) { | 263 | if (defined $opt_W) { |
264 | 264 | ||
265 | # Apply threshold to queue lengths FROM domain | 265 | # Apply threshold to queue lengths FROM domain |
266 | my @srckeys = sort { $srcdomains{$b} <=> $srcdomains{$a} } keys %srcdomains; | 266 | my @srckeys = sort { $srcdomains{$b} <=> $srcdomains{$a} } keys %srcdomains; |
267 | my $srcmaxkey = $srckeys[0]; | 267 | my $srcmaxkey = $srckeys[0]; |
268 | 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; |
269 | 269 | ||
270 | if ($srcdomains{$srcmaxkey} >= $opt_W && $srcdomains{$srcmaxkey} < $opt_C) { | 270 | if ($srcdomains{$srcmaxkey} >= $opt_W && $srcdomains{$srcmaxkey} < $opt_C) { |
271 | if ($state == $ERRORS{'OK'}) { | 271 | if ($state == $ERRORS{'OK'}) { |
272 | $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)"; |
@@ -300,7 +300,7 @@ if ($mailq eq "sendmail") { | |||
300 | my @dstkeys = sort { $dstdomains{$b} <=> $dstdomains{$a} } keys %dstdomains; | 300 | my @dstkeys = sort { $dstdomains{$b} <=> $dstdomains{$a} } keys %dstdomains; |
301 | my $dstmaxkey = $dstkeys[0]; | 301 | my $dstmaxkey = $dstkeys[0]; |
302 | 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; |
303 | 303 | ||
304 | if ($dstdomains{$dstmaxkey} >= $opt_W && $dstdomains{$dstmaxkey} < $opt_C) { | 304 | if ($dstdomains{$dstmaxkey} >= $opt_W && $dstdomains{$dstmaxkey} < $opt_C) { |
305 | if ($state == $ERRORS{'OK'}) { | 305 | if ($state == $ERRORS{'OK'}) { |
306 | $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)"; |
@@ -419,7 +419,7 @@ elsif ( $mailq eq "postfix" ) { | |||
419 | } # end of ($mailq eq "postfix") | 419 | } # end of ($mailq eq "postfix") |
420 | elsif ( $mailq eq "qmail" ) { | 420 | elsif ( $mailq eq "qmail" ) { |
421 | 421 | ||
422 | # open qmail-qstat | 422 | # open qmail-qstat |
423 | if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) { | 423 | if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) { |
424 | if (! open (MAILQ, "$sudo $utils::PATH_TO_QMAIL_QSTAT | " ) ) { | 424 | if (! open (MAILQ, "$sudo $utils::PATH_TO_QMAIL_QSTAT | " ) ) { |
425 | print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n"; | 425 | print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n"; |
@@ -471,7 +471,7 @@ elsif ( $mailq eq "qmail" ) { | |||
471 | $state = $ERRORS{'OK'}; | 471 | $state = $ERRORS{'OK'}; |
472 | } else { | 472 | } else { |
473 | print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; | 473 | print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; |
474 | 474 | ||
475 | # overall queue length | 475 | # overall queue length |
476 | if ($msg_q < $opt_w) { | 476 | if ($msg_q < $opt_w) { |
477 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; | 477 | $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; |
@@ -486,7 +486,7 @@ elsif ( $mailq eq "qmail" ) { | |||
486 | 486 | ||
487 | # check messages not yet preprocessed (only compare is $opt_W and $opt_C | 487 | # check messages not yet preprocessed (only compare is $opt_W and $opt_C |
488 | # are defined) | 488 | # are defined) |
489 | 489 | ||
490 | if (defined $opt_W) { | 490 | if (defined $opt_W) { |
491 | $msg .= "[Preprocessed = $msg_p]"; | 491 | $msg .= "[Preprocessed = $msg_p]"; |
492 | if ($msg_p >= $opt_W && $msg_p < $opt_C ) { | 492 | if ($msg_p >= $opt_W && $msg_p < $opt_C ) { |
@@ -495,13 +495,13 @@ elsif ( $mailq eq "qmail" ) { | |||
495 | $state = $ERRORS{"CRITICAL"} ; | 495 | $state = $ERRORS{"CRITICAL"} ; |
496 | } | 496 | } |
497 | } | 497 | } |
498 | } | 498 | } |
499 | 499 | ||
500 | 500 | ||
501 | 501 | ||
502 | } # end of ($mailq eq "qmail") | 502 | } # end of ($mailq eq "qmail") |
503 | elsif ( $mailq eq "exim" ) { | 503 | elsif ( $mailq eq "exim" ) { |
504 | ## open mailq | 504 | ## open mailq |
505 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { | 505 | if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { |
506 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { | 506 | if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { |
507 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; | 507 | print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; |
@@ -677,7 +677,7 @@ sub process_arguments(){ | |||
677 | $mailq = 'sendmail'; | 677 | $mailq = 'sendmail'; |
678 | } | 678 | } |
679 | } | 679 | } |
680 | 680 | ||
681 | return $ERRORS{'OK'}; | 681 | return $ERRORS{'OK'}; |
682 | } | 682 | } |
683 | 683 | ||