File Coverage

blib/lib/Ixchel/Actions/suricata_extract_submit_config.pm
Criterion Covered Total %
statement 14 36 38.8
branch 0 12 0.0
condition n/a
subroutine 5 9 55.5
pod 2 4 50.0
total 21 61 34.4


line stmt bran cond sub pod time code
1             package Ixchel::Actions::suricata_extract_submit_config;
2              
3 1     1   124709 use 5.006;
  1         4  
4 1     1   14 use strict;
  1         2  
  1         47  
5 1     1   6 use warnings;
  1         4  
  1         64  
6 1     1   563 use File::Slurp;
  1         47941  
  1         91  
7 1     1   10 use base 'Ixchel::Actions::base';
  1         2  
  1         631  
8              
9             =head1 NAME
10              
11             Ixchel::Actions::suricata_extract_submit_config - Generates the config file for suricata_extract_submit.
12              
13             =head1 VERSION
14              
15             Version 0.1.0
16              
17             =cut
18              
19             our $VERSION = '0.1.0';
20              
21             =head1 CLI SYNOPSIS
22              
23             ixchel -a suricata_extract_submit_config
24              
25             ixchel -a suricata_extract_submit_config B<-w> [B<-o> ]
26              
27             =head1 CODE SYNOPSIS
28              
29             my $results=$ixchel->action(action=>'suricata_extract_submit_config', opts=>{w=>1});
30              
31             if ($results->{ok}) {
32             print $results->{filled_in};
33             }else{
34             die('Action errored... '.joined("\n", @{$results->{errors}}));
35             }
36              
37             =head1 DESCRIPTION
38              
39             The template used is 'suricata_extract_submit'.
40              
41             The returned value is the filed in template.
42              
43             =head1 FLAGS
44              
45             =head2 -w
46              
47             Write out the file instead of stdout.
48              
49             =head2 -o
50              
51             File to write the out to if -w is specified.
52              
53             Default :: /usr/local/etc/suricata_extract_submit.ini
54              
55             =head1 RESULT HASH REF
56              
57             .errors :: A array of errors encountered.
58             .status_text :: A string description of what was done and the results.
59             .ok :: Set to zero if any of the above errored.
60             .filled_in :: The filled in template.
61              
62             =cut
63              
64       0 0   sub new_extra { }
65              
66             sub action_extra {
67 0     0 0   my $self = $_[0];
68              
69             # set the default output for -o if not defined
70 0 0         if ( !defined( $self->{opts}{o} ) ) {
71 0           $self->{opts}{o} = '/usr/local/etc/suricata_extract_submit.ini';
72             }
73              
74             # set the default output for -o if not defined
75 0 0         if ( !defined( $self->{opts}{w} ) ) {
76 0           $self->{opts}{w} = 0;
77             }
78              
79 0           my $filled_in;
80 0           eval {
81             $filled_in = $self->{ixchel}->action(
82 0           action => 'template',
83             vars => {},
84             opts => {
85             np => 1,
86             t => 'suricata_extract_submit',
87             },
88             );
89             };
90 0 0         if ($@) {
91 0           $self->status_add( status => 'Failed to fill out template suricata_extract_submit ... ' . $@, error => 1 );
92 0           return undef;
93             }
94              
95 0           $self->{results}{filled_in} = $filled_in;
96              
97 0 0         if ( !$self->{opts}{np} ) {
98 0           print $filled_in;
99             }
100              
101 0 0         if ( $self->{opts}{w} ) {
102 0           eval { write_file( $self->{opts}{o}, $filled_in ); };
  0            
103 0 0         if ($@) {
104             $self->status_add(
105 0           status => 'Failed to write out filled in template to "' . $self->{opts}{o} . '" ... ' . $@,
106             error => 1
107             );
108             }
109             }
110              
111 0           return undef;
112             } ## end sub action_extra
113              
114             sub short {
115 0     0 1   return 'Generates the config file for suricata_extract_submit.';
116             }
117              
118             sub opts_data {
119 0     0 1   return '
120             w
121             o=s
122             ';
123             }
124              
125             1;