#!perl # Many Thanks for # home777@mail.ru Ovseenko Andrey and # ######################################################################################## # Was originally prspoa.pl 1.0.0 25 OCT 2002 by # Koltogyan Sergey Rubenovich # skoltogyan@mail.ru # NPP AMI, Donetsk, ukraine ######################################################################################## # Rewritten-expanded by Rob Anderson (rob.anderson@americansouthwest.com) 24 MAR 2005 # Will run on NW5.0sp6A Perl + ActiveState PERL 5.8.4 for Windows at least. ######################################################################################## # Re-Rewritten and changed to version for Expire Statistics by Peter Toussaint # (peter.toussaint@unisa.ac.za) Unisa, Pretoria, South Africa 29 August 2005 ######################################################################################## # Date Version Description ######################################################################################## # 03/24/05 1.00.01 Add FID to output & user/resource count # 03/30/05 1.00.02 Add Processed Date/Version, cleaned up FID and user name handling # 04/20/05 1.00.03 Add handling of GW6.5.4 at least # 05/19/05 1.01.00 Bug - not handling over threshold/limits users properly # Add red background for users over the size limit # Add orange background for users over the threshold size # Correct bug with processing time for job for 6.5 # 06/16/05 1.01.01 Bug fixes - Long mailbox ID's/Fid & MailboxID's with Spaces & add # version to footer # 08/29/05 2.01.00 New version or new program? Anyway, now the script handles the GWSTAT # output from Mailbox Statistics where you select Expire Statistics # Items larger than... ######################################################################################## # Be smart and select in your GWcheck only the Sent items to prevent getting your results double # Then get all your logfiles from the seperate Post Offices and put them in one folder ################################################### #Get all logfiles and put them in an array # # enter the path to your logfiles below # ################################################### $path='c:\yourlogs'; #enter the path to your log files here chdir $path; while (defined($nextname = <*.log>)) { @logs = (@logs," $nextname"); } ################################################### #Now first get total userdatabases, nice to know..# ################################################### $total=0; foreach $logs (@logs) { open (FL, "<$logs") || die("Source File Error $!"); while () { if ($_ =~ /User databases found:\s+(\w+)/) { $pousers = $1; } } $total = ($total + $pousers); }; ###################################################################### #Now we take Lines from all log files that start with Mail or Appt # #(our perpetrators) into one big total.log and put the name of the # #logfile in front for later use. # # While we're at it, delete all brackets # ###################################################################### my $TOSAVE = "$path/total.log"; open (FL1, ">$TOSAVE") || die("Target File Error $!"); foreach $logs (@logs) { open (FL, "<$logs") || die("Source File Error $!"); while () { if ($_ =~ /^Mail\s\s\s/) { $_ =~ s/\(/-/g; $_ =~ s/\)/-/g; print FL1 $logs." ".$_; } if ($_ =~ /^Appt\s\s\s(.{1,16})/) { $_ =~ s/\(/-/g; $_ =~ s/\)/-/g; print FL1 $logs." ".$_; } } } ################################################################## sub doreport; #predeclaring the subroutine ### Below is code to get the current date and time ### ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); @nummonths = ("01","02","03","04","05","06","07","08","09","10","11","12"); @namemonths = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); @numyears = ("2002","2003","2004","2005"); if ($hour < 10) { $hour = "0$hour"; } if ($mday < 10) { $mday = "0$mday"; } if ($min < 10) { $min = "0$min"; } $year=$year+1900; $year_search = $year; $fmtdate = "@nummonths[$mon]/$mday/$year"; $sdate = "$year@nummonths[$mon]$mday"; $stime = "$hour\:$min"; ######################################################################################## ######################################################################################## #Change the below to your Company name if desired ######################################################################################## $coname = "Your Company"; ######################################################################################## ######################################################################################## # Enter your GW Domain and GW Po Information Below ######################################################################################## $gwdomain = "Unisa"; #enter the domain name for path purposes, and appearing on the report $gwpo = "Total"; #enter the PO name for path purposes, and to appear on the report ######################################################################################## #Input and Ouptut Filenames here ######################################################################################### ## Note, unless you're using linux, you're going to want to use \ in your paths. Don't!# ## PERL doesn't like that very much. use /, eg f:/$gwpo/wpcsout/ofs/contents.log # ######################################################################################### my $TOSAVE = "$path/total.html"; my $FROMREAD = "$path/total.log"; # This is the same total.log that we filled earlier. LEAVE IT!# #my $INCLPUDB = -1; doreport; #actually executes the subroutine exit (0); #leave the program ######################################################################################## #No Changes below here unless you REALLY know what you're doing!!! ######################################################################################## sub doreport { @arr = (); open (FL, "<$FROMREAD") || die("Source File Error $!"); open (FL1, ">$TOSAVE") || die("Target File Error $!"); print FL1 "\n"; print FL1 "Groupwise Total Stats\n"; print FL1 "

