| 1 | package eris::log::decoder::syslog; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Parse the syslog headers using Parse::Syslog::Line | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Const::Fast; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Parse::Syslog::Line; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | with qw( | |||||||||||||||||||||||||||
| 10 | eris::role::decoder | ||||||||||||||||||||||||||||
| 11 | ); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | our $VERSION = '0.008'; # VERSION | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # Configure Parse::Syslog::Line | ||||||||||||||||||||||||||||
| 17 | 1 | $Parse::Syslog::Line::AutoDetectKeyValues = 1; | |||||||||||||||||||||||||||
| 18 | 1 | $Parse::Syslog::Line::DateTimeCreate = 0; | |||||||||||||||||||||||||||
| 19 | 1 | $Parse::Syslog::Line::EpochCreate = 1; | |||||||||||||||||||||||||||
| 20 | 1 | $Parse::Syslog::Line::PruneRaw = 1; | |||||||||||||||||||||||||||
| 21 | 1 | $Parse::Syslog::Line::PruneEmpty = 1; | |||||||||||||||||||||||||||
| 22 | 1 | @Parse::Syslog::Line::PruneFields = qw( | |||||||||||||||||||||||||||
| 23 | date time date_str message offset | ||||||||||||||||||||||||||||
| 24 | preamble facility_int priority_int | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub _build_priority { 100; } | ||||||||||||||||||||||||||
|
Subroutine
_build_priority: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Mappings we need to make | ||||||||||||||||||||||||||||
| 31 | 1 | const my %MAP => ( | |||||||||||||||||||||||||||
| 32 | datetime_str => 'timestamp', | ||||||||||||||||||||||||||||
| 33 | domain => 'domain', | ||||||||||||||||||||||||||||
| 34 | facility => 'facility', | ||||||||||||||||||||||||||||
| 35 | host => 'hostname', | ||||||||||||||||||||||||||||
| 36 | priority => 'severity', | ||||||||||||||||||||||||||||
| 37 | program_name => 'program', | ||||||||||||||||||||||||||||
| 38 | program_pid => 'proc_id', | ||||||||||||||||||||||||||||
| 39 | program_sub => 'proc', | ||||||||||||||||||||||||||||
| 40 | content => 'message', | ||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | sub decode_message { | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my ($self,$msg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
decode_message: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 0 | my %decoded = (); | |||||||||||||||||||||||||||
| 47 | 0 | eval { | |||||||||||||||||||||||||||
| 48 | 0 | my $m = parse_syslog_line($msg); | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | if(defined $m && ref $m) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $m and ref $m
MC/DC0%0/2
defined $m and ref $m
defined $m
ref $m
Truth table0%0/3
A and B
A= defined $mB= ref $m
| |||||||||||||||||||||||||||||
| 50 | 0 | foreach my $k (keys %{ $m }) { | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $dk = exists $MAP{$k} ? $MAP{$k} : lc $k; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | $decoded{$dk} = $m->{$k}; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | }; | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return unless exists $decoded{epoch}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | # Stash this in a safe place | ||||||||||||||||||||||||||||
| 58 | 0 | $decoded{_epoch} = delete $decoded{epoch}; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return \%decoded; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | 1; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =pod | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 NAME | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | eris::log::decoder::syslog - Parse the syslog headers using Parse::Syslog::Line | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =head1 VERSION | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | version 0.008 | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | Uses L<Parse::Syslog::Line> to parse the raw string as if it were a message | ||||||||||||||||||||||||||||
| 83 | streaming into a syslog server. This helps capture the meta-data in the syslog | ||||||||||||||||||||||||||||
| 84 | headers. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head2 priority | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Defaults to 100, or last. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head1 METHODS | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =head2 decode_message | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | Takes a raw string, decodes that message using L<Parse::Syslog::Line> and then | ||||||||||||||||||||||||||||
| 97 | remaps certain keys to "Common Event Expression" field names. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Stashes the decoded UNIX timestamp into the C<_epoch> key. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | L<eris::log::decoders>, L<eris::role::decoder>, L<Parse::Syslog::Line> | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Brad Lhotsky <brad@divisionbyzero.net> | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | This software is Copyright (c) 2015 by Brad Lhotsky. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | The (three-clause) BSD License | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =cut | ||||||||||||||||||||||||||||