line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::ApacheLog; |
2
|
3
|
|
|
3
|
|
49236
|
use Catmandu::Sane; |
|
3
|
|
|
|
|
351932
|
|
|
3
|
|
|
|
|
18
|
|
3
|
3
|
|
|
3
|
|
671
|
use Catmandu::Util qw(:is :check); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1034
|
|
4
|
3
|
|
|
3
|
|
1347
|
use Apache::Log::Parser; |
|
3
|
|
|
|
|
5340
|
|
|
3
|
|
|
|
|
72
|
|
5
|
3
|
|
|
3
|
|
13
|
use Moo; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
14
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.0112'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has formats => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => sub { check_array_ref($_[0]); }, |
14
|
|
|
|
|
|
|
required => 1, |
15
|
|
|
|
|
|
|
lazy => 1, |
16
|
|
|
|
|
|
|
default => sub { ["common","combined"]; }, |
17
|
|
|
|
|
|
|
coerce => sub { |
18
|
|
|
|
|
|
|
my $f = $_[0]; |
19
|
|
|
|
|
|
|
if ( is_string $f ) { |
20
|
|
|
|
|
|
|
$f = [ $f ]; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
$f; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
has _parser => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
init_arg => undef, |
28
|
|
|
|
|
|
|
lazy => 1, |
29
|
|
|
|
|
|
|
builder => '_build_parser', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _build_parser { |
33
|
2
|
|
|
2
|
|
660
|
my $self = $_[0]; |
34
|
2
|
|
|
|
|
8
|
Apache::Log::Parser->new(fast => $self->formats()); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub generator { |
38
|
|
|
|
|
|
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return sub { |
41
|
|
|
|
|
|
|
state $fh = $self->fh; |
42
|
|
|
|
|
|
|
state $parser = $self->_parser(); |
43
|
|
|
|
|
|
|
my $line = <$fh>; |
44
|
|
|
|
|
|
|
return unless defined $line; |
45
|
|
|
|
|
|
|
my $l = $line; |
46
|
|
|
|
|
|
|
chomp $l; |
47
|
|
|
|
|
|
|
my $r = $parser->parse($line); |
48
|
|
|
|
|
|
|
$r->{_log} = $line; |
49
|
|
|
|
|
|
|
$r; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Catmandu::Importer::ApacheLog - Catmandu importer for importing log entries |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=begin markdown |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# STATUS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
[![Build Status](https://travis-ci.org/LibreCat/Catmandu-Importer-ApacheLog.svg?branch=master)](https://travis-ci.org/LibreCat/Catmandu-Importer-ApacheLog) |
62
|
|
|
|
|
|
|
[![Coverage](https://coveralls.io/repos/LibreCat/Catmandu-Importer-ApacheLog/badge.png?branch=master)](https://coveralls.io/r/LibreCat/Catmandu-Importer-ApacheLog) |
63
|
|
|
|
|
|
|
[![CPANTS kwalitee](http://cpants.cpanauthors.org/dist/Catmandu-Importer-ApacheLog.png)](http://cpants.cpanauthors.org/dist/Catmandu-Importer-ApacheLog) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=end markdown |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This importer reads every entry in the log file, and put the log entries (status, rhost ..) into a record. |
70
|
|
|
|
|
|
|
The original line is stored in the attribute '_log'. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 METHODS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 new ( file => $file, fix => $fix, formats => ['combined','common'] ) |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=over 4 |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item file |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
File to import. Can also be a string reference or a file handle. See L<Catmandu::Importer> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item fix |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Fix to apply to every record. See L<Catmandu::Importer> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item formats |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Array reference of formats |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
By default ['combined','common'] |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
For more information see L<Apache::Log::Parser>, and look for the option 'fast'. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SYNOPSIS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#!/usr/bin/env perl |
100
|
|
|
|
|
|
|
use Catmandu::Importer::ApacheLog; |
101
|
|
|
|
|
|
|
use Data::Dumper; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::ApacheLog->new( |
104
|
|
|
|
|
|
|
file => "/var/log/httpd/access_log" |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
$importer->each(sub{ |
108
|
|
|
|
|
|
|
print Dumper(shift); |
109
|
|
|
|
|
|
|
}); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#!/bin/bash |
112
|
|
|
|
|
|
|
catmandu convert ApacheLog --file access.log to YAML |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHORS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Nicolas Franck C<< <nicolas.franck at ugent.be> >> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 SEE ALSO |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L<Catmandu>, L<Catmandu::Importer> , L<Apache::Log::Parser> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |