Update THANKS file
[monitoring-plugins.git] / plugins-scripts / check_mailq.pl
blob31eb46a4d5aa93da85f39e07e25b93f8930e6c39
1 #!/usr/local/bin/perl -w
3 # check_mailq - check to see how many messages are in the smtp queue awating
4 # transmittal.
6 # Initial version support sendmail's mailq command
7 # Support for mutiple sendmail queues (Carlos Canau)
8 # Support for qmail (Benjamin Schmid)
10 # License Information:
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 ############################################################################
28 use POSIX;
29 use strict;
30 use Getopt::Long;
31 use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t
32 $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq @lines
33 %srcdomains %dstdomains);
34 use lib utils.pm;
35 use utils qw(%ERRORS &print_revision &support &usage );
38 sub print_help ();
39 sub print_usage ();
40 sub process_arguments ();
42 $ENV{'PATH'}='';
43 $ENV{'BASH_ENV'}='';
44 $ENV{'ENV'}='';
45 $PROGNAME = "check_mailq";
46 $mailq = 'sendmail'; # default
47 $msg_q = 0 ;
48 $msg_p = 0 ;
49 $state = $ERRORS{'UNKNOWN'};
51 Getopt::Long::Configure('bundling');
52 $status = process_arguments();
53 if ($status){
54 print "ERROR: processing arguments\n";
55 exit $ERRORS{"UNKNOWN"};
58 $SIG{'ALRM'} = sub {
59 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n");
60 exit $ERRORS{"WARNING"};
62 alarm($opt_t);
64 # switch based on MTA
66 if ($mailq eq "sendmail") {
68 ## open mailq
69 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
70 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) {
71 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
72 exit $ERRORS{'UNKNOWN'};
74 }elsif( defined $utils::PATH_TO_MAILQ){
75 unless (-x $utils::PATH_TO_MAILQ) {
76 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
77 exit $ERRORS{'UNKNOWN'};
79 } else {
80 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
81 exit $ERRORS{'UNKNOWN'};
83 # single queue empty
84 ##/var/spool/mqueue is empty
85 # single queue: 1
86 ## /var/spool/mqueue (1 request)
87 ##----Q-ID---- --Size-- -----Q-Time----- ------------Sender/Recipient------------
88 ##h32E30p01763 2782 Wed Apr 2 15:03 <silvaATkpnqwest.pt>
89 ## 8BITMIME
90 ## <silvaATeunet.pt>
92 # multi queue empty
93 ##/var/spool/mqueue/q0/df is empty
94 ##/var/spool/mqueue/q1/df is empty
95 ##/var/spool/mqueue/q2/df is empty
96 ##/var/spool/mqueue/q3/df is empty
97 ##/var/spool/mqueue/q4/df is empty
98 ##/var/spool/mqueue/q5/df is empty
99 ##/var/spool/mqueue/q6/df is empty
100 ##/var/spool/mqueue/q7/df is empty
101 ##/var/spool/mqueue/q8/df is empty
102 ##/var/spool/mqueue/q9/df is empty
103 ##/var/spool/mqueue/qA/df is empty
104 ##/var/spool/mqueue/qB/df is empty
105 ##/var/spool/mqueue/qC/df is empty
106 ##/var/spool/mqueue/qD/df is empty
107 ##/var/spool/mqueue/qE/df is empty
108 ##/var/spool/mqueue/qF/df is empty
109 ## Total Requests: 0
110 # multi queue: 1
111 ##/var/spool/mqueue/q0/df is empty
112 ##/var/spool/mqueue/q1/df is empty
113 ##/var/spool/mqueue/q2/df is empty
114 ## /var/spool/mqueue/q3/df (1 request)
115 ##----Q-ID---- --Size-- -----Q-Time----- ------------Sender/Recipient------------
116 ##h32De2f23534* 48 Wed Apr 2 14:40 nocol
117 ## nouserATEUnet.pt
118 ## canau
119 ##/var/spool/mqueue/q4/df is empty
120 ##/var/spool/mqueue/q5/df is empty
121 ##/var/spool/mqueue/q6/df is empty
122 ##/var/spool/mqueue/q7/df is empty
123 ##/var/spool/mqueue/q8/df is empty
124 ##/var/spool/mqueue/q9/df is empty
125 ##/var/spool/mqueue/qA/df is empty
126 ##/var/spool/mqueue/qB/df is empty
127 ##/var/spool/mqueue/qC/df is empty
128 ##/var/spool/mqueue/qD/df is empty
129 ##/var/spool/mqueue/qE/df is empty
130 ##/var/spool/mqueue/qF/df is empty
131 ## Total Requests: 1
134 while (<MAILQ>) {
136 # match email addr on queue listing
137 if ( (/<.*@.*\.(\w+\.\w+)>/) || (/<.*@(\w+\.\w+)>/) ) {
138 my $domain = $1;
139 if (/^\w+/) {
140 print "$utils::PATH_TO_MAILQ = srcdomain = $domain \n" if $verbose ;
141 $srcdomains{$domain} ++;
143 next;
147 # ...
148 # sendmail considers a message with more than one destiny, say N, to the same MX
149 # to have N messages in queue.
150 # we will only consider one in this code
151 if (( /\s\(reply:\sread\serror\sfrom\s.*\.(\w+\.\w+)\.$/ ) || ( /\s\(reply:\sread\serror\sfrom\s(\w+\.\w+)\.$/ ) ||
152 ( /\s\(timeout\swriting\smessage\sto\s.*\.(\w+\.\w+)\.:/ ) || ( /\s\(timeout\swriting\smessage\sto\s(\w+\.\w+)\.:/ ) ||
153 ( /\s\(host\smap:\slookup\s\(.*\.(\w+\.\w+)\):/ ) || ( /\s\(host\smap:\slookup\s\((\w+\.\w+)\):/ ) ||
154 ( /\s\(Deferred:\s.*\s.*\.(\w+\.\w+)\.\)/ ) || ( /\s\(Deferred:\s.*\s(\w+\.\w+)\.\)/ ) ) {
156 print "$utils::PATH_TO_MAILQ = dstdomain = $1 \n" if $verbose ;
157 $dstdomains{$1} ++;
160 if (/\s+\(I\/O\serror\)/) {
161 print "$utils::PATH_TO_MAILQ = dstdomain = UNKNOWN \n" if $verbose ;
162 $dstdomains{'UNKNOWN'} ++;
165 # Finally look at the overall queue length
167 if (/mqueue/) {
168 print "$utils::PATH_TO_MAILQ = $_ "if $verbose ;
169 if (/ \((\d+) request/) {
171 # single queue: first line
172 # multi queue: one for each queue. overwrite on multi queue below
173 $msg_q = $1 ;
175 } elsif (/^\s+Total\sRequests:\s(\d+)$/i) {
176 print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ;
178 # multi queue: last line
179 $msg_q = $1 ;
185 ## close mailq
187 close (MAILQ);
189 if ( $? ) {
190 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
191 exit $ERRORS{CRITICAL};
194 ## shut off the alarm
195 alarm(0);
199 ## now check the queue length(s)
201 if ($msg_q == 0) {
202 $msg = "OK: mailq is empty";
203 $state = $ERRORS{'OK'};
204 } else {
205 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
207 # overall queue length
208 if ($msg_q < $opt_w) {
209 $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
210 $state = $ERRORS{'OK'};
211 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
212 $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)";
213 $state = $ERRORS{'WARNING'};
214 }else {
215 $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)";
216 $state = $ERRORS{'CRITICAL'};
219 # check for domain specific queue lengths if requested
220 if (defined $opt_W) {
222 # Apply threshold to queue lengths FROM domain
223 my @srckeys = sort { $srcdomains{$b} <=> $srcdomains{$a} } keys %srcdomains;
224 my $srcmaxkey = $srckeys[0];
225 print "src max is $srcmaxkey with $srcdomains{$srcmaxkey} messages\n" if $verbose;
227 if ($srcdomains{$srcmaxkey} >= $opt_W && $srcdomains{$srcmaxkey} < $opt_C) {
228 if ($state == $ERRORS{'OK'}) {
229 $msg = "WARNING: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
230 $state = $ERRORS{'WARNING'};
231 } elsif (($state == $ERRORS{'WARNING'}) || ($state == $ERRORS{'CRITICAL'})){
232 $msg .= " -and- $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
233 } else {
234 $msg = "WARNING: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
235 $state = $ERRORS{'WARNING'};
237 } elsif ($srcdomains{$srcmaxkey} >= $opt_C) {
238 if ($state == $ERRORS{'OK'}) {
239 $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold C = $opt_C)";
240 $state = $ERRORS{'CRITICAL'};
241 } elsif ($state == $ERRORS{'WARNING'}) {
242 $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold C = $opt_C) -and- " . $msg;
243 $msg =~ s/WARNING: //;
244 } elsif ($state == $ERRORS{'CRITICAL'}) {
245 $msg .= " -and- $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
246 } else {
247 $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
248 $state = $ERRORS{'CRITICAL'};
250 } else {
251 if ($srcdomains{$srcmaxkey} > 0) {
252 $msg .= " $srcdomains{$srcmaxkey} msgs. FROM $srcmaxkey is below threshold ($opt_W/$opt_C)";
256 # Apply threshold to queue lengths TO domain
257 my @dstkeys = sort { $dstdomains{$b} <=> $dstdomains{$a} } keys %dstdomains;
258 my $dstmaxkey = $dstkeys[0];
259 print "dst max is $dstmaxkey with $dstdomains{$dstmaxkey} messages\n" if $verbose;
261 if ($dstdomains{$dstmaxkey} >= $opt_W && $dstdomains{$dstmaxkey} < $opt_C) {
262 if ($state == $ERRORS{'OK'}) {
263 $msg = "WARNING: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
264 $state = $ERRORS{'WARNING'};
265 } elsif (($state == $ERRORS{'WARNING'}) || ($state == $ERRORS{'CRITICAL'})){
266 $msg .= " -and- $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
267 } else {
268 $msg = "WARNING: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
269 $state = $ERRORS{'WARNING'};
271 } elsif ($dstdomains{$dstmaxkey} >= $opt_C) {
272 if ($state == $ERRORS{'OK'}) {
273 $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold C = $opt_C)";
274 $state = $ERRORS{'CRITICAL'};
275 } elsif ($state == $ERRORS{'WARNING'}) {
276 $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold C = $opt_C) -and- " . $msg;
277 $msg =~ s/WARNING: //;
278 } elsif ($state == $ERRORS{'CRITICAL'}) {
279 $msg .= " -and- $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
280 } else {
281 $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
282 $state = $ERRORS{'CRITICAL'};
284 } else {
285 if ($dstdomains{$dstmaxkey} > 0) {
286 $msg .= " $dstdomains{$dstmaxkey} msgs. TO $dstmaxkey is below threshold ($opt_W/$opt_C)";
290 } # End of queue length thresholds
294 } # end of ($mailq eq "sendmail")
295 elsif ( $mailq eq "postfix" ) {
297 ## open mailq
298 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
299 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) {
300 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
301 exit $ERRORS{'UNKNOWN'};
303 }elsif( defined $utils::PATH_TO_MAILQ){
304 unless (-x $utils::PATH_TO_MAILQ) {
305 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
306 exit $ERRORS{'UNKNOWN'};
308 } else {
309 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
310 exit $ERRORS{'UNKNOWN'};
314 @lines = reverse <MAILQ>;
316 # close qmail-qstat
317 close MAILQ;
319 if ( $? ) {
320 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
321 exit $ERRORS{CRITICAL};
324 ## shut off the alarm
325 alarm(0);
327 # check queue length
328 if ($lines[0]=~/Kbytes in (\d+)/) {
329 $msg_q = $1 ;
330 }elsif ($lines[0]=~/Mail queue is empty/) {
331 $msg_q = 0;
332 }else{
333 print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n";
334 exit $ERRORS{'UNKNOWN'};
337 # check messages not processed
338 #if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) {
339 # my $msg_p = $1;
340 #}else{
341 # print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n";
342 # exit $ERRORS{'UNKNOWN'};
345 # check queue length(s)
346 if ($msg_q == 0){
347 $msg = "OK: mailq reports queue is empty";
348 $state = $ERRORS{'OK'};
349 } else {
350 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
352 # overall queue length
353 if ($msg_q < $opt_w) {
354 $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
355 $state = $ERRORS{'OK'};
356 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
357 $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)";
358 $state = $ERRORS{'WARNING'};
359 }else {
360 $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)";
361 $state = $ERRORS{'CRITICAL'};
364 # check messages not yet preprocessed (only compare is $opt_W and $opt_C
365 # are defined)
367 #if (defined $opt_W) {
368 # $msg .= "[Preprocessed = $msg_p]";
369 # if ($msg_p >= $opt_W && $msg_p < $opt_C ) {
370 # $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ;
371 # }elsif ($msg_p >= $opt_C ) {
372 # $state = $ERRORS{"CRITICAL"} ;
376 } # end of ($mailq eq "postfixl")
377 elsif ( $mailq eq "qmail" ) {
379 # open qmail-qstat
380 if ( defined $utils::PATH_TO_QMAIL_QSTAT && -x $utils::PATH_TO_QMAIL_QSTAT ) {
381 if (! open (MAILQ, "$utils::PATH_TO_QMAIL_QSTAT | " ) ) {
382 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n";
383 exit $ERRORS{'UNKNOWN'};
385 }elsif( defined $utils::PATH_TO_QMAIL_QSTAT){
386 unless (-x $utils::PATH_TO_QMAIL_QSTAT) {
387 print "ERROR: $utils::PATH_TO_QMAIL_QSTAT is not executable by (uid $>:gid($)))\n";
388 exit $ERRORS{'UNKNOWN'};
390 } else {
391 print "ERROR: \$utils::PATH_TO_QMAIL_QSTAT is not defined\n";
392 exit $ERRORS{'UNKNOWN'};
395 @lines = <MAILQ>;
397 # close qmail-qstat
398 close MAILQ;
400 if ( $? ) {
401 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
402 exit $ERRORS{CRITICAL};
405 ## shut off the alarm
406 alarm(0);
408 # check queue length
409 if ($lines[0]=~/^messages in queue: (\d+)/) {
410 $msg_q = $1 ;
411 }else{
412 print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n";
413 exit $ERRORS{'UNKNOWN'};
416 # check messages not processed
417 if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) {
418 my $msg_p = $1;
419 }else{
420 print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n";
421 exit $ERRORS{'UNKNOWN'};
425 # check queue length(s)
426 if ($msg_q == 0){
427 $msg = "OK: qmail-qstat reports queue is empty";
428 $state = $ERRORS{'OK'};
429 } else {
430 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
432 # overall queue length
433 if ($msg_q < $opt_w) {
434 $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
435 $state = $ERRORS{'OK'};
436 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
437 $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)";
438 $state = $ERRORS{'WARNING'};
439 }else {
440 $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)";
441 $state = $ERRORS{'CRITICAL'};
444 # check messages not yet preprocessed (only compare is $opt_W and $opt_C
445 # are defined)
447 if (defined $opt_W) {
448 $msg .= "[Preprocessed = $msg_p]";
449 if ($msg_p >= $opt_W && $msg_p < $opt_C ) {
450 $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ;
451 }elsif ($msg_p >= $opt_C ) {
452 $state = $ERRORS{"CRITICAL"} ;
459 } # end of ($mailq eq "qmail")
460 elsif ( $mailq eq "exim" ) {
461 ## open mailq
462 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
463 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) {
464 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
465 exit $ERRORS{'UNKNOWN'};
467 }elsif( defined $utils::PATH_TO_MAILQ){
468 unless (-x $utils::PATH_TO_MAILQ) {
469 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
470 exit $ERRORS{'UNKNOWN'};
472 } else {
473 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
474 exit $ERRORS{'UNKNOWN'};
477 while (<MAILQ>) {
478 #22m 1.7K 19aEEr-0007hx-Dy <> *** frozen ***
479 #root@exlixams.glups.fr
481 if (/\s[\w\d]{6}-[\w\d]{6}-[\w\d]{2}\s/) { # message id 19aEEr-0007hx-Dy
482 $msg_q++ ;
485 close(MAILQ) ;
487 if ( $? ) {
488 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
489 exit $ERRORS{CRITICAL};
491 if ($msg_q < $opt_w) {
492 $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
493 $state = $ERRORS{'OK'};
494 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
495 $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)";
496 $state = $ERRORS{'WARNING'};
497 }else {
498 $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)";
499 $state = $ERRORS{'CRITICAL'};
501 } # end of ($mailq eq "exim")
503 # Perfdata support
504 print "$msg|unsent=$msg_q;$opt_w;$opt_c;0\n";
505 exit $state;
508 #####################################
509 #### subs
512 sub process_arguments(){
513 GetOptions
514 ("V" => \$opt_V, "version" => \$opt_V,
515 "v" => \$opt_v, "verbose" => \$opt_v,
516 "h" => \$opt_h, "help" => \$opt_h,
517 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail)
518 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number
519 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number
520 "t=i" => \$opt_t, "timeout=i" => \$opt_t
523 if ($opt_V) {
524 print_revision($PROGNAME,'@NP_VERSION@');
525 exit $ERRORS{'OK'};
528 if ($opt_h) {
529 print_help();
530 exit $ERRORS{'OK'};
533 if (defined $opt_v ){
534 $verbose = $opt_v;
537 unless (defined $opt_t) {
538 $opt_t = $utils::TIMEOUT ; # default timeout
541 unless ( defined $opt_w && defined $opt_c ) {
542 print_usage();
543 exit $ERRORS{'UNKNOWN'};
546 if ( $opt_w >= $opt_c) {
547 print "Warning (-w) cannot be greater than Critical (-c)!\n";
548 exit $ERRORS{'UNKNOWN'};
551 if (defined $opt_W && ! defined !$opt_C) {
552 print "Need -C if using -W\n";
553 exit $ERRORS{'UNKNOWN'};
554 }elsif(defined $opt_W && defined $opt_C) {
555 if ($opt_W >= $opt_C) {
556 print "Warning (-W) cannot be greater than Critical (-C)!\n";
557 exit $ERRORS{'UNKNOWN'};
561 if (defined $opt_M) {
562 if ($opt_M =~ /^(sendmail|qmail|postfix|exim)$/) {
563 $mailq = $opt_M ;
564 }elsif( $opt_M eq ''){
565 $mailq = 'sendmail';
566 }else{
567 print "-M: $opt_M is not supported\n";
568 exit $ERRORS{'UNKNOWN'};
570 }else{
571 $mailq = 'sendmail' ;
574 return $ERRORS{'OK'};
577 sub print_usage () {
578 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-v verbose]\n";
581 sub print_help () {
582 print_revision($PROGNAME,'@NP_VERSION@');
583 print "Copyright (c) 2002 Subhendu Ghosh/Carlos Canau/Benjamin Schmid\n";
584 print "\n";
585 print_usage();
586 print "\n";
587 print " Checks the number of messages in the mail queue (supports multiple sendmail queues, qmail)\n";
588 print " Feedback/patches to support non-sendmail mailqueue welcome\n\n";
589 print "-w (--warning) = Min. number of messages in queue to generate warning\n";
590 print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n";
591 print "-W (--Warning) = Min. number of messages for same domain in queue to generate warning\n";
592 print "-C (--Critical) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n";
593 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
594 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim ] (default = sendmail)\n";
595 print "-h (--help)\n";
596 print "-V (--version)\n";
597 print "-v (--verbose) = debugging output\n";
598 print "\n\n";
599 print "Note: -w and -c are required arguments. -W and -C are optional.\n";
600 print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n";
601 print " -W and -C are applied message not yet preproccessed. (qmail)\n";
602 print " This plugin uses the system mailq command (sendmail) or qmail-stat (qmail)\n";
603 print " to look at the queues. Mailq can usually only be accessed by root or \n";
604 print " a TrustedUser. You will have to set appropriate permissions for the plugin to work.\n";
605 print "";
606 print "\n\n";
607 support();