File Coverage

blib/lib/Ixchel/Actions/extend_smart_config.pm
Criterion Covered Total %
statement 14 38 36.8
branch 0 14 0.0
condition n/a
subroutine 5 9 55.5
pod 2 4 50.0
total 21 65 32.3


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