| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Message::Passing::Filter::ToLogstash; |
|
2
|
2
|
|
|
2
|
|
27140
|
use Moo; |
|
|
2
|
|
|
|
|
12228
|
|
|
|
2
|
|
|
|
|
13
|
|
|
3
|
2
|
|
|
2
|
|
2060
|
use MooX::Types::MooseLike::Base qw/ ArrayRef /; |
|
|
2
|
|
|
|
|
5056
|
|
|
|
2
|
|
|
|
|
173
|
|
|
4
|
2
|
|
|
2
|
|
1178
|
use List::MoreUtils qw/ uniq /; |
|
|
2
|
|
|
|
|
18304
|
|
|
|
2
|
|
|
|
|
22
|
|
|
5
|
2
|
|
|
2
|
|
2606
|
use DateTime; |
|
|
2
|
|
|
|
|
187928
|
|
|
|
2
|
|
|
|
|
86
|
|
|
6
|
2
|
|
|
2
|
|
481
|
use Sys::Hostname::Long; |
|
|
2
|
|
|
|
|
2122
|
|
|
|
2
|
|
|
|
|
124
|
|
|
7
|
2
|
|
|
2
|
|
440
|
use namespace::clean -except => 'meta'; |
|
|
2
|
|
|
|
|
6272
|
|
|
|
2
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
435
|
use constant HOSTNAME => hostname_long(); |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
9
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Message::Passing::Role::Filter'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has default_tags => ( |
|
14
|
|
|
|
|
|
|
is => 'ro', |
|
15
|
|
|
|
|
|
|
isa => ArrayRef, |
|
16
|
|
|
|
|
|
|
default => sub { [] }, |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has add_tags => ( |
|
20
|
|
|
|
|
|
|
is => 'ro', |
|
21
|
|
|
|
|
|
|
isa => ArrayRef, |
|
22
|
|
|
|
|
|
|
default => sub { [] }, |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %map = ( |
|
26
|
|
|
|
|
|
|
'__CLASS__' => [ 'perl:Class:', 'type' ], |
|
27
|
|
|
|
|
|
|
hostname => 'source_host', |
|
28
|
|
|
|
|
|
|
message => 'message', |
|
29
|
|
|
|
|
|
|
filename => 'source_path', |
|
30
|
|
|
|
|
|
|
date => 'timestamp', |
|
31
|
|
|
|
|
|
|
type => 'type', |
|
32
|
|
|
|
|
|
|
); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub filter { |
|
35
|
6
|
|
|
6
|
1
|
7
|
my ($self, $message) = @_; |
|
36
|
6
|
100
|
|
|
|
16
|
if ('HASH' ne ref($message)) { |
|
37
|
1
|
|
|
|
|
3
|
my $line = $message; |
|
38
|
1
|
|
|
|
|
7
|
$message = { |
|
39
|
|
|
|
|
|
|
message => $line, |
|
40
|
|
|
|
|
|
|
hostname => HOSTNAME, |
|
41
|
|
|
|
|
|
|
epochtime => AnyEvent->now, |
|
42
|
|
|
|
|
|
|
type => 'generic_line', |
|
43
|
|
|
|
|
|
|
}; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
6
|
|
|
|
|
28
|
$message = { '@fields' => { %$message } }; |
|
46
|
6
|
100
|
|
|
|
18
|
if (exists($message->{'@fields'}{epochtime})) { |
|
47
|
2
|
|
|
|
|
17
|
$message->{'@timestamp'} = DateTime->from_epoch(epoch => delete($message->{'@fields'}{epochtime})) . '' |
|
48
|
|
|
|
|
|
|
} |
|
49
|
6
|
|
|
|
|
667
|
foreach my $k (keys %map) { |
|
50
|
36
|
|
|
|
|
31
|
my $v = $map{$k}; |
|
51
|
36
|
100
|
|
|
|
64
|
$v = [ '', $v ] if !ref $v; |
|
52
|
36
|
|
|
|
|
40
|
my ($prefix, $field) = @$v; |
|
53
|
36
|
|
|
|
|
32
|
$field = '@' . $field; |
|
54
|
36
|
100
|
66
|
|
|
100
|
if (exists($message->{'@fields'}{$k}) && !exists($message->{$field})) { |
|
55
|
8
|
|
|
|
|
24
|
$message->{$field} = $prefix . delete $message->{'@fields'}{$k}; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
6
|
|
33
|
|
|
33
|
$message->{'@tags'} ||= $self->default_tags; |
|
59
|
6
|
|
|
|
|
5
|
$message->{'@tags'} = [ uniq @{ $message->{'@tags'} }, @{ $self->add_tags } ]; |
|
|
6
|
|
|
|
|
9
|
|
|
|
6
|
|
|
|
|
23
|
|
|
60
|
|
|
|
|
|
|
|
|
61
|
6
|
|
|
|
|
14
|
$message; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 NAME |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Method::Passing::Filter::ToLogstash |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This filter changes the message format to comply with LogStash. |
|
73
|
|
|
|
|
|
|
Duplicate tags will be removed. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 default_tags |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This is the list of tags which get added to the messages' @tags field in case |
|
80
|
|
|
|
|
|
|
none have been included already. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 add_tags |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This is the list of tags which get added to the messages' @tags field in all |
|
85
|
|
|
|
|
|
|
cases. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 METHODS |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 filter |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Filter the message. |
|
92
|
|
|
|
|
|
|
|