lib/Log/Munger/App/Command/grok2rules.pm

filter: Statementstmt 86.2% 25 / 29 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 80.0% 4 / 5 totaltotal 79.5% 39 / 49 CC 4 SCAR 8.2
CC
4
Cov
80%
execute
4.3
abstract
2.0
description
2.0
CRAP 2.3
« lib/Log/Munger/App.pm ↑ Summary lib/Log/Munger/App/Command.pm »
1 package Log::Munger::App::Command::grok2rules;
2  
3 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use Log::Munger::App -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use Log::Munger::Degrok ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
9 return (
10 2 [ 'f=s', 'Grok patterns file to convert.' ],
11 [ 'includes|i=s@', 'Rule file to treat as an include when resolving/overwriting (repeatable).' ],
12 [
13 'overwrite|o=s',
14 'Overwrite policy for names already in an include: yes|no_silent|no_warn|no_die.',
15 { default => 'no_warn' }
16 ],
17 );
18 } ## end sub opt_spec
19  
20 0 ▶sub abstract { "Convert a grok patterns file into a Log::Munger rules YAML skeleton" }
Subroutine abstract: not called CC=1 SCAR=6.9
Pod documented
21  
22 0 ▶sub description {
Subroutine description: not called CC=1 SCAR=6.9
Pod documented
23 0 "Turns a grok patterns file, a list of 'NAME regexp' lines, into the skeleton of a rule file.
24 Plain lines become vars, lines referencing other patterns become vars_templated once they have
25 been degrokked, and the result is printed to stdout as YAML.
26  
27 Naming what you already have with -i is worth doing. Most grok patterns files carry their own
28 copies of IP, WORD, HOSTNAME and the rest, and without the includes those all come across and
29 shadow the ones in base.
30  
31 What comes back is a skeleton. There is no rules section, no gates and no tests, because none
32 of that exists in a grok patterns file to convert.
33 ";
34 } ## end sub description
35  
36 2 ▶sub validate { return 1 }
Subroutine validate: called CC=1 SCAR=0.0
Pod undocumented
37  
38 2 ▶sub execute {
Subroutine execute: called CC=4 SCAR=14.7
Pod documented
39 2 my ( $self, $opts, $args ) = @_;
40  
41 2 ▶ if ( !defined( $opts->{'f'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts->{"f"}) 0 2 2
42 0 die('No grok file specified via -f');
43 }
44  
45 2 my %pass = ( 'file' => $opts->{'f'}, 'overwrite' => $opts->{'overwrite'} );
46 2 ▶ $pass{'includes'} = $opts->{'includes'} if ( defined( $opts->{'includes'} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"includes"} 0 2 2
47  
48 2 my $yaml;
49 2 eval { $yaml = Log::Munger::Degrok->grok2rules(%pass); };
50 2 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 2 2
51 0 die( 'Failed to convert "' . $opts->{'f'} . '"... ' . $@ );
52 }
53  
54 2 print $yaml;
55  
56 2 return;
57 } ## end sub execute
58  
59 16 1;
« lib/Log/Munger/App.pm ↑ Summary lib/Log/Munger/App/Command.pm »