|
1 #! /usr/bin/perl -w |
|
2 |
|
3 use strict; |
|
4 use File::Basename; |
|
5 use Getopt::Long; |
|
6 use lib "/usr/lib/nagios/plugins"; |
|
7 use utils qw (%ERRORS &print_revision &support); |
|
8 |
|
9 sub print_help(); |
|
10 sub print_usage(); |
|
11 |
|
12 my $ME = basename $0; |
|
13 my ( $opt_w, $opt_c, $opt_s, $opt_V, $opt_h, $opt_b ); |
|
14 my ( $result, $mailq ); |
|
15 |
|
16 $opt_s = "86400"; |
|
17 $opt_w = "10"; |
|
18 $opt_c = "20"; |
|
19 $opt_b = "/usr/sbin/exipick"; |
|
20 |
|
21 Getopt::Long::Configure('bundling'); |
|
22 GetOptions( |
|
23 "V" => \$opt_V, |
|
24 "version" => \$opt_V, |
|
25 "h" => \$opt_h, |
|
26 "help" => \$opt_h, |
|
27 "b=s" => \$opt_b, |
|
28 "binary" => \$opt_b, |
|
29 "s=i" => \$opt_s, |
|
30 "seconds" => \$opt_s, |
|
31 "w=i" => \$opt_w, |
|
32 "warning=i" => \$opt_w, |
|
33 "c=i" => \$opt_c, |
|
34 "critical=i" => \$opt_c |
|
35 ); |
|
36 |
|
37 if ($opt_V) { |
|
38 print_revision( $ME, "0.1" ); |
|
39 exit $ERRORS{"OK"}; |
|
40 } |
|
41 |
|
42 if ($opt_h) { |
|
43 print_help(); |
|
44 exit $ERRORS{"OK"}; |
|
45 } |
|
46 |
|
47 if ( $opt_w > $opt_c ) { |
|
48 print |
|
49 "MAILQ CRITICAL: Warning (-w) cannot be greater than Critical (-c)!\n"; |
|
50 exit $ERRORS{"CRITICAL"}; |
|
51 } |
|
52 |
|
53 # check exipick binary |
|
54 unless ( -x $opt_b ) { |
|
55 print "MAILQ CRITICAL: exipick not found or not executable - $opt_b\n"; |
|
56 exit $ERRORS{"CRITICAL"}; |
|
57 } |
|
58 |
|
59 # check the mailq |
|
60 `$opt_b -o $opt_s -c` =~ /^(\d+).*/; |
|
61 $mailq = $1; |
|
62 |
|
63 SWITCH: { |
|
64 $mailq < $opt_w and $result = "OK", last; |
|
65 $mailq >= $opt_c and $result = "CRITICAL", last; |
|
66 $mailq >= $opt_w and $result = "WARNING", last; |
|
67 } |
|
68 |
|
69 print |
|
70 "MAILQ $result: ($mailq) queued mails older than $opt_s sec.|unsent=$mailq;$opt_w;$opt_c;0;0\n"; |
|
71 exit $ERRORS{$result}; |
|
72 |
|
73 sub print_usage() { |
|
74 print "Usage:\n"; |
|
75 print " $ME [-b <binary>] [-s <sec>] [-w <warn>] [-c <crit>]\n"; |
|
76 print " $ME [-h | --help]\n"; |
|
77 print " $ME [-V | --version]\n"; |
|
78 } |
|
79 |
|
80 sub print_help() { |
|
81 print_revision( $ME, "0.1" ); |
|
82 print "Copyright (c) 2008 Christian Arnold\n\n"; |
|
83 print "This plugin checks the number of messages, which are longer than\n"; |
|
84 print "an specified time holding in the mail queue.\n\n"; |
|
85 print_usage(); |
|
86 print "\n"; |
|
87 print " -b, --binary <binary>\n"; |
|
88 print " Path of exipick binary (default: /usr/sbin/exipick)\n"; |
|
89 print " -s, --seconds <sec>\n"; |
|
90 print " Age of messages in seconds in the mail queue (default: 86400) one day\n"; |
|
91 print " -w, --warning <warn>\n"; |
|
92 print " Min. number of messages in the mail queue to generate warning alert (default: 10)\n"; |
|
93 print " -c, --critical <crit>\n"; |
|
94 print " Min. number of messages in the mail queue to generate critical alert (default: 20)\n"; |
|
95 print "\n"; |
|
96 print "Note: This plugin only works with exim4.\n\n"; |
|
97 support(); |
|
98 } |