aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SENDMAIL-STATS.txt19
-rw-r--r--sendmail.pl261
2 files changed, 276 insertions, 4 deletions
diff --git a/SENDMAIL-STATS.txt b/SENDMAIL-STATS.txt
index 7761e42..72b24e7 100644
--- a/SENDMAIL-STATS.txt
+++ b/SENDMAIL-STATS.txt
@@ -36,6 +36,12 @@ queueTotal OBJECT-TYPE
::= { queue 1 }
QueueNameString ::= TEXTUAL-CONVENTION
+ DISPLAY-HINT "128t"
+ STATUS current
+ DESCRIPTION "A string containing Sendmail queue name."
+ SYNTAX OCTET STRING (SIZE (0..128))
+
+QueuePathString ::= TEXTUAL-CONVENTION
DISPLAY-HINT "1024t"
STATUS current
DESCRIPTION "A string representing Sendmail queue directory."
@@ -44,6 +50,7 @@ QueueNameString ::= TEXTUAL-CONVENTION
QueueEntry ::= SEQUENCE {
queueIndex Index32,
queueName QueueNameString,
+ queueDirectory QueuePathString,
queueMessages Counter64
}
@@ -77,16 +84,24 @@ queueName OBJECT-TYPE
MAX-ACCESS read-only
STATUS current
DESCRIPTION
- "The name of the mailer."
+ "The name of the queue."
::= { queueEntry 2 }
+queueDirectory OBJECT-TYPE
+ SYNTAX QueuePathString
+ MAX-ACCESS read-only
+ STATUS current
+ DESCRIPTION
+ "Queue directory."
+ ::= { queueEntry 3 }
+
queueMessages OBJECT-TYPE
SYNTAX Counter64
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Number of messages in the queue."
- ::= { queueEntry 3 }
+ ::= { queueEntry 4 }
MailerNameString ::= TEXTUAL-CONVENTION
DISPLAY-HINT "128t"
diff --git a/sendmail.pl b/sendmail.pl
index 8cc6c65..2249ee8 100644
--- a/sendmail.pl
+++ b/sendmail.pl
@@ -14,6 +14,206 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+=head1 NAME
+
+NetSNMP::Sendmail - NetSNMP plugin for Sendmail statistics
+
+=head1 SYNOPSIS
+
+B<perl use NetSNMP::Sendmail qw (:config bindir /usr/bin/sm.bin);>
+
+=head1 DESCRIPTION
+
+A perl plugin for B<net-snmp> that provides access to Sendmail
+statistics information obtained by B<mailq> and B<mailstats>.
+
+In most cases adding
+
+ perl use NetSNMP::Sendmail;
+
+to B<snmpd.conf>(5) is enough to get the plugin working. You may
+however need to tune it. For example, Debian-based distributions
+override default Sendmail binaries with homemade scripts that have
+somewhat different output format, which can confuse this module. The
+binaries are then located in the F</usr/lib/sm.bin> directory. To have
+the plugin use the right binaries, load it as follows:
+
+ perl use NetSNMP::Sendmail qw(:config bindir /usr/lib/sm.bin);
+
+Another way to do so would be to export the B<Configure> method and
+call it right after requiring the module:
+
+ perl use NetSNMP::Sendmail qw(Configure);
+ perl NetSNMP::Sendmail::Configure(bindir => '/usr/lib/sm.bin');
+
+In general, configuration options and corresponding values are either
+passed as a hash to the B<Configure> function, or passed with the
+B<use> statement following the B<:config> marker. The following
+options are defined:
+
+=over 4
+
+=item B<bindir>
+
+Directory where to look for B<mailq> and B<mailstats>. It is unset by
+default, which means that both binaries will be looked up using the
+B<PATH> environment variable, unless they are set to absolute pathname
+using B<mailq> and B<mailstats> keywords.
+
+=item B<cf>
+
+Absolute name of the Sendmail configuaration file. Defaults to
+F</etc/mail/sendmail.cf>.
+
+=item B<mailstats>
+
+Name of the B<mailstats> binary. Default is B<mailstats>.
+
+=item B<mailq>
+
+Name of the B<mailq> binary. Default is B<mailq>.
+
+=item B<mailstats_ttl>
+
+Time in seconds during which the result of the recent invocation of
+B<mailstats>(8) is cached. Default is 10.
+
+=item B<mailq_ttl>
+
+Time in seconds during which the result of the recent invocation of
+B<mailq>(1) is cached. Default is 10.
+
+=back
+
+=head2 OIDS
+
+The MIB is defined in file SENDMAIL-STATS.txt, which is distributed along
+with this module. The following OIDs are defined:
+
+=over 4
+
+=item B<queueTotal.0>
+
+Total number of messages in the queue.
+
+=item B<queueTable>
+
+This OID provides a conceptual table of Sendmail queue groups. Each row has
+the following elements (I<N> stands for the row index):
+
+=over 4
+
+=item B<queueName.>I<N>
+
+Name of the queue group.
+
+=item B<queueDirectory.>I<N>
+
+Queue directory.
+
+=item B<queueMessages.>I<N>
+
+Number of messages in that queue group.
+
+=back
+
+=item B<mailerTable>
+
+This OID provides a conceptual table of mailers with the corresponding
+statistics. Each row has the following elements (I<N> stands for the
+row index):
+
+=over 4
+
+=item B<mailerName.>I<N>
+
+Name of the mailer, as set in its definition in F<sendmail.cf>.
+
+=item B<mailerMessagesFrom.>I<N>
+
+Number of outgoing messages sent using this mailer.
+
+=item B<mailerKBytesFrom.>I<N>
+
+Number of kilobytes in outgoing messages sent using this mailer.
+
+=item B<mailerMessagesTo.>I<N>
+
+Number of messages received using this mailer.
+
+=item B<mailerKBytesTo.>I<N>
+
+Number of kilobytes in messages received using this mailer.
+
+=item B<mailerMessagesRejected.>I<N>
+
+Number of messages rejected by this mailer.
+
+=item B<mailerMessagesDiscarded.>I<N>
+
+Number of messages discarded by this mailer.
+
+=item B<mailerMessagesQuarantined.>I<N>
+
+Number of messages put in quarantine by this mailer.
+
+=back
+
+
+=item B<totalMessagesFrom.0>
+
+Total number of outgoing messages.
+
+=item B<totalKBytesFrom.0>
+
+Total number of outgoing kilobytes.
+
+=item B<totalMessagesTo.0>
+
+Total number of incoming messages.
+
+=item B<totalKBytesTo.0>
+
+Total number of incoming kilobytes.
+
+=item B<totalMessagesRejected.0>
+
+Total number of rejected messages.
+
+=item B<totalMessagesDiscarded.0>
+
+Total number of discarded messages.
+
+=item B<totalMessagesQuarantined.0>
+
+Total number of messages put in quarantine.
+
+=item B<connectionMessagesFrom.0>
+
+Number of messages sent over TCP connections.
+
+=item B<connectionMessagesTo.0>
+
+Number of messages received over TCP connections.
+
+=item B<connectionMessagesRejected.0>
+
+Number of messages that arrived over TCP connections and were rejected.
+
+=back
+
+=head1 SEE ALSO
+
+B<snmpd.conf>(5), B<snmpd>(8), B<mailq>(1), B<mailstats>(8).
+
+=head1 AUTHOR
+
+Sergey Poznyakoff <gray@gnu.org>.
+
+=cut
+
+
+
package NetSNMP::Sendmail;
require 5.10.0;
use strict;
@@ -32,6 +232,7 @@ our $VERSION = "0.91";
our @EXPORT_OK = qw(&Configure);
+my $sendmail_cf = '/etc/mail/sendmail.cf';
my $mailq_bin = 'mailq';
my $mailstats_bin = 'mailstats';
@@ -45,6 +246,7 @@ my %config = (
mailstats_ttl => \$ttl{mailstats},
mailq => \$mailq_bin,
mailstats => \$mailstats_bin,
+ cf => \$sendmail_cf,
bindir => sub {
$mailq_bin = "$_[1]/$mailq_bin" if $mailq_bin !~ m#^/#;
$mailstats_bin = "$_[1]/$mailstats_bin" if $mailstats_bin !~ m#^/#;
@@ -87,6 +289,57 @@ sub import {
Configure(@config) if @config;
}
+my %qgroup;
+my $qdir;
+
+my %qopt = ( F => 'queueFlags',
+ N => 'queueNice',
+ I => 'queueInterval',
+ P => 'queueDirectory',
+ R => 'queueRunners',
+ J => 'queueJobs',
+ r => 'queueMaxRecipients' );
+
+sub readcf {
+ open(my $fd, '<', $sendmail_cf)
+ or do {
+ warn "can't open $sendmail_cf: $!";
+ return;
+ };
+ while (<$fd>) {
+ chomp;
+ next if /^#/;
+ if (/^O\s+QueueDirectory=(.+)/) {
+ # O QueueDirectory=/var/spool/mqueue
+ $qdir = $1;
+ } elsif (/^Q([^,]+),\s+(.+)/) {
+ # Qlocal, P=/var/spool/mqueue/local, F=f, R=2, I=1m
+ my $name = $1;
+ # Collect parameters. So far only P is actially used.
+ my %h = map { if (/([a-zA-Z])[^=]*=(.+)/) {
+ if (exists($qopt{$1})) {
+ $qopt{$1} => $2;
+ } else {
+ ()
+ }
+ } else {
+ ()
+ }
+ } split /,\s*/, $2;
+ if (exists($h{queueDirectory})) {
+ my $dir = $h{queueDirectory};
+ delete $h{$dir};
+ $h{queueName} = $name;
+ $qgroup{$dir} = \%h;
+ }
+ }
+ }
+ close($fd);
+}
+
+# Read Sendmail configuration
+readcf();
+
my %timestamp;
sub queue_stats {
@@ -103,9 +356,13 @@ sub queue_stats {
while (<$fd>) {
chomp;
if (/^(^\S+) is empty/) {
- push @{$tmp{q}}, { queueName => $1, queueMessages => 0 };
+ push @{$tmp{q}}, { queueName => $qgroup{$1}{queueName} || "",
+ queueDirectory => $1,
+ queueMessages => 0 };
} elsif (/^\s*(\S+) \((\d+) requests\)/) {
- push @{$tmp{q}}, { queueName => $1, queueMessages => $2 };
+ push @{$tmp{q}}, { queueName => $qgroup{$1}{queueName} || "",
+ queueDirectory => $1,
+ queueMessages => $2 };
} elsif (/Total requests:\s+(\d+)\s*$/) {
$tmp{total} = $1
}

Return to:

Send suggestions and report system problems to the System administrator.