plugins-qmailqueue-virus: qmail_virusba

File qmail_virusba, 1.8 kB (added by jh@byteaction.de, 6 years ago)
Line 
1 #!/usr/bin/perl
2 #
3 # Plugin to count the daily amount of Virii (qmailscan)
4 #
5 # Contributed by Juergen Hoffmann (jh@byteaction.de.de) - 03.02.2006
6 #
7 # This plugin remebers the state of the amount of virii found
8 # and reports the difference instead. Hence showing the scanning performance
9 # by day
10 #
11 #
12 # Magic markers - optional - used by installation scripts and
13 # munin-config:
14 #
15 #%# family=manual
16 #%# capabilities=autoconf
17
18 use strict;
19 require IO::File;
20
21 my $LOGFILE = $ENV{'logfile'} || "/var/spool/excubator/quarantine.log";
22 my $STATEFILE = $ENV{'statefile'} || "/var/lib/munin/plugin-state/plugin-qmail_virusba.state";
23
24 my $date = `date +%d\\ %b\\ %Y`;
25 chomp($date);
26
27 my $collector_command = "zgrep \"$date\" $LOGFILE | wc -l";
28 my $fh = new IO::File;
29
30 if($ARGV[0] eq "autoconf")
31 {
32         if( -e "$LOGFILE" )
33         {
34                 print "yes\n";
35         }
36         else
37         {
38                 print "$LOGFILE not found\n";
39         }
40 }
41
42 if($ARGV[0] eq "config")
43 {
44         print 'graph_title Virus Amount'."\n";
45         print 'graph_args --base 1000 -l 0 '."\n";
46         print 'graph_vlabel Daily Virus Amount'."\n";
47         print 'graph_category Mail'."\n";
48         print 'virus.label Virus'."\n";
49         print 'virus.draw AREA'."\n";
50         exit 0;
51 }
52
53 my $total_amount = `$collector_command`;
54 my $actual_amount = 0;
55
56 chomp($total_amount);
57
58 unless(-e "$STATEFILE")
59 {
60         $fh->open(">$STATEFILE");
61         print $fh "$total_amount";
62         $fh->close();
63         print "virus.value $total_amount";
64         exit 0;
65 }
66
67 $fh->open("<$STATEFILE");
68 my $last_amount = <$fh>;
69 chomp($last_amount);
70 $fh->close();
71
72 $actual_amount = $total_amount - $last_amount;
73 if($actual_amount < 0)
74 {
75         # A new Day has started. Set the actual_amount to total_amount and write this into the statefile
76         $actual_amount=$total_amount;
77 }
78
79
80 $fh->open(">$STATEFILE");
81 print $fh "$total_amount";
82 $fh->close();
83 print "virus.value $actual_amount";
84 exit 0;