#!/usr/bin/perl ### Perl script to generate RBL blocking statistics from Exim 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 warnings; use GD::Graph::pie; ######## Edit these items ######## #This is the path to your ClamAV log file my $logfile="/var/log/exim/main.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 $imageoutput = "/path/to/apache/www/images/rblstats.png"; #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 = "/export/sites/alexlomas.com/www/info/rblstats.html"; #### No user serviceable parts below this line #### my %data; my @graphdata; my $total = 0; open LOG, "<", "$logfile" or die "Can't open logfile: $!\n"; while ( ) { next unless /host is listed in\s*(\S+)/ig; $data{$1}++; $total++; } close LOG; my @keys = sort { $data{$b} <=> $data{$a} } keys %data; @graphdata = ( [ @keys ], [ @data{ @keys } ] ); my $graph = GD::Graph::pie->new(300, 300); $graph->set( title => '', '3d' => 1, start_angle => 90, suppress_angle => 5 ) or die $graph->error; my $gd = $graph->plot(\@graphdata) or die $graph->error; open(IMG, ">$imageoutput") or die $!; binmode IMG; print IMG $gd->png; close IMG; open (HTML, ">$htmlfile") or die "Unable to write HTML output"; for my $key ( @keys ) { my $percentage = ( $data{ $key } / $total * 100.0 ); print HTML "$key "; printf HTML ( "%.2f", $percentage ); print HTML "\%
"; } close HTML;