#!/usr/bin/perl # -w # Dump the database obtained with the xmget program. Group the # results and display them in a graph. # Phil Hollenback # philiph@pobox.com # 8/10/98 use AnyDBM_File; use Fcntl; # For O_ file creation modes. use Chart::Bars; use Env qw(HOME LOGNAME); use Getopt::Std; # For command line processing. # # Configuration Options # # Location of the mailer list database $mailer_db = "/webdocs/html/xmailer/.mailers"; # Default file to output the graph to. $graph = "/webdocs/html/xmailer/all_mailers.png"; #$graph = "/tmp/all_mailers.png"; # # End Configuration Options # # Set the program version $version = "1.0"; # Extract the program name from it's path. @progarray = split("/", $0); $progname = pop @progarray; # Initialize variables. %mailer_hash = (); %chart_hash = (); $total_messages = 0; $today = `date +%m%d%y`; chop $today; ($today_month, $today_day, $today_year) = ($today =~ m|(\d\d)(\d\d)(\d\d)|); #$HOSTNAME = `hostname`; chop $HOSTNAME; $HOSTNAME = 'hollenback.net'; $opt_v = $opt_h = $opt_c = 0; # Set flag to print the help message if getopts fails. getopts('hvdc') or $opt_h = 1; # Set flag to print the help message if there are any command line # arguments left. xmdump currently takes no arguments other than # flags. $opt_h = 1 if ($ARGV[0]); # Print a help message and exit if $opt_h flag is set from either of # the two previous checks. if ( $opt_h ) { print STDERR < ", $mailer_hash{$_}, "\n"; } } # Iterate through the database and assign entries to groups. foreach (keys %mailer_hash) { $db_entry = $mailer_hash{$_}; if ( /^Mutt/) { $chart_hash{"Mutt"} += $db_entry } elsif ( /^Mozilla/) { $chart_hash{"Netscape"} += $db_entry } elsif ( /Eudora/) { $chart_hash{"Eudora"} += $db_entry } elsif ( /^Microsoft Outlook/) { $chart_hash{"MS Outlook"} += $db_entry } elsif ( /Internet Mail/) { $chart_hash{"MS Exchange"} += $db_entry } elsif ( /GroupWise/) { $chart_hash{"GroupWise"} += $db_entry } elsif ( /^Pine/) { $chart_hash{"Pine"} += $db_entry } elsif ( /^AOL/) { $chart_hash{"AOL"} += $db_entry } elsif ( /^ELM/) { $chart_hash{"Elm"} += $db_entry } elsif ( /^Gnus/) { $chart_hash{"Gnus"} += $db_entry } elsif ( /^Mail User's Shell/) { $chart_hash{"Mush"} += $db_entry } elsif ( /^SCO OpenServer Mail/) { $chart_hash{"SCO OSR Mail"} += $db_entry } elsif ( /^SCO Shell/) { $chart_hash{"SCO Shell"} += $db_entry } elsif ( /^ScoMail/) { $chart_hash{"ScoMail"} += $db_entry } elsif ( /^XFMail/) { $chart_hash{"XFMail"} += $db_entry } elsif ( /^exmh/) { $chart_hash{"exmh"} += $db_entry } elsif ( /Unknown Mailer/) { $chart_hash{"Unknown"} += $db_entry } elsif ( /^Total Messages Received/) { $total_messages = $db_entry } elsif ( /^Date Database Created/) { ($start_month, $start_day, $start_year) = ($db_entry =~ m|(\d\d)(\d\d)(\d\d)|) } else { $chart_hash{"Other"} += $db_entry }; } # More verbose output. if ( $verbose ) { print STDERR "\nTotals for selected mailers:\n\n"; foreach (sort { $chart_hash{$b} <=> $chart_hash{$a} } keys %chart_hash) { print STDERR $_, " => ", $chart_hash{$_}, "\n"; } } # Construct the chart and output the picture. $g = Chart::Bars->new (950,600); $g->add_dataset (keys %chart_hash); $g->add_dataset (values %chart_hash); $g->set ('title' => "Mailers used to send messages to user $LOGNAME at $HOSTNAME" ); $g->set ('sub_title' => "$total_messages total messages received from $start_month/$start_day/$start_year to $today_month/$today_day/$today_year"); $g->set ('x_label' => 'Mailer Program'); $g->set ('y_label' => '# of Messages Received'); $g->set ('legend' => 'none'); $g->set ('graph_border' => 20); ##$g->set ('colors' => [[0,255,0]]); $g->set ('sort' => ['desc', 1, 'num'] ); $g->set ('transparent' => 'true' ); $g->set ('grid_lines' => 'true' ); if ( $opt_c ) { print "Content-type: image/png\n"; print "Cache-Control: no-cache\n"; print "Pragma: no-cache\n"; print "Expires: 0\n\n"; $g->png ("-"); print "\n"; } else { $g->png ($graph); print "Results graph is $graph.\n"; } # Immediately display the picture and remove it if the -d command line # argument was given. if ($opt_d == 1 ) { system("xv $graph"); unlink $graph; }