This file is indexed.

/usr/share/munin/plugins/exim_mailstats is in munin-node 1.4.6-3ubuntu3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/perl -w
# -*- perl -*-
# vim:syntax=perl

=head1 NAME

exim_mailstats - Plugin to monitor the number of mails received and
delivered by exim.

=head1 APPLICABLE SYSTEMS

Exim version 3 or 4.

=head1 CONFIGURATION

Usually no configuration is needed for this plugin.

  [exim*]
     env.logdir   /path/to/exim-logs/
     env.logname  mainlog
     env.exim     /usr/sbin/exim

The default value for the C<logdir> variable is determined by running
C<exim -bP log_file_path>.  C<mainlog> is the default name given to
exims main log, but it has been known to be called "main.log" in some
versions of Red Hat/Fedora for example.

NOTE: If you need to set logname you must also set logdir as there is
no automatic way to determine the path then.

The default value of the C<exim> variable is C</usr/sbin/exim>, but if
there is a executable called C</usr/sbin/exim4> this is used instead.

=head1 INTERPRETATION

Need some input from an exim postmaster here.

=head1 MAGIC MARKERS

  #%# family=auto
  #%# capabilities=autoconf

=head1 BUGS

None known

=head1 VERSION

  $Id: exim_mailstats.in 4101 2011-01-14 15:26:21Z jo $

=head1 AUTHOR

Copyright (C) 2000-2009 Torstein Svendsen, Henrik Grindal Bakken,
Jimmy Olsen, Nicolai Langfeldt and others.

Torstein Svendsen recalls originally writing this with Henrik Grindal
Bakken to create MRTG graphs of exims mailqueues for Linpros client
RunBox.  Thus this code predates Munin itself.

The first traces of the plugin in CVS seems to be in 2002.  Further
messing by Jimmy Olsen the same year.  Bugfixing and cleanup by
Nicolai Langfeldt 2008.

=head1 LICENSE

GPLv2

=cut

# In most installations the "use lib" can be removed as the Munin
# modules are installed in perls module path.

use strict;
use lib $ENV{'MUNIN_LIBDIR'};
use Munin::Plugin;

##########

sub get_exim_logfile
{
    my ($spec, $type, $time) = @_;
    chomp($spec);
    $time ||= time();
    my $logfile = $spec;
    $logfile =~ s/^log_file_path = //;
    $logfile =~ s/\%s/$type/;

    if ($logfile =~ /\%D/) {
        my @t = localtime($time);
        my $ts = sprintf("%04d%02d%02d", $t[5] + 1900, $t[4] + 1, $t[3]);
        $logfile =~ s/\%D/$ts/g;
    }
    my @lfiles = split(/\s?:\s?/, $logfile);
    foreach (@lfiles) {
        return $_ unless /^syslog/;
    }
    return;
}


my ($pos, $received, $completed, $rejected);

sub parseEximfile
{
    my ($fname, $start) = @_;

    my ($LOGFILE, $rotated) = tail_open($fname, $start);

    if ($rotated || $received eq 'U') {
        # Reset everything if the log has been rotated or we've just initialised
        $pos = $received = $completed = $rejected = 0;
    }

    while (<$LOGFILE>) {
        chomp;

        if (/ <= /) {
            $received++;
        }
        elsif (m/ Completed$/) {
            $completed++;
        }
        elsif (/ rejected /) {
            $rejected++;
        }
    }
    return tail_close($LOGFILE);
}


my $EXIM = "/usr/sbin/exim";

$EXIM = "/usr/sbin/exim4" if (-x "/usr/sbin/exim4");    # a Debianism
$EXIM = $ENV{'exim'}      if defined $ENV{'exim'};

my $LOGDIR  = $ENV{'logdir'}  || undef;
my $LOGNAME = $ENV{'logname'} || '';

my $logfile;

if ($ARGV[0] and $ARGV[0] eq "autoconf") {
    if (defined($LOGDIR)) {
        if (! -d $LOGDIR) {
            print "no (logdir does not exist)\n";
            exit 0;
        }
        $logfile = $LOGDIR . '/' . ($LOGNAME || 'mainlog');
    }
    else {
        my $logfilespec = `$EXIM -bP log_file_path 2>/dev/null`;

        if ($? == 0) {
            $logfile = get_exim_logfile($logfilespec, 'main');
            if (!defined($logfile)) {
                print "no (not able to parse output of '$EXIM -bP log_file_path' = '$logfilespec')\n";
                exit 0;
            }
        }
        elsif ($? == 127) {
            print "no (exim not found)\n";
            exit 0;
        }
        else {
            print "no ('$EXIM -bP log_file_path' returned an error)\n";
            exit 0;
        }
    }

    if ($logfile) {
        if (-r "$logfile") {
            print "yes\n";
        }
        else {
            print "no (logfile '$logfile' not readable)\n";
        }
    }

    exit 0;
}


my $logfilespec;

if (defined($LOGDIR)) {
    $logfilespec = '';
    $logfile = $LOGDIR . '/' . ($LOGNAME || 'mainlog');
}
else {
    $logfilespec = `$EXIM -bP log_file_path 2>/dev/null`;
    $logfile = get_exim_logfile($logfilespec, 'main');
}

die "Logfile '$logfile' is not readable\n" unless -r $logfile;

if ($ARGV[0] and $ARGV[0] eq "config") {
    print "graph_title Exim mail throughput\n";
    print "graph_args --base 1000 -l 0\n";
    print "graph_vlabel mails/\${graph_period}\n";
    print "graph_scale  no\n";
    print "graph_category exim\n";
    print "received.label received\n";
    print "received.type DERIVE\n";
    print "received.min 0\n";
    print "received.draw AREA\n";
    print "completed.label completed\n";
    print "completed.type DERIVE\n";
    print "completed.min 0\n";
    print "rejected.label rejected\n";
    print "rejected.type DERIVE\n";
    print "rejected.min 0\n";
    exit 0;
}

($pos, $received, $completed, $rejected) = restore_state();

if (! defined $pos) {
    # No state file present.  Avoid startup spike: Do not read log
    # file up to now, but remember how large it is now, and next
    # time read from there.
    $pos = (stat $logfile)[7];  # File size
    $received = $completed = $rejected = 'U';
}
else {
    $pos = parseEximfile($logfile, $pos);
}

print "received.value $received\n";
print "completed.value $completed\n";
print "rejected.value $rejected\n";

save_state($pos, $received, $completed, $rejected);