lib/eris/log/context/sudo.pm

filter: Statementstmt 44.8% 13 / 29 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 3 / 5 Podpod 50.0% 1 / 2 totaltotal 38.6% 17 / 44 CC 6 SCAR 32.5
CC
6
Cov
35%
contextualize_message
42.0
sample_messages
2.0
BEGIN
1.0
CRAP 25.7
« lib/eris/log/context/dhcpd.pm ↑ Summary lib/eris/log/decoder/syslog.pm »
1 package eris::log::context::sudo;
2 # ABSTRACT: Parses the sudo key=value pairs into structured documents
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 with qw(
7 eris::role::context
8 );
9 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.008'; # VERSION
12  
13  
14 sub sample_messages {
15 0 ▶ my @msgs = split /\r?\n/, <<'EOF';
Subroutine sample_messages: not called CC=1 SCAR=6.9
Pod undocumented
16 Sep 10 19:59:02 ether sudo: brad : TTY=pts/5 ; PWD=/home/brad ; USER=root ; COMMAND=/bin/grep -i sudo /var/log/messages
17 Sep 10 19:59:05 ether sudo: brad : TTY=pts/5 ; PWD=/home/brad ; USER=root ; COMMAND=/bin/grep -i sudo /var/log/secure
18 EOF
19 0 return @msgs;
20 }
21  
22  
23 1 const my %MAP => (
24 TTY => 'dev',
25 COMMAND => 'exe',
26 PWD => 'location',
27 USER => 'dst_user',
28 );
29  
30 sub contextualize_message {
31 0 ▶ my ($self,$log) = @_;
Subroutine contextualize_message: not called CC=6 SCAR=37.4
Pod documented
32 0 my $c = $log->context;
33 0 my $sdata = $c->{sdata};
34 0 my $str = $c->{message};
35  
36 0 my %ctxt = ();
37  
38 0 my ($user,$variables) = split ' : ', $str, 2;
39 0 foreach my $k (sort keys %MAP) {
40 0 ▶ if( exists $sdata->{$k} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $sdata->{$k}) 0 0 0
41 0 $ctxt{$MAP{$k}} = $sdata->{$k};
42 }
43 }
44 0 ▶ if( exists $ctxt{exe} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ctxt{"exe"}) 0 0 0
45 0 $ctxt{file} = (split /\s+/, $ctxt{exe})[0];
46 0 $ctxt{action} = 'execute';
47 }
48 0 ▶ $ctxt{src_user} = $user if $user;
Branch: 1 branch
BranchTrueFalseTotal
if $user 0 0 0
49  
50 0 ▶ $log->add_context($self->name,\%ctxt) if keys %ctxt;
Branch: 1 branch
BranchTrueFalseTotal
if keys %ctxt 0 0 0
51 }
52  
53  
54 1 1;
55  
56 __END__
57  
58 =pod
59  
60 =encoding UTF-8
61  
62 =head1 NAME
63  
64 eris::log::context::sudo - Parses the sudo key=value pairs into structured documents
65  
66 =head1 VERSION
67  
68 version 0.008
69  
70 =head1 SYNOPSIS
71  
72 Translates the sudo syslog lines containing "key=value" to structured documents.
73  
74 =head1 METHODS
75  
76 =head2 contextualize_message
77  
78 Transforms the sudo syslog messages into structured data.
79  
80 dev => TTY
81 exe => COMMAND
82 location => PWD
83 dst_user => USER
84 src_user => from the syslog header
85 action => literal string 'execute'
86 file => extracts just the executeable from the 'exe' parameter
87  
88 =for Pod::Coverage sample_messages
89  
90 =head1 SEE ALSO
91  
92 L<eris::log::contextualizer>, L<eris::role::context>
93  
94 =head1 AUTHOR
95  
96 Brad Lhotsky <brad@divisionbyzero.net>
97  
98 =head1 COPYRIGHT AND LICENSE
99  
100 This software is Copyright (c) 2015 by Brad Lhotsky.
101  
102 This is free software, licensed under:
103  
104 The (three-clause) BSD License
105  
106 =cut
« lib/eris/log/context/dhcpd.pm ↑ Summary lib/eris/log/decoder/syslog.pm »