#!/usr/local/bin/perl use File::Basename; use strict; my $logdate = shift @ARGV; my $crap = shift @ARGV; my $total="0"; my $blocked="0"; if (defined ($crap)) { print ("I can't take all these arguments!!\n"); print ("useage: $0 YYYYMMDD\n"); exit 1; } unless ($logdate =~ /^[\d]{8}$/ ) { print ("arg wrong: $logdate\n"); print ("useage: $0 YYYYMMDD\n"); exit 1; } my $mmdd = substr($logdate, 4, 4); my $logdir="/backup/oldlogs/cflow"; my @logs = `ls $logdir/*_$mmdd*.gz`; my %blocked; my %total; my @machines; foreach my $log (@logs) { my $machine = basename ($log); $machine =~ s/_.*//; push (@machines, $machine) unless (grep /$machine/, (@machines)); open (CFLOG, "/usr/local/bin/zcat $log |") or die ; while () { my ($stat, $cat) = (split (/","/))[0,1]; $stat =~ s/.*\"//; if ($cat eq "-") { $cat = "uncategorized";} # print ("$stat\t$cat\n"); $total{"$machine~$cat"}++; $blocked{"$machine~$cat"}++ if ($stat eq "DENIED"); } close (CFLOG); } my @cats; foreach my $key (keys %total){ $key =~ s/.*~//; next unless $key =~ /\w/; push (@cats, $key) unless (grep /$key/, (@cats));; } my @tmp = sort @cats; @cats = @tmp; #------------------------------------------------------------------- # print report # my $reportdir = substr($logdate, 0, 4) . "-" . substr($logdate, 4, 2); if (!-d $reportdir ) { mkdir ("$reportdir", 0755) or die ("$!"); } open (OUT, ">$reportdir/cf_report-$mmdd.txt") or die ("$!"); select (OUT) or die ("$!"); #------------------------------------------------------------------- # print totals # print ("\nTotal web hits\n"); # header printf ("%15s", ""); foreach my $box (@machines) { printf ("%12.12s", $box); } printf ("%12s", "Total"); print ("\n"); # each cat my %cattot; foreach my $cat (@cats) { my $tot; printf ("%15.15s", $cat); foreach my $box (@machines) { printf ("%12d", $total{"$box~$cat"} || 0); $tot += $total{"$box~$cat"} || 0; $cattot{"$box"} += $total{"$box~$cat"} || 0; } printf ("%12d", $tot); print ("\n"); } # category totals print ("\n"); printf ("%15s", "Total ="); foreach my $box (@machines) { printf ("%12d", $cattot{"$box"}); } my $grand; foreach my $num (values %cattot) { $grand += $num || 0; } printf ("%12d", $grand); print ("\n"); #------------------------------------------------------------------- # print total blocked # print ("\n\n\nTotal web hits blocked\n"); # header printf ("%15s", ""); foreach my $box (@machines) { printf ("%12.12s", $box); } printf ("%12s", "Total"); print ("\n"); # each cat my %cattot; foreach my $cat (@cats) { my $tot; printf ("%15.15s", $cat); foreach my $box (@machines) { printf ("%12d", $blocked{"$box~$cat"} || 0); $tot += $blocked{"$box~$cat"} || 0; $cattot{"$box"} += $blocked{"$box~$cat"} || 0; } printf ("%12d", $tot); print ("\n"); } # category totals print ("\n"); printf ("%15s", "Total ="); foreach my $box (@machines) { printf ("%12d", $cattot{"$box"}); } my $grand; foreach my $num (values %cattot) { $grand += $num || 0; } printf ("%12d", $grand); print ("\n"); exit 0;