#!/usr/bin/perl ### Perl script to generate ClamAV virus blocking history from clamav log files ### v1.0 by Alex Lomas alex at alex lomas dot com ### See also http://www.alexlomas.com/info/exim-scripts.html use strict; use GD::Graph::lines; ######## Edit these items ######## #This is the path to your ClamAV log file my $logfile="/var/log/clamd/clamd.log"; #This is that path you want for the output PNG pie chart #Probably this will be somewhere in your web server's directory my $imagefile="/path/to/apache/www/images/virushistory.png"; #### No user serviceable parts below this line #### my %data; my %count; open LOG, "<", "$logfile" or die "Can't open logfile: $!\n"; while ( ) { next unless /\S+\s+FOUND$/; my ( $u_date, $malware ) = $_ =~ /(.+) -> \S+: (\S+) FOUND$/; my ( $month, $day, $year ) = $u_date =~ /^\w+\s+(\w+)\s+(\d+)\s+\S+\s+(\d+)$/; if ( $day <= 9 ) { $day = "0$day"; } my %translate = ( 'Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12' ); $month = $translate{$month}; next unless ( $day && $month && $year ); my $f_date = "$year-$month-$day"; $count{$f_date}++; } close LOG; my @keys = sort keys %count; my @graphdata = ( [ @keys ], [ @count{ @keys } ] ); my $graph = GD::Graph::lines->new(600, 300); $graph->set( title => '', x_ticks => '0', x_label => 'Date', y_label => 'Intercepted email viruses', x_labels_vertical => '1', x_label_skip => '10', line_width => '3' ) or die $graph->error; my $gd = $graph->plot(\@graphdata) or die $graph->error; open(IMG, ">$imagefile") or die $!; binmode IMG; print IMG $gd->png; close IMG;