lib/eris/log/decoders.pm

filter: Statementstmt 53.4% 23 / 43 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 6 / 8 Podpod 100% 1 / 1 totaltotal 44.1% 30 / 68 CC 8 SCAR 34.2
CC
8
Cov
42%
decode
56.5
_build_namespace
2.0
BEGIN
1.0
CRAP 30.7
« lib/eris/log/context/snort.pm ↑ Summary lib/eris/log/context/dhcpd.pm »
1 package eris::log::decoders;
2 # ABSTRACT: Discovery and access for decoders
3  
4 2 ▶use eris::log;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Types::Standard qw(ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 with qw(
12 eris::role::pluggable
13 );
14  
15 2 our $VERSION = '0.008'; # VERSION
16  
17  
18 0 ▶sub _build_namespace { 'eris::log::decoder' }
Subroutine _build_namespace: not called CC=1 SCAR=6.9
19  
20  
21 {
22 2 my $decoders = undef;
23 sub decode {
24 0 ▶ my ($self,$raw) = @_;
Subroutine decode: not called CC=8 SCAR=40.3
Pod documented
25  
26 # Initialize the decoders
27 0 ▶ $decoders //= $self->plugins;
Condition0%0/3
$decoders //= $self->plugins
l!l&&r!l&&!r
000
MC/DC0%0/2
$decoders //= $self->plugins
$decoders $self->plugins
Truth table0%0/3
A //= B
A= $decodersB= $self->plugins
ABresult
1X1
011
000
28  
29 # Create the log entry
30 0 my $log = eris::log->new( raw => $raw );
31  
32 # Store the decoded data
33 0 my %t=();
34 0 foreach my $decoder (@{ $decoders }) {
35 0 my $t0 = [gettimeofday];
36 0 my $data = $decoder->decode_message($raw);
37 0 my $decoder_name = "decoder_" . $decoder->name;
38 0 ▶ if( defined $data && ref $data eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data and ref $data eq "HASH") 0 0 0
Condition0%0/3
defined $data and ref $data eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data and ref $data eq "HASH"
defined $data ref $data eq "HASH"
Truth table0%0/3
A and B
A= defined $dataB= ref $data eq "HASH"
ABresult
0X0
100
111
39 # Meta Fields
40 0 foreach my $k (qw(_epoch _schema _type)) {
41 0 ▶ next unless exists $data->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $data->{$k} 0 0 0
42 0 my $meta = $k =~ s/^_//r;
43 ## no critic (ProhibitNoStrict)
44 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 0 $log->$meta( delete $data->{$k} );
46 ## use critic
47 }
48 0 ▶ $log->unix_timestamp( delete $data->{epoch} ) if $data->{epoch};
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"epoch"} 0 0 0
49 # Stash the rest of the message
50 0 $log->add_context($decoder_name => $data);
51 }
52 0 $t{$decoder_name} = tv_interval($t0);
53 }
54 0 $log->add_timing(%t);
55  
56 0 return $log; # Return the log object
57 }
58 } # end closure
59  
60  
61 2 1;
62  
63 __END__
64  
65 =pod
66  
67 =encoding UTF-8
68  
69 =head1 NAME
70  
71 eris::log::decoders - Discovery and access for decoders
72  
73 =head1 VERSION
74  
75 version 0.008
76  
77 =head1 SYNOPSIS
78  
79 Finds all available and configured decoders, returns an L<eris::log> instance from the raw string.
80  
81 use Data::Printer;
82 use eris::log::decoders;
83  
84 my $dec = eris::decoders->new();
85  
86 while(<<>>) {
87 p( $dec->decode($_) );
88 }
89  
90 =head1 ATTRIBUTES
91  
92 =head2 namespace
93  
94 Defaults to 'eris::log::decoder' to add more, configure your C<search_path>
95  
96 ---
97 decoders:
98 search_path:
99 - 'my::app::decoders'
100  
101 =head1 METHODS
102  
103 =head2 decode
104  
105 Takes a raw string and returns a decoded L<eris::log> instance.
106  
107 Stores the raw message in the C<raw> attribute of the L<eris::log> instance.
108  
109 Every decoder discovered in the C<namespace> and C<search_path> are then passed
110 the raw string to their C<decode_message()> method. The returned HashRef is recorded
111 in the new L<eris::log> instance.
112  
113 The timing of the decoding and each individual decoder is recorded with the
114 L<eris::log> C<add_timing()> method. This data is available when the
115 L<eris::dictionary::eris::debug> is enabled. When adding new decoders, it's
116 recommended to enable this dictionary for understanding the performance of the
117 decoder in real world situations.
118  
119 =head1 SEE ALSO
120  
121 L<eris::log::contextualizer>, L<eris::role::decoder>, L<eris::log>,
122 L<eris::log::decoder::syslog>, L<eris::log::decoder::json>
123  
124 =head1 AUTHOR
125  
126 Brad Lhotsky <brad@divisionbyzero.net>
127  
128 =head1 COPYRIGHT AND LICENSE
129  
130 This software is Copyright (c) 2015 by Brad Lhotsky.
131  
132 This is free software, licensed under:
133  
134 The (three-clause) BSD License
135  
136 =cut
« lib/eris/log/context/snort.pm ↑ Summary lib/eris/log/context/dhcpd.pm »