/usr/share/perl5/Lire/Proxy/SquidAccessDlfConverter.pm is in lire 2:2.1.1-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | package Lire::Proxy::SquidAccessDlfConverter;
use strict;
use Lire::DlfConverter;
use Carp;
use Lire::Utils qw/parse_url/;
use base qw/Lire::DlfConverter/;
sub new {
return bless {}, shift;
}
sub name { 'squid_access' }
sub title { 'Squid proxy access log' }
sub description { '<para>Squid proxy access log</para>' }
sub schemas { qw/proxy/ }
sub handle_log_lines { 1 }
sub init_dlf_converter { }
sub process_log_line {
my ($self, $process, $line) = @_;
# Skip empty lines
if ( $line =~ /^(\s*$|#)/ ) {
$self->ignore_log_line( $line );
return;
}
eval {
my (%dlf, $urlstring, $source, $type);
# 979992041.366 502 192.168.1.160 TCP_IMS_HIT/304 216
# GET http://www.example.com/home2.html - DIRECT/www.example.net
# text/html
(
$dlf{'time'},
$dlf{'duration'},
$dlf{'client_ip'},
$dlf{'cache_result'}, # to do: normalise this with ms_isa
$dlf{'req_result'},
$dlf{'bytes'},
$dlf{'operation'},
$urlstring,
$dlf{'user'},
$source,
$type,
) = $line =~ m|^
([0-9]+)\.[0-9]*\s+ # time (drop the milliseconds)
([0-9]+)\s+ # elapsed
([^ ]+)\s+ # remotehost
([A-Z_]+)\/ # cache_result (e.g. TCP_MISS)
([0-9-]+)\s+ # http_status (e.g. 503). Netcache may use -
([0-9]+)\s+ # bytes
([A-Z_]+)\s+ # method (e.g. GET)
(\S+)\s+ # url
([^ ]+)\s+ # rfc931
([^ ]+)\s+ # Result Src Code/Peer
# Some logs also contains -
(.*) # mime type
$|x or die 'squid lexer failed';
$dlf{'duration'} = sprintf '%.3f', $dlf{'duration'} / 1000;
$dlf{'client_host'} = $dlf{'client_ip'};
if( $dlf{'operation'} eq 'CONNECT' ) {
my ( $host, $port ) = split /:/, $urlstring;
$dlf{'dst_host'} = $host;
$dlf{'port'} = $port;
if ($port == 443) {
# We cannot be sure of this actually
$dlf{'protocol'} = 'https';
} else {
$dlf{'protocol'} = 'connect';
}
} else {
my $url = parse_url( $urlstring );
$dlf{'protocol'} = $url->{'scheme'}
if $url->{'scheme'};
$dlf{'dst_host'} = $url->{'host'}
if $url->{'host'};
$dlf{'requested_url'} = $url->{'path'}
if $url->{'path'};
$dlf{'dst_port'} = $url->{'port'}
if $url->{'port'};
}
# Handle Netcache quoted MIME type
if ( $type =~ /^"([^"]+)"\s*$/ ) {
$type = $1
}
$dlf{'type'} = $type;
my $peer;
(
$dlf{'result_src_code'},
$peer
) = $source =~ m|^
([A-Z_]+)/ # result_src_code, aka
# cache_result_code (e.g.
# NONE or DIRECT)
([-0-9a-zA-Z\.]+) # peer (could be host, ip or
# can be just '-')
$|x;
if ( $dlf{'result_src_code'} ) {
if ($peer =~ /^(\d{1,3}\.){3}\d{1,3}$/) {
# looks like an ip adress
$dlf{'result_src_ip'} = $peer;
$dlf{'result_src_host'} = $peer;
} else {
$dlf{'result_src_host'} = $peer;
}
} else {
# FIXME: Is this really what Netcache - means?
$dlf{'result_src_code'} = 'NONE';
}
$process->write_dlf( 'proxy', \%dlf )
};
if($@) {
$process->error($line, $@);
}
}
sub finish_conversion { }
1; # nag nag.
__END__
=pod
=head1 NAME
Lire::Proxy::SquidAccessDlfConverter - convert squid logs to dlf format
=head1 DESCRIPTION
squid_access2dlf expects an access.log log file, as produced by the SQUID Web Proxy
Cache (http://www.squid-cache.org/) on its stdin.
These log files are whitespace separated, columns are
time elapsed remotehost code/status bytes method URL rfc931
peerstatus/peerhost type
A typical logline looks like e.g.:
979992041.366 502 192.168.1.160 TCP_IMS_HIT/304 216 GET
http://example.com/home2.html - NONE/- text/html
Meaning of fields is:
=over
=item time
A Unix timestamp as UTC seconds with a millisecond resolution.
=item elapsed
The elapsed time considers how many milliseconds the transaction busied the
cache.
=item remotehost
The IP address of the requesting instance, the client IP address.
=item code/status
This column is made up of two entries separated by a slash. This column encodes
the transaction result.
The cache result of the request contains information on the kind of request,
how it was satisfied, or in what way it failed. The status part contains the
HTTP result codes with some Squid specific extensions. Squid uses a subset of
the RFC defined error codes for HTTP.
=over
=item TCP_HIT
A valid copy of the requested object was in the cache.
=item TCP_MISS
The requested object was not in the cache.
=item TCP_REFRESH_HIT
The requested object was cached but STALE. The IMS query for the object
resulted in "304 not modified".
=item TCP_REF_FAIL_HIT
The requested object was cached but STALE. The IMS query failed and the stale
object was delivered.
=item TCP_REFRESH_MISS
The requested object was cached but STALE. The IMS query returned the new
content.
=item TCP_CLIENT_REFRESH_MISS
The client issued a "no-cache" pragma, or some analogous cache control command
along with the request. Thus, the cache has to refetch the object.
=item TCP_IMS_HIT
The client issued an IMS request for an object which was in the cache and
fresh.
=item TCP_SWAPFAIL_MISS
The object was believed to be in the cache, but could not be accessed.
=item TCP_NEGATIVE_HIT
Request for a negatively cached object, e.g. "404 not found", for which the
cache believes to know that it is inaccessible.
=item TCP_MEM_HIT
A valid copy of the requested object was in the cache and it was in memory,
thus avoiding disk accesses.
=item TCP_DENIED
Access was denied for this request.
=item TCP_OFFLINE_HIT
The requested object was retrieved from the cache during offline mode. The
offline mode never validates any object, see offline_mode in squid.conf file.
=item UDP_HIT
A valid copy of the requested object was in the cache.
=item UDP_MISS
The requested object is not in this cache.
=item UDP_DENIED
Access was denied for this request.
=item UDP_INVALID
An invalid request was received.
=item UDP_MISS_NOFETCH
During "C<-Y>" startup, or during frequent failures, a cache in hit only mode
will return either UDP_HIT or this code. Neighbours will thus only fetch hits.
=item NONE
Seen with errors and cachemgr requests.
=back
=item bytes
The size is the amount of data delivered to the client. Mind that this does not
constitute the net object size, as headers are also counted.
=item method
The request method to obtain an object. Methods are:
method defined cachabil. meaning
--------- ---------- ---------- --------------------
GET HTTP/0.9 possibly object retrieval and simple searches.
HEAD HTTP/1.0 possibly metadata retrieval.
POST HTTP/1.0 CC or Exp. submit data (to a program).
PUT HTTP/1.1 never upload data (e.g. to a file).
DELETE HTTP/1.1 never remove resource (e.g. file).
TRACE HTTP/1.1 never appl. layer trace of request route.
OPTIONS HTTP/1.1 never request available comm. options.
CONNECT HTTP/1.1r3 never tunnel SSL connection.
ICP_QUERY Squid never used for ICP based exchanges.
PURGE Squid never remove object from cache.
PROPFIND rfc2518 ? retrieve properties of an object.
PROPATCH rfc2518 ? change properties of an object.
MKCOL rfc2518 never create a new collection.
MOVE rfc2518 never create a duplicate of src in dst.
COPY rfc2518 never atomically move src to dst.
LOCK rfc2518 never lock an object against modifications.
UNLOCK rfc2518 never unlock an object.
=item URL
This column contains the URL requested. Please note that the log file may
contain whitespaces for the URI. In the Lire DLF the URL is split up in
proto, host and path.
=item rfc931
The eighth column may contain the ident lookups for the requesting client.
=item peerstatus/peerhost
results from neighbouring caches.
=item type
The content type of the object as seen in the HTTP reply header.
=back
=head1 EXAMPLES
To process a log as produced by Squid:
$ squid_access2dlf < squid.log
squid_access2dlf will be rarely used on its own, but is more likely
called by lr_log2report:
$ cat /var/log/squid.log | lr_run lr_log2report squid_access
=head1 VERSION
$Id: SquidAccessDlfConverter.pm,v 1.8 2008/06/12 15:04:32 wraay Exp $
=head1 AUTHORS
Joost Bekkers <joost@jodocus.org>
Joost van Baal <joostvb@logreport.org>
Wessel Dankers <wsl@logreport.org>
=head1 COPYRIGHT
Copyright (C) 2001 Joost Bekkers <joost@jodocus.org>
Copyright (C) 2001-2003 Stichting LogReport Foundation LogReport@LogReport.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (see COPYING); if not, check with
http://www.gnu.org/copyleft/gpl.html.
=cut
# Local Variables:
# mode: cperl
# End:
|