$coname

\n"; print FL1 "

Groupwise Biggest E-mail Statistics for $fmtdate

\n"; print FL1 "

For: ($gwdomain.$gwpo)

\n"; $progver='GWbigSTATS (PDT) Version 02.00.01'; $user = ''; $big = ''; $from = ''; $to = ''; $date = ''; $proctime = ''; $ver = ''; $serverlog = ''; while () { ### First my new fields @words = split; $serverlog = $words[0]; ################################################# #This gets the first word of the logfile (which # #is the logfile where the row comes from), it is# #put in $serverlog. # ################################################# if ($_ =~ /Mail\s\s\s(.{1,16})/) { $from = $1; } if ($_ =~ /Appt\s\s\s(.{1,16})/) { $from = $1; } if ($_ =~ /Mail\s\s\s$from\s(.{1,16})/) { $to = $1; } if ($_ =~ /Appt\s\s\s$from\s(.{1,16})/) { $to = $1; } if ($_ =~ /Mail\s\s\s$from\s$to(.{1,15})/) { $date = $1; } if ($_ =~ /Appt\s\s\s$from\s$to(.{1,15})/) { $date = $1; } if ($_ =~ /Mail\s\s\s$from\s$to$date\s(.{1,10})/) { $big = $1; } if ($_ =~ /Appt\s\s\s$from\s$to$date\s(.{1,10})/) { $big = $1; } ####################################################### #Now we have both the Mail and the Appt lines and from# #those lines the 'From', the 'To', the date/time and # # size of the item. # ####################################################### if ($from && $big) { ##This means there must be both a from and the size > zeros my %hash; $hash{'from'} = $from; $hash{'to'} = $to; $hash{'date'} = $date; $hash{'big'} = $big; $hash{'user'} = $user; $hash{'serverlog'} = $serverlog; push @arr, \%hash; $from = ''; $to = ''; $date = ''; $big = ''; $serverlog = ''; } }; @arr = sort {$b->{'big'} <=> $a->{'big'}} @arr; print FL1 "
";
  print FL1 "
"; print FL1 ""; print FL1 "

Summary Information

\n"; print FL1 ""; print FL1 "
Users/Resources in system $gwpo:$total
\n"; print FL1 "
";
  print FL1 "
"; print FL1 ""; print FL1 ""; print FL1 ""; print FL1 "\n"; ############################################### # I just want the first $amount of this list # ############################################### # And my default value... # ############################################### $default = 100; #of course you can set another default here print "how many results do you want? default=$default: "; chomp($amount = ); $amount ||= $default; for ($i = 1; $i <= $amount; $i++) { for ($arr[$i]) { ############################################### print FL1 ''; #white print FL1 '\n"; } } print FL1 "
"; print FL1 "
ServerFromToDateMail Size (in bytes)
'; print FL1 $_->{'serverlog'}; print FL1 ''; print FL1 $_->{'from'}; print FL1 ''; print FL1 $_->{'to'}; print FL1 '
'; print FL1 $_->{'date'}; print FL1 '
'; print FL1 $_->{'big'}; print FL1 "
\n"; print FL1 "



This page created at $fmtdate $stime
$progver
"; print FL1 "\© $year $coname
"; print FL1 ""; close(FL); close(FL1); }