~ubuntu-branches/ubuntu/gutsy/munin/gutsy

« back to all changes in this revision

Viewing changes to node/node.d/spamstats.in

  • Committer: Bazaar Package Importer
  • Author(s): Tore Anderson
  • Date: 2004-05-21 20:51:19 UTC
  • Revision ID: james.westby@ubuntu.com-20040521205119-oz8bllbjp9hs80ig
Tags: upstream-0+1.0.0pre5
ImportĀ upstreamĀ versionĀ 0+1.0.0pre5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!@@PERL@@
 
2
#
 
3
# $Log: spamstats.in,v $
 
4
# Revision 1.1  2004/01/02 18:50:00  jimmyo
 
5
# Renamed occurrances of lrrd -> munin
 
6
#
 
7
# Revision 1.1.1.1  2004/01/02 15:18:07  jimmyo
 
8
# Import of LRRD CVS tree after renaming to Munin
 
9
#
 
10
# Revision 1.1  2003/11/10 18:51:50  jimmyo
 
11
# Initial entries
 
12
#
 
13
#
 
14
 
 
15
$statefile = $ENV{statefile} || "@@PLUGSTATE@@/munin-spamstats.state";
 
16
$pos   = undef;
 
17
$ham = 0;
 
18
$spam = 0;
 
19
 
 
20
$logfile = $ENV{logdir} || "/var/log/";
 
21
$logfile .= $ENV{logfile} || "syslog";
 
22
 
 
23
if (-f "$logfile.0")
 
24
{
 
25
    $rotlogfile = $logfile . ".0";
 
26
}
 
27
elsif (-f "$logfile.1")
 
28
{
 
29
    $rotlogfile = $logfile . ".1";
 
30
}
 
31
elsif (-f "$logfile.01")
 
32
{
 
33
    $rotlogfile = $logfile . ".01";
 
34
}
 
35
else
 
36
{
 
37
    $rotlogfile = $logfile . ".0";
 
38
}
 
39
 
 
40
if ( $ARGV[0] and $ARGV[0] eq "config" )
 
41
{
 
42
    print "host_name $ENV{FQDN}\n";
 
43
    print "graph_title SpamAssassin throughput\n";
 
44
    print "graph_args --base 1000 -v mails/min -l 0\n";
 
45
    print "graph_order ham spam\n";
 
46
    print "ham.label ham\n";
 
47
    print "ham.type COUNTER\n";
 
48
    print "ham.draw AREA\n";
 
49
    print "ham.cdef ham,60,*\n";
 
50
    print "spam.label spam\n";
 
51
    print "spam.type COUNTER\n";
 
52
    print "spam.cdef spam,60,*\n";
 
53
    print "spam.draw STACK\n";
 
54
    exit 0;
 
55
}
 
56
 
 
57
if (! -f $logfile and ! -f $rotlogfile)
 
58
{
 
59
    print "ham.value U\n";
 
60
    print "spam.value U\n";
 
61
    exit 0;
 
62
}
 
63
 
 
64
if (-f "$statefile")
 
65
{
 
66
    open (IN, "$statefile") or exit 4;
 
67
    if (<IN> =~ /^(\d+):(\d+):(\d+)/)
 
68
    {
 
69
        ($pos, $ham, $spam) = ($1, $2, $3);
 
70
    }
 
71
    close IN;
 
72
}
 
73
 
 
74
$startsize = (stat $logfile)[7];
 
75
 
 
76
if (!defined $pos)
 
77
{
 
78
    # Initial run.
 
79
    $pos = $startsize;
 
80
}
 
81
 
 
82
if ($startsize < $pos)
 
83
{
 
84
    # Log rotated
 
85
    parselogfile ($rotlogfile, $pos, (stat $rotlogfile)[7]);
 
86
    $pos = 0;
 
87
}
 
88
 
 
89
parselogfile ($logfile, $pos, $startsize);
 
90
$pos = $startsize;
 
91
 
 
92
print "ham.value $ham\n";
 
93
print "spam.value $spam\n";
 
94
 
 
95
open (OUT, ">$statefile") or exit 4;
 
96
print OUT "$pos:$ham:$spam\n";
 
97
close OUT;
 
98
 
 
99
sub parselogfile 
 
100
{    
 
101
    my ($fname, $start, $stop) = @_;
 
102
    open (LOGFILE, $fname) or exit 3;
 
103
    seek (LOGFILE, $start, 0) or exit 2;
 
104
 
 
105
    while (tell (LOGFILE) < $stop) 
 
106
    {
 
107
        my $line =<LOGFILE>;
 
108
        chomp ($line);
 
109
 
 
110
        if ($line =~ m/clean message/) 
 
111
        {
 
112
            $ham++;
 
113
        } 
 
114
        elsif ($line =~ m/identified spam/)
 
115
        {
 
116
            $spam++;
 
117
        }
 
118
    }
 
119
    close(LOGFILE);    
 
120
}