-
-
Notifications
You must be signed in to change notification settings - Fork 128
Description
Is your feature request related to a problem? Please describe.
unable to parse apache log entries such as one below
LogFormat=%v:%p [%a]:%{remote}p %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"
as AWStats requires spaces everywhere and what-not
Describe the solution you'd like
the changes ive included below, yes im the worst, your call, have a look anyway, i added %a as %h also
diff /usr/lib/cgi-bin/awstats.pl.orig /usr/lib/cgi-bin/awstats.pl
9046,9048d9045
< # Replacement for Notes format string that are not Apache
< $LogFormatString =~ s/%vh/%virtualname/g;
<
9050,9070c9047,9062
< $LogFormatString =~ s/%v(\s)/%virtualname$1/g;
< $LogFormatString =~ s/%v$/%virtualname/g;
< $LogFormatString =~ s/%h(\s)/%host$1/g;
< $LogFormatString =~ s/%h$/%host/g;
< $LogFormatString =~ s/%l(\s)/%other$1/g;
< $LogFormatString =~ s/%l$/%other/g;
< $LogFormatString =~ s/\"%u\"/%lognamequot/g;
< $LogFormatString =~ s/%u(\s)/%logname$1/g;
< $LogFormatString =~ s/%u$/%logname/g;
< $LogFormatString =~ s/%t(\s)/%time1$1/g;
< $LogFormatString =~ s/%t$/%time1/g;
< $LogFormatString =~ s/\"%r\"/%methodurl/g;
< $LogFormatString =~ s/%>s/%code/g;
< $LogFormatString =~ s/%b(\s)/%bytesd$1/g;
< $LogFormatString =~ s/%b$/%bytesd/g;
< $LogFormatString =~ s/\"%\{Referer}i\"/%refererquot/g;
< $LogFormatString =~ s/\"%\{User-Agent}i\"/%uaquot/g;
< $LogFormatString =~ s/%\{mod_gzip_input_size}n/%gzipin/g;
< $LogFormatString =~ s/%\{mod_gzip_output_size}n/%gzipout/g;
< $LogFormatString =~ s/%\{mod_gzip_compression_ratio}n/%gzipratio/g;
< $LogFormatString =~ s/\(%\{ratio}n\)/%deflateratio/g;
---
> $LogFormatString =~ s/\Q%v\E/%virtualname/g;
> $LogFormatString =~ s/\Q%h\E/%host/g;
> $LogFormatString =~ s/\Q%a\E/%host/g;
> $LogFormatString =~ s/\Q%l\E/%other/g;
> $LogFormatString =~ s/\"\Q%u\E\"/%lognamequot/g;
> $LogFormatString =~ s/\Q%u\E/%logname/g;
> $LogFormatString =~ s/\Q%t\E/%time1/g;
> $LogFormatString =~ s/\"\Q%r\E\"/%methodurl/g;
> $LogFormatString =~ s/\Q%>s\E/%code/g;
> $LogFormatString =~ s/\Q%b\E/%bytesd/g;
> $LogFormatString =~ s/"\Q%{Referer}i\E"/%refererquot/g;
> $LogFormatString =~ s/"\Q%{User-Agent}i\E"/%uaquot/g;
> $LogFormatString =~ s/\Q%{mod_gzip_input_size}n\E/%gzipin/g;
> $LogFormatString =~ s/\Q%{mod_gzip_output_size}n\E/%gzipout/g;
> $LogFormatString =~ s/\Q%{mod_gzip_compression_ratio}n\E/%gzipratio/g;
> $LogFormatString =~ s/\(\Q%{ratio}n\E\)/%deflateratio/g;
9123c9115,9119
< foreach my $f ( split( /\s+/, $LogFormatString ) ) {
---
>
> my @f_queue = split( /\s+/, $LogFormatString );
> my $index = 0;
> while ($index < @f_queue) {
> my $f = $f_queue[$index];
9126c9122,9126
< if ($PerlParsingFormat) { $PerlParsingFormat .= "$LogSeparator"; }
---
> if ($index eq 0) {}
> else
> {
> if ($PerlParsingFormat) { $PerlParsingFormat .= "$LogSeparator"; }
> }
9129,9130c9129,9133
< if ( $f =~ /^([^%]+)%/ ) {
< $PerlParsingFormat .= "$1"
---
> my $_remerge = '';
> if ( $f =~ /^([^%]*)%([\w-_]+)(.*)/ ) {
> $PerlParsingFormat .= "\Q$1\E";
> $f = "%$2";
> $_remerge = "$3";
9409a9413,9423
>
> if ($_remerge eq '') {}
> else
> {
> @f_queue = splice(@f_queue, $index + 1);
> unshift(@f_queue, $_remerge);
> $index = 0;
>
> next;
> }
> $index++;
9413a9428
>
Describe alternatives you've considered
i dont know why it was done the way it was, hopefully this means people can just cut and paste their apache log directly now shrug or not be forced to use space delims
Additional context
i was on some old prod server which was running awstats 7.6 (build 20161204), it had way to many other things based on the apache log format. if there was a way to use awstats already with the above logformat, then yes, as said, im an idiot
NB, after looking at the code and/or being lazy, i never tested with straight cut n paste, i used the above changes and
LogFormat="%v:%p [%a]:%other %other \"%u\" %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\""