summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_mailq.pl
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/check_mailq.pl')
-rwxr-xr-xplugins-scripts/check_mailq.pl84
1 files changed, 58 insertions, 26 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index aac1310e..49156af3 100755
--- a/plugins-scripts/check_mailq.pl
+++ b/plugins-scripts/check_mailq.pl
@@ -4,7 +4,7 @@
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 mutiple sendmail queues (Carlos Canau) 7# Support for multiple sendmail queues (Carlos Canau)
8# Support for qmail (Benjamin Schmid) 8# Support for qmail (Benjamin Schmid)
9 9
10# License Information: 10# License Information:
@@ -28,9 +28,9 @@
28use POSIX; 28use POSIX;
29use strict; 29use strict;
30use Getopt::Long; 30use Getopt::Long;
31use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $opt_s 31use 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 @lines 32 $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq $mailq_args
33 %srcdomains %dstdomains); 33 @lines %srcdomains %dstdomains);
34use FindBin; 34use FindBin;
35use lib "$FindBin::Bin"; 35use lib "$FindBin::Bin";
36use utils qw(%ERRORS &print_revision &support &usage ); 36use utils qw(%ERRORS &print_revision &support &usage );
@@ -48,6 +48,8 @@ $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
52$mailq_args = '' ;
51$state = $ERRORS{'UNKNOWN'}; 53$state = $ERRORS{'UNKNOWN'};
52 54
53Getopt::Long::Configure('bundling'); 55Getopt::Long::Configure('bundling');
@@ -68,6 +70,10 @@ if ($opt_s) {
68 $sudo = ""; 70 $sudo = "";
69} 71}
70 72
73if ($opt_d) {
74 $mailq_args = $mailq_args . ' -C ' . $opt_d;
75}
76
71$SIG{'ALRM'} = sub { 77$SIG{'ALRM'} = sub {
72 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); 78 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n");
73 exit $ERRORS{"WARNING"}; 79 exit $ERRORS{"WARNING"};
@@ -143,7 +149,26 @@ if ($mailq eq "sendmail") {
143##/var/spool/mqueue/qF/df is empty 149##/var/spool/mqueue/qF/df is empty
144## Total Requests: 1 150## Total Requests: 1
145 151
146 152# separate submission/transport queues, empty
153## MSP Queue status...
154## /var/spool/mqueue-client is empty
155## Total requests: 0
156## MTA Queue status...
157## /var/spool/mqueue is empty
158## Total requests: 0
159# separate submission/transport queues: 1
160## MSP Queue status...
161## /var/spool/mqueue-client (1 request)
162## -----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
163## oAJEfhdW014123 5 Fri Nov 19 14:41 jwm
164## (Deferred: Connection refused by [127.0.0.1])
165## root
166## Total requests: 1
167## MTA Queue status...
168## /var/spool/mqueue is empty
169## Total requests: 0
170
171 my $this_msg_q = 0;
147 while (<MAILQ>) { 172 while (<MAILQ>) {
148 173
149 # match email addr on queue listing 174 # match email addr on queue listing
@@ -183,13 +208,18 @@ if ($mailq eq "sendmail") {
183 # 208 #
184 # single queue: first line 209 # single queue: first line
185 # multi queue: one for each queue. overwrite on multi queue below 210 # multi queue: one for each queue. overwrite on multi queue below
186 $msg_q = $1 ; 211 $this_msg_q = $1 ;
212 $msg_q += $1 ;
187 } 213 }
188 } elsif (/^\s+Total\sRequests:\s(\d+)$/i) { 214 } elsif (/^\s+Total\sRequests:\s(\d+)$/i) {
189 print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ; 215 if ($this_msg_q) {
190 # 216 $this_msg_q = 0 ;
191 # multi queue: last line 217 } else {
192 $msg_q = $1 ; 218 print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ;
219 #
220 # multi queue: last line
221 $msg_q += $1 ;
222 }
193 } 223 }
194 224
195 } 225 }
@@ -309,8 +339,8 @@ elsif ( $mailq eq "postfix" ) {
309 339
310 ## open mailq 340 ## open mailq
311 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 341 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
312 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { 342 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) {
313 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 343 print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n";
314 exit $ERRORS{'UNKNOWN'}; 344 exit $ERRORS{'UNKNOWN'};
315 } 345 }
316 }elsif( defined $utils::PATH_TO_MAILQ){ 346 }elsif( defined $utils::PATH_TO_MAILQ){
@@ -330,7 +360,7 @@ elsif ( $mailq eq "postfix" ) {
330 close MAILQ; 360 close MAILQ;
331 361
332 if ( $? ) { 362 if ( $? ) {
333 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; 363 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ$mailq_args",$/;
334 exit $ERRORS{CRITICAL}; 364 exit $ERRORS{CRITICAL};
335 } 365 }
336 366
@@ -343,7 +373,7 @@ elsif ( $mailq eq "postfix" ) {
343 }elsif ($lines[0]=~/Mail queue is empty/) { 373 }elsif ($lines[0]=~/Mail queue is empty/) {
344 $msg_q = 0; 374 $msg_q = 0;
345 }else{ 375 }else{
346 print "Couldn't match $utils::PATH_TO_MAILQ output\n"; 376 print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n";
347 exit $ERRORS{'UNKNOWN'}; 377 exit $ERRORS{'UNKNOWN'};
348 } 378 }
349 379
@@ -531,9 +561,9 @@ elsif ( $mailq eq "nullmailer" ) {
531 } 561 }
532 562
533 while (<MAILQ>) { 563 while (<MAILQ>) {
534 #2006-06-22 16:00:00 282 bytes 564 #2022-08-25 01:30:40 502 bytes from <user@example.com>
535 565
536 if (/^[1-9][0-9]*-[01][0-9]-[0-3][0-9]\s[0-2][0-9]\:[0-2][0-9]\:[0-2][0-9]\s{2}[0-9]+\sbytes$/) { 566 if (/^\d{4}-\d{2}-\d{2}\s+\d{2}\:\d{2}\:\d{2}\s+\d+\sbytes/) {
537 $msg_q++ ; 567 $msg_q++ ;
538 } 568 }
539 } 569 }
@@ -561,16 +591,17 @@ exit $state;
561 591
562sub process_arguments(){ 592sub process_arguments(){
563 GetOptions 593 GetOptions
564 ("V" => \$opt_V, "version" => \$opt_V, 594 ("V" => \$opt_V, "version" => \$opt_V,
565 "v" => \$opt_v, "verbose" => \$opt_v, 595 "v" => \$opt_v, "verbose" => \$opt_v,
566 "h" => \$opt_h, "help" => \$opt_h, 596 "h" => \$opt_h, "help" => \$opt_h,
567 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) 597 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail)
568 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number 598 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number
569 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number 599 "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
601 "C=i" => \$opt_C, "critical-domain=i" => \$opt_C, # Critical if above this number
570 "t=i" => \$opt_t, "timeout=i" => \$opt_t, 602 "t=i" => \$opt_t, "timeout=i" => \$opt_t,
571 "s" => \$opt_s, "sudo" => \$opt_s, 603 "s" => \$opt_s, "sudo" => \$opt_s,
572 "W=i" => \$opt_W, # warning if above this number 604 "d:s" => \$opt_d, "configdir:s" => \$opt_d,
573 "C=i" => \$opt_C, # critical if above this number
574 ); 605 );
575 606
576 if ($opt_V) { 607 if ($opt_V) {
@@ -651,7 +682,7 @@ sub process_arguments(){
651} 682}
652 683
653sub print_usage () { 684sub print_usage () {
654 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-v]\n"; 685 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n";
655} 686}
656 687
657sub print_help () { 688sub print_help () {
@@ -664,14 +695,15 @@ sub print_help () {
664 print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; 695 print " Feedback/patches to support non-sendmail mailqueue welcome\n\n";
665 print "-w (--warning) = Min. number of messages in queue to generate warning\n"; 696 print "-w (--warning) = Min. number of messages in queue to generate warning\n";
666 print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; 697 print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n";
667 print "-W = Min. number of messages for same domain in queue to generate warning\n"; 698 print "-W (--warning-domain) = Min. number of messages for same domain in queue to generate warning\n";
668 print "-C = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; 699 print "-C (--critical-domain) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n";
669 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; 700 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
670 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; 701 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n";
671 print "-s (--sudo) = Use sudo to call the mailq command\n"; 702 print "-s (--sudo) = Use sudo to call the mailq command\n";
703 print "-d (--configdir) = Config file or directory\n";
672 print "-h (--help)\n"; 704 print "-h (--help)\n";
673 print "-V (--version)\n"; 705 print "-V (--version)\n";
674 print "-v (--verbose) = debugging output\n"; 706 print "-v (--verbose) = debugging output\n";
675 print "\n\n"; 707 print "\n\n";
676 print "Note: -w and -c are required arguments. -W and -C are optional.\n"; 708 print "Note: -w and -c are required arguments. -W and -C are optional.\n";
677 print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n"; 709 print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n";