lib/eris/log/context/crond.pm

filter: Statementstmt 39.1% 9 / 23 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 40.0% 2 / 5 Podpod 50.0% 1 / 2 totaltotal 35.2% 12 / 34 CC 3 SCAR 17.9
CC
3
Cov
33%
contextualize_message
12.0
_build_matcher
2.0
sample_messages
2.0
CRAP 6.0
« lib/eris/role/schema.pm ↑ Summary lib/eris/log/context/yum.pm »
1 package eris::log::context::crond;
2 # ABSTRACT: Parse crond messages to structured data
3  
4 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 with qw(
6 eris::role::context
7 );
8 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '0.008'; # VERSION
11  
12  
13 sub _build_matcher {
14 0 ▶ [qw(crond cron CROND /usr/sbin/cron /USR/SBIN/CRON)]
Subroutine _build_matcher: not called CC=1 SCAR=6.9
15 }
16  
17  
18 sub sample_messages {
19 0 ▶ my @msgs = split /\r?\n/, <<'EOF';
Subroutine sample_messages: not called CC=1 SCAR=6.9
Pod undocumented
20 Nov 24 01:00:01 janus CROND[30472]: (root) CMD (/usr/lib64/sa/sa1 1 1)
21 Nov 24 01:01:01 janus CROND[30689]: (root) CMD (run-parts /etc/cron.hourly)
22 Nov 24 01:01:01 janus CROND[30690]: (root) CMD (/usr/local/bin/linux_basic_performance_data.sh)
23 EOF
24 0 return @msgs;
25 }
26  
27  
28 sub contextualize_message {
29 0 ▶ my ($self,$log) = @_;
Subroutine contextualize_message: not called CC=3 SCAR=24.8
Pod documented
30 0 my $str = $log->context->{message};
31  
32 0 my %ctxt = ();
33 0 ▶ if( $str =~ / CMD / ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ / CMD /) 0 0 0
34 0 my @parts = map { s/(?:^\()|(?:\)$)//rg } split / CMD /, $str;
35 0 $ctxt{src_user} = $parts[0];
36 0 $ctxt{exe} = $parts[1];
37 0 $ctxt{file} = (split /\s+/, $parts[1])[0];
38 0 $ctxt{action} = 'execute';
39 }
40  
41 0 ▶ $log->add_context($self->name,\%ctxt) if keys %ctxt;
Branch: 1 branch
BranchTrueFalseTotal
if keys %ctxt 0 0 0
42 }
43  
44  
45 1 1;
46  
47 __END__
48  
49 =pod
50  
51 =encoding UTF-8
52  
53 =head1 NAME
54  
55 eris::log::context::crond - Parse crond messages to structured data
56  
57 =head1 VERSION
58  
59 version 0.008
60  
61 =head1 SYNOPSIS
62  
63 Parses the crond execution log file entries into structured data
64  
65 =head1 ATTRIBUTES
66  
67 =head2 matcher
68  
69 Matches 'cron', 'CROND', '/usr/sbin/cron'
70  
71 =head1 METHODS
72  
73 =head2 contextualize_message
74  
75 Parses the crond log messages specifying what was run into:
76  
77 src_user => User executing
78 exe => Full command as run by cron
79 file => Just the executeable without arguments
80  
81 =for Pod::Coverage sample_messages
82  
83 =head1 SEE ALSO
84  
85 L<eris::log::contextualizer>, L<eris::role::context>
86  
87 =head1 AUTHOR
88  
89 Brad Lhotsky <brad@divisionbyzero.net>
90  
91 =head1 COPYRIGHT AND LICENSE
92  
93 This software is Copyright (c) 2015 by Brad Lhotsky.
94  
95 This is free software, licensed under:
96  
97 The (three-clause) BSD License
98  
99 =cut
« lib/eris/role/schema.pm ↑ Summary lib/eris/log/context/yum.pm »