File Coverage

blib/lib/Ixchel/Actions/snmp_v2.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::snmp_v2;
2              
3 1     1   119182 use 5.006;
  1         5  
4 1     1   11 use strict;
  1         3  
  1         32  
5 1     1   4 use warnings;
  1         2  
  1         64  
6 1     1   578 use File::Slurp;
  1         45119  
  1         131  
7 1     1   12 use base 'Ixchel::Actions::base';
  1         2  
  1         628  
8              
9             =head1 NAME
10              
11             Ixchel::Actions::snmp_v2 - Generates a config file SNMPD.
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 snmp_v2
24              
25             ixchel -a snmp_v2 B<-w> [B<-o> ] [B<--np>]
26              
27             =head1 CODE SYNOPSIS
28              
29             my $filled_in=$ixchel->action(action=>'snmp_v2', opts=>{w=>1});
30              
31             print $filled_in;
32              
33             =head1 DESCRIPTION
34              
35             The template used is 'snmp_v2'.
36              
37             The returned value is the filled in template..
38              
39             =head1 FLAGS
40              
41             =head2 -w
42              
43             Write out the file instead of stdout.
44              
45             =head2 -o
46              
47             File to write the out to if -w is specified.
48              
49             Default :: /usr/local/etc/snmpd.conf
50              
51             Linux Default :: /etc/snmp/snmpd.conf
52              
53             =head2 --np
54              
55             Don't print the the filled in template.
56              
57             =head1 RESULT HASH REF
58              
59             .errors :: A array of errors encountered.
60             .status_text :: A string description of what was done and the results.
61             .ok :: Set to zero if any of the above errored.
62             .filled_in :: The filled in template.
63              
64             =cut
65              
66       0 0   sub new_extra { }
67              
68             sub action_extra {
69 0     0 0   my $self = $_[0];
70              
71             # set the default output for -o if not defined
72 0 0         if ( !defined( $self->{opts}{o} ) ) {
73 0           $self->{opts}{o} = $self->{config}{snmp}{config_file};
74             }
75              
76             # set the default output for -o if not defined
77 0 0         if ( !defined( $self->{opts}{w} ) ) {
78 0           $self->{opts}{w} = 0;
79             }
80              
81 0           my $filled_in;
82 0           eval {
83             $filled_in = $self->{ixchel}->action(
84 0           action => 'template',
85             vars => {},
86             opts => {
87             np => 1,
88             t => 'snmp_v2',
89             },
90             );
91             };
92 0 0         if ($@) {
93 0           $self->status_add(
94             error => 1,
95             status => 'Filling in the template failed... ' . $@
96             );
97 0           return undef;
98             }
99              
100 0           $self->{results}{filled_in} = $filled_in;
101              
102 0 0         if ( !$self->{opts}{np} ) {
103 0           print $filled_in;
104             }
105              
106 0 0         if ( $self->{opts}{w} ) {
107 0           eval { write_file( $self->{opts}{o}, $filled_in ); };
  0            
108 0 0         if ($@) {
109             $self->status_add(
110             error => 1,
111 0           status => 'Writing out config to "' . $self->{opts}{o} . '" failed ... ' . $@
112             );
113             }
114             }
115              
116 0           return undef;
117             } ## end sub action_extra
118              
119             sub short {
120 0     0 1   return 'Generates a config file SNMPD.';
121             }
122              
123             sub opts_data {
124 0     0 1   return '
125             w
126             np
127             o=s
128             ';
129             }
130              
131             1;