File Coverage

blib/lib/Log/Saftpresse/Input/Journald.pm
Criterion Covered Total %
statement 6 21 28.5
branch 0 6 0.0
condition 0 6 0.0
subroutine 2 3 66.6
pod 0 1 0.0
total 8 37 21.6


line stmt bran cond sub pod time code
1             package Log::Saftpresse::Input::Journald;
2              
3 1     1   1650 use Moose;
  1         2  
  1         10  
4              
5             # ABSTRACT: log input for systemd-journald
6             our $VERSION = '1.6'; # VERSION
7              
8              
9 1     1   5900 use JSON;
  1         4  
  1         14  
10              
11             extends 'Log::Saftpresse::Input::Command';
12              
13             has 'command' => ( is => 'ro', isa => 'Str', default => 'journalctl -f -o json');
14              
15             has 'lowercase' => ( is => 'ro', isa => 'Bool', default => 1 );
16             has 'remove_address_fields' => ( is => 'ro', isa => 'Bool', default => 1 );
17             has 'merge_trusted_fields' => ( is => 'ro', isa => 'Bool', default => 1 );
18              
19             sub process_line {
20 0     0 0   my ( $self, $line ) = @_;
21 0           my $data = from_json( $line );
22 0 0         if( $self->lowercase ) {
23 0           my %new = map { lc $_ => $data->{$_} } keys %$data;
  0            
24 0           $data = \%new;
25             }
26 0           foreach my $key ( keys %$data ) {
27 0 0 0       if( $self->remove_address_fields && $key =~ /^__/ ) {
28 0           delete( $data->{$key} );
29             }
30 0 0 0       if( $self->merge_trusted_fields && $key =~ /^_[^_]/ ) {
31 0           my $newkey = $key;
32 0           $newkey =~ s/^_//;
33 0           $data->{$newkey} = $data->{$key};
34 0           delete( $data->{$key} );
35             }
36             }
37 0           return %$data;
38             }
39              
40             1;
41              
42             __END__
43              
44             =pod
45              
46             =encoding UTF-8
47              
48             =head1 NAME
49              
50             Log::Saftpresse::Input::Journald - log input for systemd-journald
51              
52             =head1 VERSION
53              
54             version 1.6
55              
56             =head1 Description
57              
58             This input will read events from the systemd journal.
59              
60             =head1 Synopsis
61              
62             <Input systemd>
63             module = "Journald"
64             </Input>
65              
66             =head1 Parameters
67              
68             =over
69              
70             =item lowercase (default: 1)
71              
72             Systemd fields will be transformed to lowercase.
73              
74             =item remove_address_fields (default: 1)
75              
76             Remove systemd journal address informations.
77              
78             =item merge_trusted_fields (default: 1)
79              
80             Will remove the "_" prefix of systemd trusted fields.
81              
82             =back
83              
84             =head1 AUTHOR
85              
86             Markus Benning <ich@markusbenning.de>
87              
88             =head1 COPYRIGHT AND LICENSE
89              
90             This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
91              
92             This is free software, licensed under:
93              
94             The GNU General Public License, Version 2, June 1991
95              
96             =cut