File Coverage

blib/lib/Ixchel/Actions/snmp_install.pm
Criterion Covered Total %
statement 17 42 40.4
branch 0 8 0.0
condition 0 18 0.0
subroutine 6 10 60.0
pod 2 4 50.0
total 25 82 30.4


line stmt bran cond sub pod time code
1             package Ixchel::Actions::snmp_install;
2              
3 1     1   117339 use 5.006;
  1         4  
4 1     1   6 use strict;
  1         2  
  1         43  
5 1     1   7 use warnings;
  1         2  
  1         62  
6 1     1   603 use Rex::Commands::Gather;
  1         175998  
  1         8  
7 1     1   1343 use Rex::Commands::Pkg;
  1         10109  
  1         10  
8 1     1   712 use base 'Ixchel::Actions::base';
  1         2  
  1         45  
9              
10             # prevents Rex from printing out rex is exiting after the script ends
11             $::QUIET = 2;
12              
13             =head1 NAME
14              
15             Ixchel::Actions::snmp_install - Installs snmpd and snmp utils.
16              
17             =head1 VERSION
18              
19             Version 0.1.0
20              
21             =cut
22              
23             our $VERSION = '0.1.0';
24              
25             =head1 SYNOPSIS
26              
27             use Data::Dumper;
28              
29             my $results=$ixchel->action(action=>'snmp_install', opts=>{});
30              
31             print Dumper($results);
32              
33             =head1 RESULT HASH REF
34              
35             .errors :: A array of errors encountered.
36             .status_text :: A string description of what was done and the results.
37             .ok :: Set to zero if any of the above errored.
38              
39             =cut
40              
41       0 0   sub new_extra { }
42              
43             sub action_extra {
44 0     0 0   my $self = $_[0];
45              
46 0           $self->status_add( status => 'Installing snmp utils and snmpd' );
47              
48 0           my @depends = ();
49              
50 0 0 0       if ( is_freebsd || is_netbsd || is_freebsd ) {
    0 0        
    0 0        
      0        
      0        
      0        
51 0           $self->status_add( status => 'OS Family FreeBSD, NetBSD, or OpenBSD detectected' );
52 0           push( @depends, 'net-snmp' );
53             } elsif (is_debian) {
54 0           $self->status_add( status => 'OS Family Debian detectected' );
55 0           push( @depends, 'snmp', 'snmpd' );
56             } elsif ( is_redhat || is_arch || is_suse || is_alt || is_mageia ) {
57 0           $self->status_add( status => 'OS Family Redhat, Arch, Suse, Alt, or Mageia detectected' );
58 0           push( @depends, 'net-snmp' );
59             }
60              
61 0           $self->status_add( status => 'Packages: ' . join( ', ' . @depends ) );
62              
63 0           my @failed;
64             my @installed;
65              
66 0           foreach my $pkg (@depends) {
67 0           eval { pkg( $pkg, ensure => 'present' ); };
  0            
68 0 0         if ($@) {
69 0           $self->status_add( status => 'Installing ' . $pkg . ' failed... ' . $@, error => 1 );
70 0           push( @failed, $pkg );
71             } else {
72 0           $self->status_add( status => 'Installed ' . $pkg );
73 0           push( @installed, $pkg );
74             }
75             } ## end foreach my $pkg (@depends)
76              
77 0           $self->status_add( status => 'Failed: ' . join( ', ', @failed ), error => 1 );
78 0           $self->status_add( status => 'Installed: ' . join( ', ', @installed ) );
79              
80 0           return undef;
81             } ## end sub action_extra
82              
83             sub short {
84 0     0 1   return 'Installs snmpd and snmp utils.';
85             }
86              
87             sub opts_data {
88 0     0 1   return '
89             ';
90             }
91              
92             1;