AWStats

From SpenchWiki
Jump to: navigation, search

Patch to AWStatus to enable precise (and more flexible) log line matching. Catch is that matching on arbitrary words is exact, and if they're not registered beforehand, matching will fail (e.g. see the "IIS Other" section below - these, and any others, must be there, otherwise this patch will create breaking changes!). Also, there is the FIXME regarding using %% to imply an escaped literal %.

For example, for Squid reverse proxy:

LogFormat="%time4b %other %host %other/%code %bytesd %method http://%virtualname%url %other %other/%other %other"

Patch:

8723a8724,8730
>
>       # IIS other
>       $LogFormatString =~ s/s-ip/%other/g;
>       $LogFormatString =~ s/s-port/%other/g;
>       $LogFormatString =~ s/cs\(Cookie\)/%other/g;
>       $LogFormatString =~ s/sc-substatus/%other/g;
>       $LogFormatString =~ s/sc-win32-status/%other/g;
8736,8737c8743,8752
<       foreach my $f ( split( /\s+/, $LogFormatString ) ) {
<
---
> #     foreach my $f ( split( /\s+/, $LogFormatString ) ) {
>       foreach my $fx ( split( /%/, $LogFormatString ) ) {     # FIXME: %% -> empty string in between them, prepend to next iteration (ignore first loop though!)
>
>               my $f = $fx;
>               $f =~ s/^([a-z\d_]+).*/%$1/;
>               my $fz = substr($fx, (length($f)-1));
>               $fz =~ s/(\/|\\)/\\$1/g;
>               $fz =~ s/\s+/$LogSeparator/g;
> if ($Debug) { debug(" fx=\"$fx\", f=\"$f\", fz=\"$fz\""); }
8739c8754
<               if ($PerlParsingFormat) { $PerlParsingFormat .= "$LogSeparator"; }
---
>               #if ($PerlParsingFormat) { $PerlParsingFormat .= "$LogSeparator"; }
8792a8808,8813
>               elsif ( $f =~ /%time4b$/ ) {    # ddddddddddddd.ddd (only take first lot)
>                       $pos_date = $i;
>                       $i++;
>                       push @fieldlib, 'date';
>                       $PerlParsingFormat .= "(\\d+)[\\.\\d]*";
>               }
8829c8850,8851
<                       $PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
---
>                       #$PerlParsingFormat .= "([^$LogSeparatorWithoutStar]+)";
>                       $PerlParsingFormat .= "([\\w\\.-]+)";
9000c9022
<               else {
---
>               elsif ( $f !~ /^$/ ) {
9002a9025,9026
>
>               $PerlParsingFormat .= $fz;
10865a10890
>                       || $field[$pos_method] eq 'CONNECT'           # Squid