summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts')
-rw-r--r--plugins-scripts/Makefile.am4
-rwxr-xr-xplugins-scripts/check_mailq.pl179
-rw-r--r--plugins-scripts/utils.pm.in4
3 files changed, 185 insertions, 2 deletions
diff --git a/plugins-scripts/Makefile.am b/plugins-scripts/Makefile.am
index 1ca1549..5377bf4 100644
--- a/plugins-scripts/Makefile.am
+++ b/plugins-scripts/Makefile.am
@@ -6,11 +6,11 @@ VPATH=$(top_srcdir) $(top_srcdir)/plugins-scripts $(top_srcdir)/plugins-scripts/
6 6
7libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \ 7libexec_SCRIPTS = check_breeze check_disk_smb check_flexlm check_ircd \
8 check_log check_ntp check_oracle check_rpc check_sensors check_wave \ 8 check_log check_ntp check_oracle check_rpc check_sensors check_wave \
9 check_ifstatus check_ifoperstatus utils.sh utils.pm 9 check_ifstatus check_ifoperstatus check_mailq utils.sh utils.pm
10 10
11EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \ 11EXTRA_DIST=check_breeze.pl check_disk_smb.pl check_flexlm.pl check_ircd.pl \
12 check_log.sh check_ntp.pl check_oracle.sh check_rpc.pl check_sensors.sh \ 12 check_log.sh check_ntp.pl check_oracle.sh check_rpc.pl check_sensors.sh \
13 check_ifstatus.pl check_ifoperstatus.pl check_wave.pl utils.sh.in utils.pm.in t 13 check_ifstatus.pl check_ifoperstatus.pl check_wave.pl check_mailq.pl utils.sh.in utils.pm.in t
14 14
15TESTS_ENVIRONMENT=perl -I $(top_builddir) -I $(top_srcdir) 15TESTS_ENVIRONMENT=perl -I $(top_builddir) -I $(top_srcdir)
16 16
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
new file mode 100755
index 0000000..901209b
--- /dev/null
+++ b/plugins-scripts/check_mailq.pl
@@ -0,0 +1,179 @@
1#!/usr/local/bin/perl -w
2
3# check_mailq - check to see how many messages are in the smtp queue awating
4# transmittal.
5#
6# Initial version support sendmail's mailq command
7
8# License Information:
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22#
23############################################################################
24
25use POSIX;
26use strict;
27use Getopt::Long;
28use vars qw($opt_V $opt_h $opt_v $verbose $PROGNAME $opt_w $opt_c $opt_t $status $state $msg $msg_q );
29use lib utils.pm;
30use utils qw(%ERRORS &print_revision &support &usage );
31
32#my $MAILQ = "/usr/bin/mailq"; # need to migrate support to utils.pm and autoconf
33
34
35sub print_help ();
36sub print_usage ();
37sub process_arguments ();
38
39$ENV{'PATH'}='';
40$ENV{'BASH_ENV'}='';
41$ENV{'ENV'}='';
42$PROGNAME = "check_mailq";
43
44Getopt::Long::Configure('bundling');
45$status = process_arguments();
46if ($status){
47 print "ERROR: processing arguments\n";
48 exit $ERRORS{"UNKNOWN"};
49}
50
51$SIG{'ALRM'} = sub {
52 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n");
53 exit $ERRORS{"WARNING"};
54};
55alarm($opt_t);
56
57## open mailq
58if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) {
59 if (! open (MAILQ, "$utils::PATH_TO_MAILQ | " ) ) {
60 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
61 exit $ERRORS{'UNKNOWN'};
62 }
63}else{
64 print "ERROR: Could not find mailq executable!\n";
65 exit $ERRORS{'UNKNOWN'};
66}
67
68# only first line is relevant in this iteration.
69while (<MAILQ>) {
70 if (/mqueue/) {
71 print "$utils::PATH_TO_MAILQ = $_ "if $verbose ;
72 if (/empty/ ) {
73 $msg = "OK: mailq is empty";
74 $msg_q = 0;
75 $state = $ERRORS{'OK'};
76 }elsif ( /(\d+)/ ) {
77 $msg_q = $1 ;
78
79 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
80
81 if ($msg_q < $opt_w) {
82 $msg = "OK: mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
83 $state = $ERRORS{'OK'};
84 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
85 $msg = "WARNING: mailq is $msg_q (threshold w = $opt_w)";
86 $state = $ERRORS{'WARNING'};
87 }else {
88 $msg = "CRITICAL: mailq is $msg_q (threshold c = $opt_c)";
89 $state = $ERRORS{'CRITICAL'};
90 }
91
92 }
93
94 last;
95 }
96
97}
98
99close (MAILQ);
100# declare an error if we also get a non-zero return code from mailq
101# unless already set to critical
102if ( $? ) {
103 print "stderr = $? : $! \n" if $verbose;
104 $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"UNKNOWN"} ;
105 print "MAILQ error: $!\n" if $verbose;
106}
107## close mailq
108
109# Perfdata support
110print "$msg | mailq = $msg_q\n";
111exit $state;
112
113
114#####################################
115#### subs
116
117
118sub process_arguments(){
119 GetOptions
120 ("V" => \$opt_V, "version" => \$opt_V,
121 "v" => \$opt_v, "verbose" => \$opt_v,
122 "h" => \$opt_h, "help" => \$opt_h,
123 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number
124 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number
125 "t=i" => \$opt_t, "timeout=i" => \$opt_t
126 );
127
128 if ($opt_V) {
129 print_revision($PROGNAME,'$Revision$ ');
130 exit $ERRORS{'OK'};
131 }
132
133 if ($opt_h) {
134 print_help();
135 exit $ERRORS{'OK'};
136 }
137
138 if (defined $opt_v ){
139 $verbose = $opt_v;
140 }
141
142 unless (defined $opt_t) {
143 $opt_t = $utils::TIMEOUT ; # default timeout
144 }
145
146 unless ( defined $opt_w && defined $opt_c ) {
147 print_usage();
148 exit $ERRORS{'UNKNOWN'};
149 }
150
151 if ( $opt_w >= $opt_c) {
152 print "Warning cannot be greater than Critical!\n";
153 exit $ERRORS{'UNKNOWN'};
154 }
155
156 return $ERRORS{'OK'};
157}
158
159sub print_usage () {
160 print "Usage: $PROGNAME [-w <warn>] [-c <crit>] [-t <timeout>] [-v verbose]\n";
161}
162
163sub print_help () {
164 print_revision($PROGNAME,'$Revision$');
165 print "Copyright (c) 2002 Subhendu Ghosh\n";
166 print "\n";
167 print_usage();
168 print "\n";
169 print " Checks the number of messages in the mail queue\n";
170 print " Feedback/patches to support non-sendmail mailqueue welcome\n\n";
171 print "-w (--warning) = Min. number of messages in queue to generate warning\n";
172 print "-c (--critical) = Min. number of messages in queu to generate critical alert ( w < c )\n";
173 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
174 print "-h (--help)\n";
175 print "-V (--version)\n";
176 print "-v (--verbose) = deebugging output\n";
177 print "\n\n";
178 support();
179}
diff --git a/plugins-scripts/utils.pm.in b/plugins-scripts/utils.pm.in
index fe9bc24..05735eb 100644
--- a/plugins-scripts/utils.pm.in
+++ b/plugins-scripts/utils.pm.in
@@ -2,6 +2,9 @@
2# $Id$ 2# $Id$
3# 3#
4# $Log$ 4# $Log$
5# Revision 1.5 2002/10/30 05:07:29 sghosh
6# monitor mailq
7#
5# Revision 1.4 2002/05/27 02:01:09 sghosh 8# Revision 1.4 2002/05/27 02:01:09 sghosh
6# new var - smbclient 9# new var - smbclient
7# 10#
@@ -31,6 +34,7 @@ $PATH_TO_NTPDATE = "@PATH_TO_NTPDATE@" ;
31$PATH_TO_NTPDC = "@PATH_TO_NTPDC@" ; 34$PATH_TO_NTPDC = "@PATH_TO_NTPDC@" ;
32$PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ; 35$PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
33$PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ; 36$PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
37$PATH_TO_MAILQ = "@PATH_TO_MAILQ@";
34 38
35## common variables 39## common variables
36$TIMEOUT = 15; 40$TIMEOUT = 15;