#!/usr/bin/perl ### Perl script to generate ClamAV virus blocking statistics 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::pie; ######## Edit these items ######## #This is the path to your ClamAV log file my $logfile="/var/log/clamd/clamd.log"; #This is the path to some simple HTML formatted text output #The use of this would be to do a server side include to add it to an existing web page my $htmlfile="/path/to/apache/www/virusout.html"; #This is that path you want for the output PNG pie chart #Again, probably somewhere in your web server's directory my $imagefile="/path/to/apache/www/images/virus.png"; #### No user serviceable parts below this line #### my %count; my %data; my $total; open OUTFILE, ">", "$htmlfile" or die "Can't open $htmlfile file for writing: $!\n"; open LOG, "<", "$logfile" or die "Can't open logfile: $!\n"; while ( ) { next unless /(\S+)\s+FOUND$/; $count{$1}++; $total++; } my @keys = sort { $count{$b} <=> $count{$a} } keys %count; my @graphdata = ( [ @keys ], [ @count{ @keys } ] ); my $graph = GD::Graph::pie->new(300, 300); $graph->set( title => '', '3d' => 1, start_angle => 180, suppress_angle => 10 ) 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; for my $key ( @keys ) { my $percentage = ( $count{ $key } / $total * 100.0 ); print OUTFILE "$key "; printf OUTFILE ( "%.2f", $percentage ); print OUTFILE "\%
"; }