-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexim_snmp_agent
executable file
·60 lines (45 loc) · 1.68 KB
/
exim_snmp_agent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/perl
# exec "sudo", "-u", "exim", $0, @ARGV unless getpwnam($<) eq "exim";
use warnings;
use strict;
use FindBin;
use lib $FindBin::Bin;
require SNMPAgentUtil;
require EximMessageCounters;
SNMPAgentUtil->run(
# log_to => "/dev/tty",
# log_to => "/tmp/exim_snmp_agent.log",
# get => \&get,
# get_next => \&get_next,
prepare_responses => \&prepare_responses,
);
{
my $expire = time;
sub prepare_responses
{
my ($self) = @_;
return if defined($expire) and time() < $expire;
my @responses;
# .1.3.6.1.4.1.204718080 = fake Powernet enterprise
# .3 = exim
# .1 = queue contents
# .1 = count of messages in queue
# .2 = count of bytes in queue (approx)
# .2 = count of messages (senders) accepted to date
# .3 = count of recipients accepted to date
# .4 = count of messages completed to date
push @responses, ".1.3.6.1.4.1.204718080.3", "string", "dummy";
push @responses, ".1.3.6.1.4.1.204718080.3.1", "string", "dummy";
push @responses, ".1.3.6.1.4.1.204718080.3.1.1", "gauge", count_glob("/var/spool/exim/input/*D");
push @responses, ".1.3.6.1.4.1.204718080.3.1.2", "gauge", count_bytes("/var/spool/exim/input");
my ($messages, $recipients, $completed) = get_exim_counters();
push @responses, ".1.3.6.1.4.1.204718080.3.2", "counter", $messages;
push @responses, ".1.3.6.1.4.1.204718080.3.3", "counter", $recipients;
push @responses, ".1.3.6.1.4.1.204718080.3.4", "counter", $completed;
$self->set_responses(@responses);
$expire = time() + 10;
}
}
sub count_glob { my @g = glob $_[0]; return scalar @g }
sub count_bytes { my $dir = $_[0]; my $o = `du --bytes -s $dir`; $o =~ /^(\d+)/; return $1 }
# eof