summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-xplugins-scripts/check_mailq.pl1042
-rwxr-xr-xplugins-scripts/check_oracle.sh23
2 files changed, 530 insertions, 535 deletions
diff --git a/plugins-scripts/check_mailq.pl b/plugins-scripts/check_mailq.pl
index 49156af3..f143c6fa 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)
@@ -29,8 +29,8 @@ use 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 $opt_d 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 $mailq_args 32 $opt_M $mailq $status $state $msg $msg_q $msg_p $opt_W $opt_C $mailq $mailq_args
33 @lines %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 );
@@ -42,10 +42,10 @@ sub print_usage ();
42sub process_arguments (); 42sub 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
49$msg_q = 0 ; 49$msg_q = 0 ;
50$msg_p = 0 ; 50$msg_p = 0 ;
51# If appended, must start with a space 51# If appended, must start with a space
@@ -55,50 +55,49 @@ $state = $ERRORS{'UNKNOWN'};
55Getopt::Long::Configure('bundling'); 55Getopt::Long::Configure('bundling');
56$status = process_arguments(); 56$status = process_arguments();
57if ($status){ 57if ($status){
58 print "ERROR: processing arguments\n"; 58 print "ERROR: processing arguments\n";
59 exit $ERRORS{"UNKNOWN"}; 59 exit $ERRORS{"UNKNOWN"};
60} 60}
61 61
62if ($opt_s) { 62if ($opt_s) {
63 if (defined $utils::PATH_TO_SUDO && -x $utils::PATH_TO_SUDO) { 63 if (defined $utils::PATH_TO_SUDO && -x $utils::PATH_TO_SUDO) {
64 $sudo = $utils::PATH_TO_SUDO; 64 $sudo = $utils::PATH_TO_SUDO;
65 } else { 65 } else {
66 print "ERROR: Cannot execute sudo\n"; 66 print "ERROR: Cannot execute sudo\n";
67 exit $ERRORS{'UNKNOWN'}; 67 exit $ERRORS{'UNKNOWN'};
68 } 68 }
69} else { 69} else {
70 $sudo = ""; 70 $sudo = "";
71} 71}
72 72
73if ($opt_d) { 73if ($opt_d) {
74 $mailq_args = $mailq_args . ' -C ' . $opt_d; 74 $mailq_args = $mailq_args . ' -C ' . $opt_d;
75} 75}
76 76
77$SIG{'ALRM'} = sub { 77$SIG{'ALRM'} = sub {
78 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n"); 78 print ("ERROR: timed out waiting for $utils::PATH_TO_MAILQ \n");
79 exit $ERRORS{"WARNING"}; 79 exit $ERRORS{"WARNING"};
80}; 80};
81alarm($opt_t); 81alarm($opt_t);
82 82
83# switch based on MTA 83# switch based on MTA
84 84
85if ($mailq eq "sendmail") { 85if ($mailq eq "sendmail") {
86 86 if( ! $utils::PATH_TO_MAILQ) {
87 ## open mailq 87 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
88 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 88 exit $ERRORS{'UNKNOWN'};
89 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { 89 }
90 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 90
91 exit $ERRORS{'UNKNOWN'}; 91 if ( ! -x $utils::PATH_TO_MAILQ) {
92 } 92 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
93 }elsif( defined $utils::PATH_TO_MAILQ){ 93 exit $ERRORS{'UNKNOWN'};
94 unless (-x $utils::PATH_TO_MAILQ) { 94 }
95 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; 95
96 exit $ERRORS{'UNKNOWN'}; 96 ## open mailq
97 } 97 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
98 } else { 98 print "ERROR: could not open $sudo $utils::PATH_TO_MAILQ \n";
99 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; 99 exit $ERRORS{'UNKNOWN'};
100 exit $ERRORS{'UNKNOWN'}; 100 }
101 }
102# single queue empty 101# single queue empty
103##/var/spool/mqueue is empty 102##/var/spool/mqueue is empty
104# single queue: 1 103# single queue: 1
@@ -168,213 +167,207 @@ if ($mailq eq "sendmail") {
168## /var/spool/mqueue is empty 167## /var/spool/mqueue is empty
169## Total requests: 0 168## Total requests: 0
170 169
171 my $this_msg_q = 0; 170 my $this_msg_q = 0;
172 while (<MAILQ>) { 171 while (<MAILQ>) {
173 172
174 # match email addr on queue listing 173 # match email addr on queue listing
175 if ( (/<.*@.*\.(\w+\.\w+)>/) || (/<.*@(\w+\.\w+)>/) ) { 174 if ( (/<.*@.*\.(\w+\.\w+)>/) || (/<.*@(\w+\.\w+)>/) ) {
176 my $domain = $1; 175 my $domain = $1;
177 if (/^\w+/) { 176 if (/^\w+/) {
178 print "$utils::PATH_TO_MAILQ = srcdomain = $domain \n" if $verbose ; 177 print "$utils::PATH_TO_MAILQ = srcdomain = $domain \n" if $verbose ;
179 $srcdomains{$domain} ++; 178 $srcdomains{$domain} ++;
180 } 179 }
181 next; 180 next;
182 } 181 }
183
184 #
185 # ...
186 # sendmail considers a message with more than one destiny, say N, to the same MX
187 # to have N messages in queue.
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+)\.$/ ) ||
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+)\):/ ) ||
192 ( /\s\(Deferred:\s.*\s.*\.(\w+\.\w+)\.\)/ ) || ( /\s\(Deferred:\s.*\s(\w+\.\w+)\.\)/ ) ) {
193
194 print "$utils::PATH_TO_MAILQ = dstdomain = $1 \n" if $verbose ;
195 $dstdomains{$1} ++;
196 }
197
198 if (/\s+\(I\/O\serror\)/) {
199 print "$utils::PATH_TO_MAILQ = dstdomain = UNKNOWN \n" if $verbose ;
200 $dstdomains{'UNKNOWN'} ++;
201 }
202
203 # Finally look at the overall queue length
204 #
205 if (/mqueue/) {
206 print "$utils::PATH_TO_MAILQ = $_ "if $verbose ;
207 if (/ \((\d+) request/) {
208 #
209 # single queue: first line
210 # multi queue: one for each queue. overwrite on multi queue below
211 $this_msg_q = $1 ;
212 $msg_q += $1 ;
213 }
214 } elsif (/^\s+Total\sRequests:\s(\d+)$/i) {
215 if ($this_msg_q) {
216 $this_msg_q = 0 ;
217 } else {
218 print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ;
219 #
220 # multi queue: last line
221 $msg_q += $1 ;
222 }
223 }
224
225 }
226
227
228 ## close mailq
229
230 close (MAILQ);
231
232 if ( $? ) {
233 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
234 exit $ERRORS{CRITICAL};
235 }
236
237 ## shut off the alarm
238 alarm(0);
239
240
241
242 ## now check the queue length(s)
243
244 if ($msg_q == 0) {
245 $msg = "OK: $mailq mailq is empty";
246 $state = $ERRORS{'OK'};
247 } else {
248 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
249
250 # overall queue length
251 if ($msg_q < $opt_w) {
252 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
253 $state = $ERRORS{'OK'};
254 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
255 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
256 $state = $ERRORS{'WARNING'};
257 }else {
258 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
259 $state = $ERRORS{'CRITICAL'};
260 }
261
262 # check for domain specific queue lengths if requested
263 if (defined $opt_W) {
264
265 # Apply threshold to queue lengths FROM domain
266 my @srckeys = sort { $srcdomains{$b} <=> $srcdomains{$a} } keys %srcdomains;
267 my $srcmaxkey = $srckeys[0];
268 print "src max is $srcmaxkey with $srcdomains{$srcmaxkey} messages\n" if $verbose;
269
270 if ($srcdomains{$srcmaxkey} >= $opt_W && $srcdomains{$srcmaxkey} < $opt_C) {
271 if ($state == $ERRORS{'OK'}) {
272 $msg = "WARNING: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
273 $state = $ERRORS{'WARNING'};
274 } elsif (($state == $ERRORS{'WARNING'}) || ($state == $ERRORS{'CRITICAL'})){
275 $msg .= " -and- $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
276 } else {
277 $msg = "WARNING: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
278 $state = $ERRORS{'WARNING'};
279 }
280 } elsif ($srcdomains{$srcmaxkey} >= $opt_C) {
281 if ($state == $ERRORS{'OK'}) {
282 $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold C = $opt_C)";
283 $state = $ERRORS{'CRITICAL'};
284 } elsif ($state == $ERRORS{'WARNING'}) {
285 $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold C = $opt_C) -and- " . $msg;
286 $msg =~ s/WARNING: //;
287 } elsif ($state == $ERRORS{'CRITICAL'}) {
288 $msg .= " -and- $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
289 } else {
290 $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
291 $state = $ERRORS{'CRITICAL'};
292 }
293 } else {
294 if ($srcdomains{$srcmaxkey} > 0) {
295 $msg .= " $srcdomains{$srcmaxkey} msgs. FROM $srcmaxkey is below threshold ($opt_W/$opt_C)";
296 }
297 }
298
299 # Apply threshold to queue lengths TO domain
300 my @dstkeys = sort { $dstdomains{$b} <=> $dstdomains{$a} } keys %dstdomains;
301 my $dstmaxkey = $dstkeys[0];
302 print "dst max is $dstmaxkey with $dstdomains{$dstmaxkey} messages\n" if $verbose;
303
304 if ($dstdomains{$dstmaxkey} >= $opt_W && $dstdomains{$dstmaxkey} < $opt_C) {
305 if ($state == $ERRORS{'OK'}) {
306 $msg = "WARNING: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
307 $state = $ERRORS{'WARNING'};
308 } elsif (($state == $ERRORS{'WARNING'}) || ($state == $ERRORS{'CRITICAL'})){
309 $msg .= " -and- $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
310 } else {
311 $msg = "WARNING: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
312 $state = $ERRORS{'WARNING'};
313 }
314 } elsif ($dstdomains{$dstmaxkey} >= $opt_C) {
315 if ($state == $ERRORS{'OK'}) {
316 $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold C = $opt_C)";
317 $state = $ERRORS{'CRITICAL'};
318 } elsif ($state == $ERRORS{'WARNING'}) {
319 $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold C = $opt_C) -and- " . $msg;
320 $msg =~ s/WARNING: //;
321 } elsif ($state == $ERRORS{'CRITICAL'}) {
322 $msg .= " -and- $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
323 } else {
324 $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
325 $state = $ERRORS{'CRITICAL'};
326 }
327 } else {
328 if ($dstdomains{$dstmaxkey} > 0) {
329 $msg .= " $dstdomains{$dstmaxkey} msgs. TO $dstmaxkey is below threshold ($opt_W/$opt_C)";
330 }
331 }
332
333 } # End of queue length thresholds
334
335 }
336 182
337} # end of ($mailq eq "sendmail") 183 #
338elsif ( $mailq eq "postfix" ) { 184 # ...
185 # sendmail considers a message with more than one destiny, say N, to the same MX
186 # to have N messages in queue.
187 # we will only consider one in this code
188 if (( /\s\(reply:\sread\serror\sfrom\s.*\.(\w+\.\w+)\.$/ ) || ( /\s\(reply:\sread\serror\sfrom\s(\w+\.\w+)\.$/ ) ||
189 ( /\s\(timeout\swriting\smessage\sto\s.*\.(\w+\.\w+)\.:/ ) || ( /\s\(timeout\swriting\smessage\sto\s(\w+\.\w+)\.:/ ) ||
190 ( /\s\(host\smap:\slookup\s\(.*\.(\w+\.\w+)\):/ ) || ( /\s\(host\smap:\slookup\s\((\w+\.\w+)\):/ ) ||
191 ( /\s\(Deferred:\s.*\s.*\.(\w+\.\w+)\.\)/ ) || ( /\s\(Deferred:\s.*\s(\w+\.\w+)\.\)/ ) ) {
192
193 print "$utils::PATH_TO_MAILQ = dstdomain = $1 \n" if $verbose ;
194 $dstdomains{$1} ++;
195 }
339 196
340 ## open mailq 197 if (/\s+\(I\/O\serror\)/) {
341 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 198 print "$utils::PATH_TO_MAILQ = dstdomain = UNKNOWN \n" if $verbose ;
342 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) { 199 $dstdomains{'UNKNOWN'} ++;
343 print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n";
344 exit $ERRORS{'UNKNOWN'};
345 }
346 }elsif( defined $utils::PATH_TO_MAILQ){
347 unless (-x $utils::PATH_TO_MAILQ) {
348 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
349 exit $ERRORS{'UNKNOWN'};
350 }
351 } else {
352 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
353 exit $ERRORS{'UNKNOWN'};
354 } 200 }
355 201
202 # Finally look at the overall queue length
203 #
204 if (/mqueue/) {
205 print "$utils::PATH_TO_MAILQ = $_ "if $verbose ;
206 if (/ \((\d+) request/) {
207 #
208 # single queue: first line
209 # multi queue: one for each queue. overwrite on multi queue below
210 $this_msg_q = $1 ;
211 $msg_q += $1 ;
212 }
213 } elsif (/^\s+Total\sRequests:\s(\d+)$/i) {
214 if ($this_msg_q) {
215 $this_msg_q = 0 ;
216 } else {
217 print "$utils::PATH_TO_MAILQ = $_ \n" if $verbose ;
218 #
219 # multi queue: last line
220 $msg_q += $1 ;
221 }
222 }
356 223
357 @lines = reverse <MAILQ>; 224 }
225
226 ## close mailq
227 close (MAILQ);
228
229 if ( $? ) {
230 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
231 exit $ERRORS{CRITICAL};
232 }
233
234 ## shut off the alarm
235 alarm(0);
236
237 ## now check the queue length(s)
238
239 if ($msg_q == 0) {
240 $msg = "OK: $mailq mailq is empty";
241 $state = $ERRORS{'OK'};
242 } else {
243 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
244
245 # overall queue length
246 if ($msg_q < $opt_w) {
247 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
248 $state = $ERRORS{'OK'};
249 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
250 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
251 $state = $ERRORS{'WARNING'};
252 }else {
253 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
254 $state = $ERRORS{'CRITICAL'};
255 }
358 256
359 # close qmail-qstat 257 # check for domain specific queue lengths if requested
360 close MAILQ; 258 if (defined $opt_W) {
259
260 # Apply threshold to queue lengths FROM domain
261 my @srckeys = sort { $srcdomains{$b} <=> $srcdomains{$a} } keys %srcdomains;
262 my $srcmaxkey = $srckeys[0];
263 print "src max is $srcmaxkey with $srcdomains{$srcmaxkey} messages\n" if $verbose;
264
265 if ($srcdomains{$srcmaxkey} >= $opt_W && $srcdomains{$srcmaxkey} < $opt_C) {
266 if ($state == $ERRORS{'OK'}) {
267 $msg = "WARNING: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
268 $state = $ERRORS{'WARNING'};
269 } elsif (($state == $ERRORS{'WARNING'}) || ($state == $ERRORS{'CRITICAL'})){
270 $msg .= " -and- $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
271 } else {
272 $msg = "WARNING: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
273 $state = $ERRORS{'WARNING'};
274 }
275 } elsif ($srcdomains{$srcmaxkey} >= $opt_C) {
276 if ($state == $ERRORS{'OK'}) {
277 $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold C = $opt_C)";
278 $state = $ERRORS{'CRITICAL'};
279 } elsif ($state == $ERRORS{'WARNING'}) {
280 $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold C = $opt_C) -and- " . $msg;
281 $msg =~ s/WARNING: //;
282 } elsif ($state == $ERRORS{'CRITICAL'}) {
283 $msg .= " -and- $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
284 } else {
285 $msg = "CRITICAL: $srcdomains{$srcmaxkey} messages in queue FROM $srcmaxkey (threshold W = $opt_W)";
286 $state = $ERRORS{'CRITICAL'};
287 }
288 } else {
289 if ($srcdomains{$srcmaxkey} > 0) {
290 $msg .= " $srcdomains{$srcmaxkey} msgs. FROM $srcmaxkey is below threshold ($opt_W/$opt_C)";
291 }
292 }
293
294 # Apply threshold to queue lengths TO domain
295 my @dstkeys = sort { $dstdomains{$b} <=> $dstdomains{$a} } keys %dstdomains;
296 my $dstmaxkey = $dstkeys[0];
297 print "dst max is $dstmaxkey with $dstdomains{$dstmaxkey} messages\n" if $verbose;
298
299 if ($dstdomains{$dstmaxkey} >= $opt_W && $dstdomains{$dstmaxkey} < $opt_C) {
300 if ($state == $ERRORS{'OK'}) {
301 $msg = "WARNING: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
302 $state = $ERRORS{'WARNING'};
303 } elsif (($state == $ERRORS{'WARNING'}) || ($state == $ERRORS{'CRITICAL'})){
304 $msg .= " -and- $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
305 } else {
306 $msg = "WARNING: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
307 $state = $ERRORS{'WARNING'};
308 }
309 } elsif ($dstdomains{$dstmaxkey} >= $opt_C) {
310 if ($state == $ERRORS{'OK'}) {
311 $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold C = $opt_C)";
312 $state = $ERRORS{'CRITICAL'};
313 } elsif ($state == $ERRORS{'WARNING'}) {
314 $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold C = $opt_C) -and- " . $msg;
315 $msg =~ s/WARNING: //;
316 } elsif ($state == $ERRORS{'CRITICAL'}) {
317 $msg .= " -and- $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
318 } else {
319 $msg = "CRITICAL: $dstdomains{$dstmaxkey} messages in queue TO $dstmaxkey (threshold W = $opt_W)";
320 $state = $ERRORS{'CRITICAL'};
321 }
322 } else {
323 if ($dstdomains{$dstmaxkey} > 0) {
324 $msg .= " $dstdomains{$dstmaxkey} msgs. TO $dstmaxkey is below threshold ($opt_W/$opt_C)";
325 }
326 }
361 327
362 if ( $? ) { 328 } # End of queue length thresholds
363 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ$mailq_args",$/;
364 exit $ERRORS{CRITICAL};
365 }
366 329
367 ## shut off the alarm 330 }
368 alarm(0);
369 331
370 # check queue length 332} # end of ($mailq eq "sendmail")
371 if ($lines[0]=~/Kbytes in (\d+)/) { 333elsif ( $mailq eq "postfix" ) {
372 $msg_q = $1 ; 334 if( ! $utils::PATH_TO_MAILQ ) {
373 }elsif ($lines[0]=~/Mail queue is empty/) { 335 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
374 $msg_q = 0; 336 exit $ERRORS{'UNKNOWN'};
337 }
338
339 if ( ! -x $utils::PATH_TO_MAILQ) {
340 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
341 exit $ERRORS{'UNKNOWN'};
342 }
343
344 ## open mailq
345 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ$mailq_args | " ) ) {
346 print "ERROR: could not open $utils::PATH_TO_MAILQ$mailq_args \n";
347 exit $ERRORS{'UNKNOWN'};
348 }
349
350 @lines = reverse <MAILQ>;
351
352 # close qmail-qstat
353 close MAILQ;
354
355 if ( $? ) {
356 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ$mailq_args",$/;
357 exit $ERRORS{CRITICAL};
358 }
359
360 ## shut off the alarm
361 alarm(0);
362
363 # check queue length
364 if ($lines[0]=~/Kbytes in (\d+)/) {
365 $msg_q = $1 ;
366 }elsif ($lines[0]=~/Mail queue is empty/) {
367 $msg_q = 0;
375 }else{ 368 }else{
376 print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n"; 369 print "Couldn't match $utils::PATH_TO_MAILQ$mailq_args output\n";
377 exit $ERRORS{'UNKNOWN'}; 370 exit $ERRORS{'UNKNOWN'};
378 } 371 }
379 372
380 # check messages not processed 373 # check messages not processed
@@ -390,194 +383,193 @@ elsif ( $mailq eq "postfix" ) {
390 $msg = "OK: $mailq mailq reports queue is empty"; 383 $msg = "OK: $mailq mailq reports queue is empty";
391 $state = $ERRORS{'OK'}; 384 $state = $ERRORS{'OK'};
392 } else { 385 } else {
393 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose; 386 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
394 387
395 # overall queue length 388 # overall queue length
396 if ($msg_q < $opt_w) { 389 if ($msg_q < $opt_w) {
397 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; 390 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
398 $state = $ERRORS{'OK'}; 391 $state = $ERRORS{'OK'};
399 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { 392 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
400 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; 393 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
401 $state = $ERRORS{'WARNING'}; 394 $state = $ERRORS{'WARNING'};
402 }else { 395 }else {
403 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; 396 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
404 $state = $ERRORS{'CRITICAL'}; 397 $state = $ERRORS{'CRITICAL'};
405 } 398 }
406 399
407 # check messages not yet preprocessed (only compare is $opt_W and $opt_C 400 # check messages not yet preprocessed (only compare is $opt_W and $opt_C
408 # are defined) 401 # are defined)
409 402
410 #if (defined $opt_W) { 403 #if (defined $opt_W) {
411 # $msg .= "[Preprocessed = $msg_p]"; 404 # $msg .= "[Preprocessed = $msg_p]";
412 # if ($msg_p >= $opt_W && $msg_p < $opt_C ) { 405 # if ($msg_p >= $opt_W && $msg_p < $opt_C ) {
413 # $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ; 406 # $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ;
414 # }elsif ($msg_p >= $opt_C ) { 407 # }elsif ($msg_p >= $opt_C ) {
415 # $state = $ERRORS{"CRITICAL"} ; 408 # $state = $ERRORS{"CRITICAL"} ;
416 # } 409 # }
417 #} 410 #}
418 } 411 }
419} # end of ($mailq eq "postfix") 412} # end of ($mailq eq "postfix")
420elsif ( $mailq eq "qmail" ) { 413elsif ( $mailq eq "qmail" ) {
414 if ( ! $utils::PATH_TO_QMAIL_QSTAT ) {
415 print "ERROR: \$utils::PATH_TO_QMAIL_QSTAT is not defined\n";
416 exit $ERRORS{'UNKNOWN'};
417 }
418
419 if ( ! -x $utils::PATH_TO_QMAIL_QSTAT) {
420 print "ERROR: $utils::PATH_TO_QMAIL_QSTAT is not executable by (uid $>:gid($)))\n";
421 exit $ERRORS{'UNKNOWN'};
422 }
423
424 # open qmail-qstat
425 if (! open (MAILQ, "$sudo $utils::PATH_TO_QMAIL_QSTAT | " ) ) {
426 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n";
427 exit $ERRORS{'UNKNOWN'};
428 }
429
430 @lines = <MAILQ>;
431
432 # close qmail-qstat
433 close MAILQ;
434
435 if ( $? ) {
436 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
437 exit $ERRORS{CRITICAL};
438 }
439
440 ## shut off the alarm
441 alarm(0);
442
443 # check queue length
444 if ($lines[0]=~/^messages in queue: (\d+)/) {
445 $msg_q = $1 ;
446 }else{
447 print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n";
448 exit $ERRORS{'UNKNOWN'};
449 }
450
451 # check messages not processed
452 if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) {
453 my $msg_p = $1;
454 }else{
455 print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n";
456 exit $ERRORS{'UNKNOWN'};
457 }
458
459
460 # check queue length(s)
461 if ($msg_q == 0){
462 $msg = "OK: qmail-qstat reports queue is empty";
463 $state = $ERRORS{'OK'};
464 } else {
465 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
466
467 # overall queue length
468 if ($msg_q < $opt_w) {
469 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
470 $state = $ERRORS{'OK'};
471 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
472 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
473 $state = $ERRORS{'WARNING'};
474 }else {
475 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
476 $state = $ERRORS{'CRITICAL'};
477 }
478
479 # check messages not yet preprocessed (only compare is $opt_W and $opt_C
480 # are defined)
481
482 if (defined $opt_W) {
483 $msg .= "[Preprocessed = $msg_p]";
484 if ($msg_p >= $opt_W && $msg_p < $opt_C ) {
485 $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ;
486 }elsif ($msg_p >= $opt_C ) {
487 $state = $ERRORS{"CRITICAL"} ;
488 }
489 }
490 }
421 491
422 # open 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 | " ) ) {
425 print "ERROR: could not open $utils::PATH_TO_QMAIL_QSTAT \n";
426 exit $ERRORS{'UNKNOWN'};
427 }
428 }elsif( defined $utils::PATH_TO_QMAIL_QSTAT){
429 unless (-x $utils::PATH_TO_QMAIL_QSTAT) {
430 print "ERROR: $utils::PATH_TO_QMAIL_QSTAT is not executable by (uid $>:gid($)))\n";
431 exit $ERRORS{'UNKNOWN'};
432 }
433 } else {
434 print "ERROR: \$utils::PATH_TO_QMAIL_QSTAT is not defined\n";
435 exit $ERRORS{'UNKNOWN'};
436 }
437
438 @lines = <MAILQ>;
439
440 # close qmail-qstat
441 close MAILQ;
442
443 if ( $? ) {
444 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
445 exit $ERRORS{CRITICAL};
446 }
447
448 ## shut off the alarm
449 alarm(0);
450
451 # check queue length
452 if ($lines[0]=~/^messages in queue: (\d+)/) {
453 $msg_q = $1 ;
454 }else{
455 print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n";
456 exit $ERRORS{'UNKNOWN'};
457 }
458
459 # check messages not processed
460 if ($lines[1]=~/^messages in queue but not yet preprocessed: (\d+)/) {
461 my $msg_p = $1;
462 }else{
463 print "Couldn't match $utils::PATH_TO_QMAIL_QSTAT output\n";
464 exit $ERRORS{'UNKNOWN'};
465 }
466
467
468 # check queue length(s)
469 if ($msg_q == 0){
470 $msg = "OK: qmail-qstat reports queue is empty";
471 $state = $ERRORS{'OK'};
472 } else {
473 print "msg_q = $msg_q warn=$opt_w crit=$opt_c\n" if $verbose;
474
475 # overall queue length
476 if ($msg_q < $opt_w) {
477 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
478 $state = $ERRORS{'OK'};
479 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
480 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
481 $state = $ERRORS{'WARNING'};
482 }else {
483 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
484 $state = $ERRORS{'CRITICAL'};
485 }
486
487 # check messages not yet preprocessed (only compare is $opt_W and $opt_C
488 # are defined)
489
490 if (defined $opt_W) {
491 $msg .= "[Preprocessed = $msg_p]";
492 if ($msg_p >= $opt_W && $msg_p < $opt_C ) {
493 $state = $state == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"WARNING"} ;
494 }elsif ($msg_p >= $opt_C ) {
495 $state = $ERRORS{"CRITICAL"} ;
496 }
497 }
498 }
499
500 492
501 493
502} # end of ($mailq eq "qmail") 494} # end of ($mailq eq "qmail")
503elsif ( $mailq eq "exim" ) { 495elsif ( $mailq eq "exim" ) {
504 ## open mailq 496 if ( ! $utils::PATH_TO_MAILQ ) {
505 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 497 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
506 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { 498 exit $ERRORS{'UNKNOWN'};
507 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 499 }
508 exit $ERRORS{'UNKNOWN'}; 500
509 } 501 if ( ! -x $utils::PATH_TO_MAILQ) {
510 }elsif( defined $utils::PATH_TO_MAILQ){ 502 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
511 unless (-x $utils::PATH_TO_MAILQ) { 503 exit $ERRORS{'UNKNOWN'};
512 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; 504 }
513 exit $ERRORS{'UNKNOWN'}; 505
514 } 506 ## open mailq
515 } else { 507 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
516 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; 508 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
517 exit $ERRORS{'UNKNOWN'}; 509 exit $ERRORS{'UNKNOWN'};
518 } 510 }
519 511
520 while (<MAILQ>) { 512 while (<MAILQ>) {
521 #22m 1.7K 19aEEr-0007hx-Dy <> *** frozen *** 513 #22m 1.7K 19aEEr-0007hx-Dy <> *** frozen ***
522 #root@exlixams.glups.fr 514 #root@exlixams.glups.fr
523 515
524 if (/\s[\w\d]{6}-[\w\d]{6}-[\w\d]{2}\s/) { # message id 19aEEr-0007hx-Dy 516 if (/\s[\w\d]{6}-[\w\d]{6}-[\w\d]{2}\s/) { # message id 19aEEr-0007hx-Dy
525 $msg_q++ ; 517 $msg_q++ ;
526 } 518 }
527 } 519 }
528 close(MAILQ) ; 520 close(MAILQ) ;
529 521
530 if ( $? ) { 522 if ( $? ) {
531 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/; 523 print "CRITICAL: Error code ".($?>>8)." returned from $utils::PATH_TO_MAILQ",$/;
532 exit $ERRORS{CRITICAL}; 524 exit $ERRORS{CRITICAL};
533 } 525 }
534 if ($msg_q < $opt_w) { 526 if ($msg_q < $opt_w) {
535 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; 527 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
536 $state = $ERRORS{'OK'}; 528 $state = $ERRORS{'OK'};
537 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { 529 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
538 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; 530 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
539 $state = $ERRORS{'WARNING'}; 531 $state = $ERRORS{'WARNING'};
540 }else { 532 }else {
541 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; 533 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
542 $state = $ERRORS{'CRITICAL'}; 534 $state = $ERRORS{'CRITICAL'};
543 } 535 }
544} # end of ($mailq eq "exim") 536} # end of ($mailq eq "exim")
545 537
546elsif ( $mailq eq "nullmailer" ) { 538elsif ( $mailq eq "nullmailer" ) {
547 ## open mailq 539 if( ! $utils::PATH_TO_MAILQ) {
548 if ( defined $utils::PATH_TO_MAILQ && -x $utils::PATH_TO_MAILQ ) { 540 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n";
549 if (! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) { 541 exit $ERRORS{'UNKNOWN'};
550 print "ERROR: could not open $utils::PATH_TO_MAILQ \n"; 542 }
551 exit $ERRORS{'UNKNOWN'}; 543
552 } 544 if ( ! -x $utils::PATH_TO_MAILQ) {
553 }elsif( defined $utils::PATH_TO_MAILQ){ 545 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n";
554 unless (-x $utils::PATH_TO_MAILQ) { 546 exit $ERRORS{'UNKNOWN'};
555 print "ERROR: $utils::PATH_TO_MAILQ is not executable by (uid $>:gid($)))\n"; 547 }
556 exit $ERRORS{'UNKNOWN'}; 548
557 } 549 ## open mailq
558 } else { 550 if ( ! open (MAILQ, "$sudo $utils::PATH_TO_MAILQ | " ) ) {
559 print "ERROR: \$utils::PATH_TO_MAILQ is not defined\n"; 551 print "ERROR: could not open $utils::PATH_TO_MAILQ \n";
560 exit $ERRORS{'UNKNOWN'}; 552 exit $ERRORS{'UNKNOWN'};
561 } 553 }
562 554
563 while (<MAILQ>) { 555 while (<MAILQ>) {
564 #2022-08-25 01:30:40 502 bytes from <user@example.com> 556 #2022-08-25 01:30:40 502 bytes from <user@example.com>
565 557
566 if (/^\d{4}-\d{2}-\d{2}\s+\d{2}\:\d{2}\:\d{2}\s+\d+\sbytes/) { 558 if (/^\d{4}-\d{2}-\d{2}\s+\d{2}\:\d{2}\:\d{2}\s+\d+\sbytes/) {
567 $msg_q++ ; 559 $msg_q++ ;
568 } 560 }
569 } 561 }
570 close(MAILQ) ; 562 close(MAILQ) ;
571 if ($msg_q < $opt_w) { 563 if ($msg_q < $opt_w) {
572 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)"; 564 $msg = "OK: $mailq mailq ($msg_q) is below threshold ($opt_w/$opt_c)";
573 $state = $ERRORS{'OK'}; 565 $state = $ERRORS{'OK'};
574 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) { 566 }elsif ($msg_q >= $opt_w && $msg_q < $opt_c) {
575 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)"; 567 $msg = "WARNING: $mailq mailq is $msg_q (threshold w = $opt_w)";
576 $state = $ERRORS{'WARNING'}; 568 $state = $ERRORS{'WARNING'};
577 }else { 569 }else {
578 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)"; 570 $msg = "CRITICAL: $mailq mailq is $msg_q (threshold c = $opt_c)";
579 $state = $ERRORS{'CRITICAL'}; 571 $state = $ERRORS{'CRITICAL'};
580 } 572 }
581} # end of ($mailq eq "nullmailer") 573} # end of ($mailq eq "nullmailer")
582 574
583# Perfdata support 575# Perfdata support
@@ -590,130 +582,130 @@ exit $state;
590 582
591 583
592sub process_arguments(){ 584sub process_arguments(){
593 GetOptions 585 GetOptions
594 ("V" => \$opt_V, "version" => \$opt_V, 586 ("V" => \$opt_V, "version" => \$opt_V,
595 "v" => \$opt_v, "verbose" => \$opt_v, 587 "v" => \$opt_v, "verbose" => \$opt_v,
596 "h" => \$opt_h, "help" => \$opt_h, 588 "h" => \$opt_h, "help" => \$opt_h,
597 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail) 589 "M:s" => \$opt_M, "mailserver:s" => \$opt_M, # mailserver (default sendmail)
598 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number 590 "w=i" => \$opt_w, "warning=i" => \$opt_w, # warning if above this number
599 "c=i" => \$opt_c, "critical=i" => \$opt_c, # critical if above this number 591 "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 592 "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 593 "C=i" => \$opt_C, "critical-domain=i" => \$opt_C, # Critical if above this number
602 "t=i" => \$opt_t, "timeout=i" => \$opt_t, 594 "t=i" => \$opt_t, "timeout=i" => \$opt_t,
603 "s" => \$opt_s, "sudo" => \$opt_s, 595 "s" => \$opt_s, "sudo" => \$opt_s,
604 "d:s" => \$opt_d, "configdir:s" => \$opt_d, 596 "d:s" => \$opt_d, "configdir:s" => \$opt_d,
605 ); 597 );
606 598
607 if ($opt_V) { 599 if ($opt_V) {
608 print_revision($PROGNAME,'@NP_VERSION@'); 600 print_revision($PROGNAME,'@NP_VERSION@');
609 exit $ERRORS{'UNKNOWN'}; 601 exit $ERRORS{'UNKNOWN'};
610 } 602 }
611 603
612 if ($opt_h) { 604 if ($opt_h) {
613 print_help(); 605 print_help();
614 exit $ERRORS{'UNKNOWN'}; 606 exit $ERRORS{'UNKNOWN'};
615 } 607 }
616 608
617 if (defined $opt_v ){ 609 if (defined $opt_v ){
618 $verbose = $opt_v; 610 $verbose = $opt_v;
619 } 611 }
620 612
621 unless (defined $opt_t) { 613 unless (defined $opt_t) {
622 $opt_t = $utils::TIMEOUT ; # default timeout 614 $opt_t = $utils::TIMEOUT ; # default timeout
623 } 615 }
624 616
625 unless ( defined $opt_w && defined $opt_c ) { 617 unless ( defined $opt_w && defined $opt_c ) {
626 print_usage(); 618 print_usage();
627 exit $ERRORS{'UNKNOWN'}; 619 exit $ERRORS{'UNKNOWN'};
628 } 620 }
629 621
630 if ( $opt_w >= $opt_c) { 622 if ( $opt_w >= $opt_c) {
631 print "Warning (-w) cannot be greater than Critical (-c)!\n"; 623 print "Warning (-w) cannot be greater than Critical (-c)!\n";
632 exit $ERRORS{'UNKNOWN'}; 624 exit $ERRORS{'UNKNOWN'};
633 } 625 }
634 626
635 if (defined $opt_W && ! defined !$opt_C) { 627 if (defined $opt_W && ! defined !$opt_C) {
636 print "Need -C if using -W\n"; 628 print "Need -C if using -W\n";
637 exit $ERRORS{'UNKNOWN'}; 629 exit $ERRORS{'UNKNOWN'};
638 }elsif(defined $opt_W && defined $opt_C) { 630 }elsif(defined $opt_W && defined $opt_C) {
639 if ($opt_W >= $opt_C) { 631 if ($opt_W >= $opt_C) {
640 print "Warning (-W) cannot be greater than Critical (-C)!\n"; 632 print "Warning (-W) cannot be greater than Critical (-C)!\n";
641 exit $ERRORS{'UNKNOWN'}; 633 exit $ERRORS{'UNKNOWN'};
642 } 634 }
643 } 635 }
644 636
645 if (defined $opt_M) { 637 if (defined $opt_M) {
646 if ($opt_M =~ /^(sendmail|qmail|postfix|exim|nullmailer)$/) { 638 if ($opt_M =~ /^(sendmail|qmail|postfix|exim|nullmailer)$/) {
647 $mailq = $opt_M ; 639 $mailq = $opt_M ;
648 }elsif( $opt_M eq ''){ 640 }elsif( $opt_M eq ''){
649 $mailq = 'sendmail'; 641 $mailq = 'sendmail';
650 }else{ 642 }else{
651 print "-M: $opt_M is not supported\n"; 643 print "-M: $opt_M is not supported\n";
652 exit $ERRORS{'UNKNOWN'}; 644 exit $ERRORS{'UNKNOWN'};
653 } 645 }
654 }else{ 646 }else{
655 if (defined $utils::PATH_TO_QMAIL_QSTAT 647 if (defined $utils::PATH_TO_QMAIL_QSTAT
656 && -x $utils::PATH_TO_QMAIL_QSTAT) 648 && -x $utils::PATH_TO_QMAIL_QSTAT)
657 { 649 {
658 $mailq = 'qmail'; 650 $mailq = 'qmail';
659 } 651 }
660 elsif (-d '/var/lib/postfix' || -d '/var/local/lib/postfix' 652 elsif (-d '/var/lib/postfix' || -d '/var/local/lib/postfix'
661 || -e '/usr/sbin/postfix' || -e '/usr/local/sbin/postfix') 653 || -e '/usr/sbin/postfix' || -e '/usr/local/sbin/postfix')
662 { 654 {
663 $mailq = 'postfix'; 655 $mailq = 'postfix';
664 } 656 }
665 elsif (-d '/usr/lib/exim4' || -d '/usr/local/lib/exim4' 657 elsif (-d '/usr/lib/exim4' || -d '/usr/local/lib/exim4'
666 || -e '/usr/sbin/exim' || -e '/usr/local/sbin/exim') 658 || -e '/usr/sbin/exim' || -e '/usr/local/sbin/exim')
667 { 659 {
668 $mailq = 'exim'; 660 $mailq = 'exim';
669 } 661 }
670 elsif (-d '/usr/lib/nullmailer' || -d '/usr/local/lib/nullmailer' 662 elsif (-d '/usr/lib/nullmailer' || -d '/usr/local/lib/nullmailer'
671 || -e '/usr/sbin/nullmailer-send' 663 || -e '/usr/sbin/nullmailer-send'
672 || -e '/usr/local/sbin/nullmailer-send') 664 || -e '/usr/local/sbin/nullmailer-send')
673 { 665 {
674 $mailq = 'nullmailer'; 666 $mailq = 'nullmailer';
675 } 667 }
676 else { 668 else {
677 $mailq = 'sendmail'; 669 $mailq = 'sendmail';
678 } 670 }
679 } 671 }
680 672
681 return $ERRORS{'OK'}; 673 return $ERRORS{'OK'};
682} 674}
683 675
684sub print_usage () { 676sub print_usage () {
685 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n"; 677 print "Usage: $PROGNAME -w <warn> -c <crit> [-W <warn>] [-C <crit>] [-M <MTA>] [-t <timeout>] [-s] [-d <CONFIGDIR>] [-v]\n";
686} 678}
687 679
688sub print_help () { 680sub print_help () {
689 print_revision($PROGNAME,'@NP_VERSION@'); 681 print_revision($PROGNAME,'@NP_VERSION@');
690 print "Copyright (c) 2002 Subhendu Ghosh/Carlos Canau/Benjamin Schmid\n"; 682 print "Copyright (c) 2002 Subhendu Ghosh/Carlos Canau/Benjamin Schmid\n";
691 print "\n"; 683 print "\n";
692 print_usage(); 684 print_usage();
693 print "\n"; 685 print "\n";
694 print " Checks the number of messages in the mail queue (supports multiple sendmail queues, qmail)\n"; 686 print " Checks the number of messages in the mail queue (supports multiple sendmail queues, qmail)\n";
695 print " Feedback/patches to support non-sendmail mailqueue welcome\n\n"; 687 print " Feedback/patches to support non-sendmail mailqueue welcome\n\n";
696 print "-w (--warning) = Min. number of messages in queue to generate warning\n"; 688 print "-w (--warning) = Min. number of messages in queue to generate warning\n";
697 print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n"; 689 print "-c (--critical) = Min. number of messages in queue to generate critical alert ( w < c )\n";
698 print "-W (--warning-domain) = Min. number of messages for same domain in queue to generate warning\n"; 690 print "-W (--warning-domain) = Min. number of messages for same domain in queue to generate warning\n";
699 print "-C (--critical-domain) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n"; 691 print "-C (--critical-domain) = Min. number of messages for same domain in queue to generate critical alert ( W < C )\n";
700 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; 692 print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n";
701 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n"; 693 print "-M (--mailserver) = [ sendmail | qmail | postfix | exim | nullmailer ] (default = autodetect)\n";
702 print "-s (--sudo) = Use sudo to call the mailq command\n"; 694 print "-s (--sudo) = Use sudo to call the mailq command\n";
703 print "-d (--configdir) = Config file or directory\n"; 695 print "-d (--configdir) = Config file or directory\n";
704 print "-h (--help)\n"; 696 print "-h (--help)\n";
705 print "-V (--version)\n"; 697 print "-V (--version)\n";
706 print "-v (--verbose) = debugging output\n"; 698 print "-v (--verbose) = debugging output\n";
707 print "\n\n"; 699 print "\n\n";
708 print "Note: -w and -c are required arguments. -W and -C are optional.\n"; 700 print "Note: -w and -c are required arguments. -W and -C are optional.\n";
709 print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n"; 701 print " -W and -C are applied to domains listed on the queues - both FROM and TO. (sendmail)\n";
710 print " -W and -C are applied message not yet preproccessed. (qmail)\n"; 702 print " -W and -C are applied message not yet preproccessed. (qmail)\n";
711 print " This plugin tries to autodetect which mailserver you are running,\n"; 703 print " This plugin tries to autodetect which mailserver you are running,\n";
712 print " you can override the autodetection with -M.\n"; 704 print " you can override the autodetection with -M.\n";
713 print " This plugin uses the system mailq command (sendmail) or qmail-stat (qmail)\n"; 705 print " This plugin uses the system mailq command (sendmail) or qmail-stat (qmail)\n";
714 print " to look at the queues. Mailq can usually only be accessed by root or \n"; 706 print " to look at the queues. Mailq can usually only be accessed by root or \n";
715 print " a TrustedUser. You will have to set appropriate permissions for the plugin to work.\n"; 707 print " a TrustedUser. You will have to set appropriate permissions for the plugin to work.\n";
716 print ""; 708 print "";
717 print "\n\n"; 709 print "\n\n";
718 support(); 710 support();
719} 711}
diff --git a/plugins-scripts/check_oracle.sh b/plugins-scripts/check_oracle.sh
index 59981386..db824bef 100755
--- a/plugins-scripts/check_oracle.sh
+++ b/plugins-scripts/check_oracle.sh
@@ -47,7 +47,7 @@ print_help() {
47 echo "--cache" 47 echo "--cache"
48 echo " Check local database for library and buffer cache hit ratios" 48 echo " Check local database for library and buffer cache hit ratios"
49 echo " ---> Requires Oracle user/password and SID specified." 49 echo " ---> Requires Oracle user/password and SID specified."
50 echo " ---> Requires select on v_$sysstat and v_$librarycache" 50 echo " ---> Requires select on v_\$sysstat and v_\$librarycache"
51 echo "--tablespace" 51 echo "--tablespace"
52 echo " Check local database for tablespace capacity in ORACLE_SID" 52 echo " Check local database for tablespace capacity in ORACLE_SID"
53 echo " ---> Requires Oracle user/password specified." 53 echo " ---> Requires Oracle user/password specified."
@@ -109,14 +109,14 @@ if [ -z "$ORACLE_HOME" ] ; then
109 for oratab in /var/opt/oracle/oratab /etc/oratab 109 for oratab in /var/opt/oracle/oratab /etc/oratab
110 do 110 do
111 [ ! -f $oratab ] && continue 111 [ ! -f $oratab ] && continue
112 ORACLE_HOME=`IFS=: 112 ORACLE_HOME=$(IFS=:
113 while read -r SID ORACLE_HOME junk; 113 while read -r SID ORACLE_HOME _;
114 do 114 do
115 if [ "$SID" = "$2" ] || [ "$SID" = "*" ] ; then 115 if [ "$SID" = "$2" ] || [ "$SID" = "*" ] ; then
116 echo "$ORACLE_HOME"; 116 echo "$ORACLE_HOME";
117 exit; 117 exit;
118 fi; 118 fi;
119 done < $oratab` 119 done < $oratab)
120 [ -n "$ORACLE_HOME" ] && break 120 [ -n "$ORACLE_HOME" ] && break
121 done 121 done
122fi 122fi
@@ -209,7 +209,7 @@ case "$cmd" in
209 echo "UNKNOWN - Warning level is less then Crit" 209 echo "UNKNOWN - Warning level is less then Crit"
210 exit "$STATE_UNKNOWN" 210 exit "$STATE_UNKNOWN"
211 fi 211 fi
212 result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF 212 result=$(sqlplus -s "${3}"/"${4}"@"${2}" << EOF
213set pagesize 0 213set pagesize 0
214set numf '9999999.99' 214set numf '9999999.99'
215select (1-(pr.value/(dbg.value+cg.value)))*100 215select (1-(pr.value/(dbg.value+cg.value)))*100
@@ -217,7 +217,8 @@ from v\\$sysstat pr, v\\$sysstat dbg, v\\$sysstat cg
217where pr.name='physical reads' 217where pr.name='physical reads'
218and dbg.name='db block gets' 218and dbg.name='db block gets'
219and cg.name='consistent gets'; 219and cg.name='consistent gets';
220EOF` 220EOF
221)
221 222
222 if echo "$result" | grep -q 'ORA-' ; then 223 if echo "$result" | grep -q 'ORA-' ; then
223 error=$(echo "$result" | grep "ORA-" | head -1) 224 error=$(echo "$result" | grep "ORA-" | head -1)
@@ -227,12 +228,13 @@ EOF`
227 228
228 buf_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}') 229 buf_hr=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print int($1)}')
229 buf_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}') 230 buf_hrx=$(echo "$result" | awk '/^[0-9\. \t]+$/ {print $1}')
230 result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF 231 result=$(sqlplus -s "${3}"/"${4}"@"${2}" << EOF
231set pagesize 0 232set pagesize 0
232set numf '9999999.99' 233set numf '9999999.99'
233select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 234select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100
234from v\\$librarycache lc; 235from v\\$librarycache lc;
235EOF` 236EOF
237)
236 238
237 if echo "$result" | grep -q 'ORA-' ; then 239 if echo "$result" | grep -q 'ORA-' ; then
238 error=$(echo "$result" | grep "ORA-" | head -1) 240 error=$(echo "$result" | grep "ORA-" | head -1)
@@ -260,7 +262,7 @@ EOF`
260 echo "UNKNOWN - Warning level is more then Crit" 262 echo "UNKNOWN - Warning level is more then Crit"
261 exit "$STATE_UNKNOWN" 263 exit "$STATE_UNKNOWN"
262 fi 264 fi
263 result=`sqlplus -s "${3}"/"${4}"@"${2}" << EOF 265 result=$(sqlplus -s "${3}"/"${4}"@"${2}" << EOF
264set pagesize 0 266set pagesize 0
265set numf '9999999.99' 267set numf '9999999.99'
266select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc 268select NVL(b.free,0.0),a.total,100 - trunc(NVL(b.free,0.0)/a.total * 1000) / 10 prc
@@ -271,7 +273,8 @@ LEFT OUTER JOIN
271( select tablespace_name,sum(bytes)/1024/1024 free 273( select tablespace_name,sum(bytes)/1024/1024 free
272from dba_free_space group by tablespace_name) B 274from dba_free_space group by tablespace_name) B
273ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}'; 275ON a.tablespace_name=b.tablespace_name WHERE a.tablespace_name='${5}';
274EOF` 276EOF
277)
275 278
276 if echo "$result" | grep -q 'ORA-' ; then 279 if echo "$result" | grep -q 'ORA-' ; then
277 error=$(echo "$result" | grep "ORA-" | head -1) 280 error=$(echo "$result" | grep "ORA-" | head -1)