#!/usr/bin/perl -w use strict; # 'global' variable declarations go here my $bgcolor= "silver"; my $fontcolor = "white"; my $headcolor = "#33ccff"; my $linkcolor = "red"; my $outpath = "/var/www/html"; my $msg = "/var/log/messages"; my %messages; my %msgbydate; my $tempcounter; my %flag; my $key; my $date; my %number = ( "Jan" => "1", "Feb" => "2", "Mar" => "3", "Apr" => "4", "May" => "5", "Jun" => "6", "Jul" => "7", "Aug" => "8", "Sep" => "9", "Oct" =>"10", "Nov" =>"11", "Dec" =>"12"); open (MESSAGELOG,$msg) or die "failed to open $msg: $!\n"; while () { my ($month,$day,$time,$host,$service,undef) = split; $date = $number{$month}."-".$day; # strip out anything between non word characters (basically looking to eliminate pids) $service =~s/(\W[\d\w\W]+\W)//g; $service =~s/://g; # print "- $service\n"; $messages{$service}++; $msgbydate{$date}++; unless ($service=~m/--/) {&writefile ($flag{$service},$service,$_);} $flag{$service} = 1; &writefile ($flag{$date},$date,$_); $flag{date}=1; } close MESSAGELOG; my $outfile = $outpath ."/messages.html"; open (TEMPOUT,">$outfile") or die "failed to open $outfile: $!\n"; print TEMPOUT <<"END";
Message Log Viewer
by service by date
END close TEMPOUT; $outfile = $outpath ."/messageservices.html"; open (TEMPOUT,">$outfile") or die "failed to open $outfile: $!\n"; print TEMPOUT <<"END";

Summary of $msg


END foreach $key (sort keys %messages) { unless ($key=~m/--/) { print TEMPOUT ""; } } print TEMPOUT <<"END";
Service # of Msgs
$key$messages{$key}
END close TEMPOUT; $outfile = $outpath."/messagedates.html"; open (TEMPOUT,">$outfile") or die "failed to open $outfile: $!\n"; print TEMPOUT <<"END";

Summary of $msg


END foreach $key (sort keys %msgbydate) { print TEMPOUT ""; } print TEMPOUT <<"END";
Date # of Msgs
$key$msgbydate{$key}
END close TEMPOUT; sub writefile { my $flag = $_[0]; my $label = $_[1]; my $line = $_[2]; unless ($flag) { open(TEMPOUT,">".$outpath."/".$label.".html") or die "failed to open $date: $!\n"; $flag{$date}=1; } else { open(TEMPOUT,">>".$outpath."/".$label.".html") or die "failed to open $date: $!\n"; } print TEMPOUT $line; print TEMPOUT "
"; close TEMPOUT; }