#!/usr/bin/perl #Plot month-month data for e-mail (ham & spam) recevied @flanigan.net # Example using GD::Graph with arrays # By: David A. Flanigan # No Warrnety provided or implied, use at your own risk. # Free for any use. Please send improvements back to dave@flanigan.net # E-mail dave@flanigan.net with questions on modifying this script. # http://www.flanigan.net/scripts # use warnings; use strict; use GD::Graph::lines #init variables chomp(my $date=`/bin/date`); my $count = 0; my @month = (); my @spc = (); # Open Smonthly Log File (/var/log/smonthly.log) # Date | Total Mail | Spam Mail | Spam % | Ham Mail | DSBL Blocks| Referrer Spam # Tue Aug 1 00:10:02 EDT 2006|50602|48104|95.1|2498|1170186|0 open (SML, "/var/log/smonthly.log"); while ( ) { chomp; next if ($_ =~ /^#/); (my $smldate, my $smltmail, my $smlsmail, my $smlspc, my $smlhmail, my $smldsbl, my $smlrs) = split (/\|/); #parse date (my $smlday, my $smlmonth, my $smldom, my $smltime, my $smltz, my $smlyr) = split (/[ \t]+/,$smldate); #Figure out last month and year as needed. if ($smlmonth eq "Jan") { $smlmonth = "Dec"; $smlyr = $smlyr - 1; } if ($smlmonth eq "Feb") { $smlmonth = "Jan"; } if ($smlmonth eq "Mar") { $smlmonth = "Feb"; } if ($smlmonth eq "Apr") { $smlmonth = "Mar"; } if ($smlmonth eq "May") { $smlmonth = "Apr"; } if ($smlmonth eq "Jun") { $smlmonth = "May"; } if ($smlmonth eq "Jul") { $smlmonth = "Jun"; } if ($smlmonth eq "Aug") { $smlmonth = "Jul"; } if ($smlmonth eq "Sep") { $smlmonth = "Aug"; } if ($smlmonth eq "Oct") { $smlmonth = "Sep"; } if ($smlmonth eq "Nov") { $smlmonth = "Oct"; } if ($smlmonth eq "Dec") { $smlmonth = "Nov"; } my $monyr = "$smlmonth $smlyr"; #debug #print "month = $monyr, Ham = $smlhmail, Spam = $smlsmail, Total = $smltmail\n"; #populate arrays push (@month, $monyr); push (@spc, $smlspc); } # Graph it #The tricky part - load the graph array my @data = (\@month, \@spc); my $graph = GD::Graph::lines->new(500,250); $graph->set( x_label => 'Month', y_label => '% of Mail which is Spam', title => 'Spam % @flanigan.net', y_max_value => 100, y_tick_number => 5, line_width => 2, long_ticks => 1, l_margin => 0, r_margin => 0, x_label_position => 1/2, ) or die $graph->error; #Set Graph Color #$graph->set_text_clr(black); #Set Font $graph->set_title_font('Ariel', 12); $graph->set_legend_font('Ariel', 12); $graph->set_legend('% Spam'); my $gd = $graph->plot(\@data) or die $graph->error; #gif option #open (IMG, '>file.gif') or die $!; #binmode IMG; #print IMG $gd->gif; #close IMG; open (IMG, '>/var/www/html/spam/spampc.png') or die $!; binmode IMG; print IMG $gd->png; exit;