This file is indexed.

/usr/share/munin/plugins/mailman is in munin-plugins-extra 2.0.6-4+deb7u2.

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
#!/usr/bin/perl
# -*- perl -*-

=head1 NAME

mailman - Plugin to monitor activity on mailman mailing list
management systems

=head1 CONFIGURATION

No configuration

=head1 AUTHOR

Author unknown.  Source code strongly related to the Exim plugin of old.

=head1 LICENSE

License unknown

=head1 MAGIC MARKERS

 #%# family=contrib

=cut

$statefile = "$ENV{MUNIN_PLUGSTATE}/munin-mailman-log.state";
$pos = undef;
$posts = 0;
$members = 0;

# System paths (as known to mailman-limacute
$logfile = "/var/log/mailman/post";
$libdir  = "/var/lib/mailman";
$lister  = "/usr/lib/mailman/bin/list_members";

if (-f "$logfile.0")
{
    $rotlogfile = $logfile . ".0";
}
elsif (-f "$logfile.1")
{
    $rotlogfile = $logfile . ".1";
}
elsif (-f "$logfile.01")
{
    $rotlogfile = $logfile . ".01";
}
else
{
    $rotlogfile = $logfile . ".0";
}

if($ARGV[0] and $ARGV[0] eq "config") {
    print "graph_title Mailman usage\n";
    print "graph_args --base 1000\n";
    print "posts.label posts per minute\n";
    print "posts.type DERIVE\n";
    print "posts.min 0\n";
    print "members.label members\n";
    print "members.type GAUGE\n";
    exit 0;
}

if(! -f $logfile &&
   ! -d $libdir &&
   ! -x $lister &&
   ! -f $rotlogfile) {
    print "posts.value U\n";
    print "posts.extinfo Can't find any log files\n";
    print "members.value U\n";
    exit 0;
}

if(-f $statefile) {
    open(IN, "<$statefile") or die "Can't open $statefile for reading: $!";
    if(<IN> =~ /^(\d+):(\d+)/) {
	($pos,$posts) = ($1, $2);
    }
    close(IN);
}

$startsize = (stat $logfile)[7];

if(!defined $pos) {
    # Initial run.
    $pos = $startsize;
    $startsize = 0;
} elsif($startsize < $pos) {
    # Log rotated
    parseMailmanLog($rotlogfile, $pos, (stat $rotlogfile)[7]);
    $pos = 0;
}

parseMailmanLog($logfile, $pos, $startsize);
$pos = $startsize;

parseMailmanLists();

print "posts.value $posts\n";
print "members.value $members\n";

open (OUT, ">$statefile") or die "Can't open $statefile for writing: $!";
print OUT "$pos:$posts\n";
close OUT;

sub parseMailmanLog {
    my($fname, $start, $stop) = @_;
    open(LOGFILE, $fname) or die "Can't open $fname for reading: $!";
    seek(LOGFILE, $start, 0) or die "Can't seek in $fname: $!";
    while(tell(LOGFILE) < $stop) {
	my $line = <LOGFILE>;
	if($line =~ / post to/) {
	    $posts++;
	}
    }
    close(LOGFILE);
}

sub parseMailmanLists {
    my @domains = &mailmanDomains;
    for(my $i = 0; $i < @domains; $i++) {
        my @lists = &mailmanLists($domains[$i]);
        for(my $j = 0; $j < @lists; $j++) {
            $members += &mailmanMembers($domains[$i], $lists[$j]);
        }
    }
}

sub mailmanDomains {
    my @domains;
    if (-e "$libdir/data") {
	@domains = (".");
    } else {
	opendir(DOMAINS, $libdir) or 
	    die "Can't open directory $libdir for reading: $!";
	@domains = grep ( { !/^\@/ && !/^\./ && -d "$libdir/$_" }
			  readdir(DOMAINS) );
	closedir(DOMAINS);
    }
    return @domains;
}

sub mailmanLists {
    my ($domain) = @_;
    opendir(LISTS, "$libdir/$domain/lists") or
	die "Can't open directory $libdir/$domain/lists for reading: $!";
    my @lists = grep ( { !/^\@/ && !/^\./ && -d "$libdir/$domain/lists/$_" } 
		       readdir(LISTS) );
    closedir(LISTS);
    return @lists;
}

sub mailmanMembers {
    my ($domain, $list) = @_;
    return 0 unless $domain;
    return 0 unless $list;
    my $cnt = 0;
    open(MEMBERS, "DOMAIN=$domain $lister $list|") or
	die "Cannot execute pipe: $lister $list: $!";
    while(<MEMBERS>) {
        $cnt++;
    }
    close(MEMBERS);
    return $cnt;
}

# vim:syntax=perl