my $font = '/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf';
$graph->set_values_font($font, 12);
####
#!/usr/bin/perl
# page.cgi
use strict;
use CGI ':standard';
print header();
print start_html(-title =>'Global Mail Statistics',
-bgcolor=>'#95B8DB');
print qq!
Global Mail Statistics
!;
print end_html;
####
#!/usr/bin/perl
# bargraph.cgi
use strict;
use warnings;
use CGI qw(:standard);
use GD::Graph;
use GD::Graph::bars;
use CGI::Carp 'fatalsToBrowser'; # use only for testing
my $logfile = '/var/log/maillog';
open $fh, '<', $logfile or die "Could not open $logfile : $!";
my %count=();
while (<$fh>){
if (/amavis.*(Passed|Blocked) (CLEAN|SPAM|INFECTED|BANNED)/){
++$count{$2};
} elsif (/amavis.*(BAD-HEADER)-/) {
++$count{$1};
} elsif (/reject/){
++$count{'REJECTED'};
}
}
close $fh;
my @data = map{ $count{$_} || 0 } qw(CLEAN SPAM INFECTED BANNED BAD-HEADER REJECTED);
my $data = GD::Graph::Data->new([
["Cleaned","Spam","Virus","Banned","BadHeader","Rejected"],
[@data],
]) or die GD::Graph::Data->error;
my $graph = GD::Graph::bars->new(900,600);
$graph->set(
x_label => 'Category',
y_label => 'Count',
title => 'Global Mail Statistics for '.localtime,
show_values => 1,
y_tick_number => 8,
bar_spacing => 10,
shadow_depth => -4,
shadowclr => 'dred',
transparent => 0,
) or die $graph->error;
my $font = '/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf';
$graph->set_title_font($font,14);
$graph->set_values_font($font, 12);
$graph->set_x_axis_font($font,10);
$graph->set_y_axis_font($font,10);
$graph->set_x_label_font($font,12);
$graph->set_y_label_font($font,12);
print header('image/png');
$graph->plot($data) or die $graph->error;
binmode STDOUT;
print $graph->gd->png;