root / plugins / mail / sendmail_mailq @ 31412baa
Historique | Voir | Annoter | Télécharger (4,33 ko)
| 1 | c81b798b | Jose-Marcio Martins da Cruz | #! @@PERL@@ -w |
|---|---|---|---|
| 2 | # -*- perl -*- |
||
| 3 | |||
| 4 | =head1 NAME |
||
| 5 | |||
| 6 | sendmail_mailq |
||
| 7 | |||
| 8 | =head1 APPLICABLE SYSTEMS |
||
| 9 | |||
| 10 | Systems running sendmail as MTA |
||
| 11 | |||
| 12 | =head1 CONFIGURATION |
||
| 13 | |||
| 14 | [sendmail_mailq] |
||
| 15 | # shall run as root in order to get access to sendmail queues |
||
| 16 | user root |
||
| 17 | |||
| 18 | # warning and critical thresholds |
||
| 19 | env.warning 200 |
||
| 20 | env.critical 300 |
||
| 21 | |||
| 22 | # include total and/or detail of MTA queues |
||
| 23 | # rem : mtatotal is changed to "yes" if both are "no" |
||
| 24 | # in case of just one queue only one is shown |
||
| 25 | env.mtatotal yes |
||
| 26 | env.mtadetail yes |
||
| 27 | |||
| 28 | # include total and/or detail of MSP queues |
||
| 29 | # rem : mtatotal is changed to "yes" if both are "no" |
||
| 30 | # in case of just one queue only one is shown |
||
| 31 | env.msptotal yes |
||
| 32 | env.mspdetail yes |
||
| 33 | |||
| 34 | =head1 BUGS/GOTCHAS |
||
| 35 | |||
| 36 | |||
| 37 | If you find one, drop a message to the author |
||
| 38 | |||
| 39 | * The autoconfiguration returns yes if it finds both sendmail |
||
| 40 | mailq and sendmail.cf configuration files. This may be wrong |
||
| 41 | if the system has both postfix and sendmail installed but the |
||
| 42 | enabled MTA is postfix. |
||
| 43 | |||
| 44 | =head1 AUTHOR |
||
| 45 | |||
| 46 | Jose-Marcio Martins da Cruz - mailto:Jose-Marcio.Martins@mines-paristech.fr |
||
| 47 | Ecole Nationale Superieure des Mines de Paris |
||
| 48 | |||
| 49 | =head1 VERSION |
||
| 50 | |||
| 51 | 1.0 - Jan, 04, 2014 |
||
| 52 | |||
| 53 | =head1 LICENSE |
||
| 54 | |||
| 55 | GPLv2 |
||
| 56 | |||
| 57 | =head1 MAGIC MARKERS |
||
| 58 | |||
| 59 | #%# family=contrib |
||
| 60 | #%# capabilities=autoconf |
||
| 61 | |||
| 62 | =cut |
||
| 63 | |||
| 64 | use strict; |
||
| 65 | use warnings; |
||
| 66 | |||
| 67 | my $MAILQ = "mailq"; |
||
| 68 | my $SMCF = "/etc/mail/sendmail.cf"; |
||
| 69 | |||
| 70 | my %EnvConf = ( |
||
| 71 | 'warning' => defined $ENV{'warning'} ? $ENV{'warning'} : '200',
|
||
| 72 | 'critical' => defined $ENV{'critical'} ? $ENV{'critical'} : '300'
|
||
| 73 | ); |
||
| 74 | foreach my $k (qw(mtatotal mtadetail msptotal mspdetail)) {
|
||
| 75 | if (exists $ENV{$k}) {
|
||
| 76 | $EnvConf{$k} = $ENV{$k} =~ /^(yes|true|oui|vrai|1)$/i;
|
||
| 77 | } else {
|
||
| 78 | $EnvConf{$k} = 1;
|
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | if ($#ARGV >= 0 && $ARGV[0] eq "autoconf") {
|
||
| 83 | unless (-f $SMCF) {
|
||
| 84 | print "no\n"; |
||
| 85 | exit 0; |
||
| 86 | } |
||
| 87 | unless (system("$MAILQ > /dev/null 2>&1") == 0) {
|
||
| 88 | print "no\n"; |
||
| 89 | exit 0; |
||
| 90 | } |
||
| 91 | print "yes\n"; |
||
| 92 | exit 0; |
||
| 93 | } |
||
| 94 | |||
| 95 | if ($#ARGV >= 0 && $ARGV[0] eq "config") {
|
||
| 96 | my %MTAQueue = (); |
||
| 97 | my %MSPQueue = (); |
||
| 98 | |||
| 99 | GetQueue(\%MTAQueue, "", $EnvConf{mtadetail}, $EnvConf{mtatotal});
|
||
| 100 | GetQueue(\%MSPQueue, "-Ac", $EnvConf{mspdetail}, $EnvConf{msptotal});
|
||
| 101 | |||
| 102 | print <<EOT; |
||
| 103 | graph_title sendmail queue size |
||
| 104 | e00bd6b8 | Gabriele Pohl | graph_category mail |
| 105 | c81b798b | Jose-Marcio Martins da Cruz | graph_vlabel messages |
| 106 | graph_scale no |
||
| 107 | EOT |
||
| 108 | my @ord = qw(); |
||
| 109 | push @ord, sort grep {$_ = "mta_" . $_;} keys %MTAQueue;
|
||
| 110 | push @ord, sort grep {$_ = "msp_" . $_;} keys %MSPQueue;
|
||
| 111 | printf "graph_order %s\n", join " ", @ord; |
||
| 112 | foreach my $k (sort keys %MTAQueue) {
|
||
| 113 | printf "mta_%s.label MTA %s\n", $k, $MTAQueue{$k}{name};
|
||
| 114 | printf "mta_%s.warning %d\n", $k, $EnvConf{warning};
|
||
| 115 | printf "mta_%s.critical %d\n", $k, $EnvConf{critical};
|
||
| 116 | } |
||
| 117 | foreach my $k (sort keys %MSPQueue) {
|
||
| 118 | printf "msp_%s.label MSP %s\n", $k, $MSPQueue{$k}{name};
|
||
| 119 | printf "msp_%s.warning %d\n", $k, $EnvConf{warning};
|
||
| 120 | printf "msp_%s.critical %d\n", $k, $EnvConf{critical};
|
||
| 121 | } |
||
| 122 | exit 0; |
||
| 123 | } |
||
| 124 | |||
| 125 | if ($#ARGV < 0) {
|
||
| 126 | my %MTAQueue = (); |
||
| 127 | my %MSPQueue = (); |
||
| 128 | |||
| 129 | GetQueue(\%MTAQueue, "", $EnvConf{mtadetail}, $EnvConf{mtatotal});
|
||
| 130 | foreach my $k (sort keys %MTAQueue) {
|
||
| 131 | printf "mta_%s.value %d\n", $k, $MTAQueue{$k}{value};
|
||
| 132 | } |
||
| 133 | GetQueue(\%MSPQueue, "-Ac", $EnvConf{mspdetail}, $EnvConf{msptotal});
|
||
| 134 | foreach my $k (sort keys %MSPQueue) {
|
||
| 135 | printf "msp_%s.value %d\n", $k, $MSPQueue{$k}{value};
|
||
| 136 | } |
||
| 137 | exit 0; |
||
| 138 | } |
||
| 139 | |||
| 140 | exit 1; |
||
| 141 | |||
| 142 | sub GetQueue {
|
||
| 143 | my ($h, $opt, $detail, $total, undef) = @_; |
||
| 144 | my @QUEUE = `$MAILQ $opt 2>/dev/null`; |
||
| 145 | my $totsz = 0; |
||
| 146 | my $ndetail = 0; |
||
| 147 | foreach my $qline (@QUEUE) {
|
||
| 148 | if ($qline =~ /^\s*(\S+)\s+\((\d+)\s+request.*\)/) {
|
||
| 149 | $ndetail++; |
||
| 150 | if ($detail || !$total) {
|
||
| 151 | my ($field, $name) = QueueName($1); |
||
| 152 | $h->{$field}{name} = $name;
|
||
| 153 | $h->{$field}{value} = $2;
|
||
| 154 | $totsz += $2; |
||
| 155 | } |
||
| 156 | next; |
||
| 157 | } |
||
| 158 | if ($qline =~ /^\s*(\S+)\s+is\s+empty/) {
|
||
| 159 | $ndetail++; |
||
| 160 | if ($detail || !$total) {
|
||
| 161 | my ($field, $name) = QueueName($1); |
||
| 162 | $h->{$field}{name} = $name;
|
||
| 163 | $h->{$field}{value} = 0;
|
||
| 164 | } |
||
| 165 | next; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | if ($total && $ndetail > 1) {
|
||
| 169 | $h->{zztotal}{name} = "=== Total ===";
|
||
| 170 | $h->{zztotal}{value} = $totsz;
|
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | sub QueueName {
|
||
| 175 | my ($q, undef) = @_; |
||
| 176 | my ($field, $name) = (undef, undef); |
||
| 177 | $name = `basename $q`; |
||
| 178 | chomp $name; |
||
| 179 | $field = $name; |
||
| 180 | $field =~ s/[^A-Za-z0-9_]/_/g; |
||
| 181 | return ($field, $name); |
||
| 182 | } |
