summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_mailq.pl
diff options
context:
space:
mode:
authorSubhendu Ghosh <sghosh@users.sourceforge.net>2002-10-30 05:07:29 (GMT)
committerSubhendu Ghosh <sghosh@users.sourceforge.net>2002-10-30 05:07:29 (GMT)
commitce72bc784d0bc9bdc70f5f74f2a0823eb816d710 (patch)
treed5454f300bd39f4802cd8267ef6a0dd77fb0e18f /plugins-scripts/check_mailq.pl
parenta7fed9440ff832951c7fcaef915aba9080d58cf6 (diff)
downloadmonitoring-plugins-ce72bc784d0bc9bdc70f5f74f2a0823eb816d710.tar.gz
monitor mailq
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@163 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts/check_mailq.pl')
-rwxr-xr-xplugins-scripts/check_mailq.pl179
1 files changed, 179 insertions, 0 deletions
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}