5 use vars qw(%DATAFIELDS);
8 use Yaala::Parser::WebserverTools qw(%MONTH_NUMBERS);
9 use Yaala::Data::Persistent qw#init#;
10 use Yaala::Config qw#get_config#;
12 @Yaala::Parser::EXPORT_OK = qw(parse extra %DATAFIELDS);
13 @Yaala::Parser::ISA = ('Exporter');
15 our $LASTDATE = init ('$LASTDATE', 'scalar');
16 our $EXTRA = init ('$EXTRA', 'hash');
18 if (!$$LASTDATE) { $$LASTDATE = 0; }
19 if (!defined ($EXTRA->{'total'})) { $EXTRA->{'total'} = 0; }
20 if (!defined ($EXTRA->{'days'} )) { $EXTRA->{'days'} = {}; }
29 status => 'key:numeric',
34 # This needs to be done at runtime, since Data uses Setup which relies on
35 # %DATAFIELDS to be defined -octo
36 require Yaala::Data::Core;
37 import Yaala::Data::Core qw#store#;
39 my $VERSION = '$Id: Common.pm,v 1.14 2003/12/07 14:56:38 octo Exp $';
40 print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
46 my $line = shift or return undef;
47 if ($line =~ /^(\S+) (\S+) (\S+) \[([^\]]+)\] "([^"]+)" (\d+) (\d+|-)$/)
49 my ($host, $ident, $user, $date, $request, $status, $bytes) =
50 ($1, $2, $3, $4, $5, $6, $7);
52 my ($day, $month, $year, $hour, $minute, $second) =
53 $date =~ m#(\d\d)/(\w{3})/(\d{4}):(\d\d):(\d\d):(\d\d)#;
55 $month = $MONTH_NUMBERS{$month};
56 $date = sprintf("%04u-%02u-%02u", $year, $month, $day);
59 my $tmp = int (sprintf ("%04u%02u%02u%02u%02u%02u",
60 $year, $month, $day, $hour, $minute, $second));
62 if ($tmp < $$LASTDATE)
64 print STDERR $/, __FILE__, ": Skipping.. ($tmp < $$LASTDATE)" if ($::DEBUG & 0x0200);
67 else { $$LASTDATE = $tmp; }
70 my ($method, $file, $params);
71 if ($request =~ m#(\S+) ([^ \?]+)\??(\S*)#)
75 $params = (defined ($3) ? $3 : '');
79 print STDERR $/, __FILE__, ": Malformed request: ``$request''." if ($::DEBUG);
83 if (($user ne '-') and ($status >= 400) and ($status < 500))
88 if ($user eq '-') { $user = '*UNKNOWN*'; }
89 if ($bytes eq '-') { $bytes = 0; }
92 if ($host =~ m/\.([a-z]{2,})$/i)
98 $tld = '*UNRESOLVED*';
102 $EXTRA->{'days'}{$date}++;
120 print STDERR $/, __FILE__, ": Unable to parse: '$line'";
126 my ($average, $days) = (0, 0);
128 $days = scalar (keys (%{$EXTRA->{'days'}}));
130 return (0) unless ($days);
132 $average = sprintf ("%.1f", ($EXTRA->{'total'} / $days));
134 $::EXTRA->{'Total requests'} = $EXTRA->{'total'};
135 $::EXTRA->{'Average requests per day'} = $average;
136 $::EXTRA->{'Reporting period'} = "$days days";