lib/Rex/Hardware.pm

filter: Statementstmt 96.3% 79 / 82 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 21 / 21 Podpod 50.0% 1 / 2 totaltotal 94.5% 105 / 111 CC 5 SCAR 4.1
CC
5
Cov
94%
get
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« lib/Rex/Helper/Misc.pm ↑ Summary lib/Rex/Interface/Shell.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 =head1 NAME
6  
7 Rex::Hardware - Base Class for hardware / information gathering
8  
9 =head1 DESCRIPTION
10  
11 This module is the base class for hardware/information gathering.
12  
13 =head1 SYNOPSIS
14  
15 use Rex::Hardware;
16  
17 my %host_info = Rex::Hardware->get(qw/ Host /);
18 my %all_info = Rex::Hardware->get(qw/ All /);
19  
20 =head1 CLASS METHODS
21  
22 =cut
23  
24 package Rex::Hardware;
25  
26 72 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 72 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 69 our $VERSION = '1.16.1'; # VERSION
30  
31 72 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 69 require Rex::Args;
34  
35 =head2 get(@modules)
36  
37 Returns a hash with the wanted information.
38  
39 task "get-info", "server1", sub {
40 %hw_info = Rex::Hardware->get(qw/ Host Network /);
41 };
42  
43 Or if you want to get all information
44  
45 task "get-all-info", "server1", sub {
46 %hw_info = Rex::Hardware->get(qw/ All /);
47 };
48  
49 Available modules:
50  
51 =over 4
52  
53 =item Host
54  
55 =item Kernel
56  
57 =item Memory
58  
59 =item Network
60  
61 =item Swap
62  
63 =item VirtInfo
64  
65 =back
66  
67 =cut
68  
69 69 my %HW_PROVIDER;
70  
71 3 ▶sub register_hardware_provider {
Subroutine register_hardware_provider: called CC=1 SCAR=0.0
Pod undocumented
72 3 my ( $class, $service_name, $service_class ) = @_;
73 3 $HW_PROVIDER{"\L$service_name"} = $service_class;
74 3 return 1;
75 }
76  
77 42 ▶sub get {
Subroutine get: called CC=5 SCAR=16.1
Pod documented
78 42 my ( $class, @modules ) = @_;
79  
80 42 my %hardware_information;
81  
82 42 ▶ if ( "all" eq "\L$modules[0]" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("all" eq lc $modules[0]) 9 30 39
83  
84 12 @modules = qw(Host Kernel Memory Network Swap VirtInfo);
85 12 push( @modules, keys(%HW_PROVIDER) );
86  
87 }
88  
89 42 for my $mod_string (@modules) {
90  
91 87 Rex::Commands::profiler()->start("hardware: $mod_string");
92  
93 86 my $mod = "Rex::Hardware::$mod_string";
94 86 ▶ if ( exists $HW_PROVIDER{$mod_string} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $HW_PROVIDER{$mod_string}) 0 84 84
95 2 $mod = $HW_PROVIDER{$mod_string};
96 }
97  
98 86 Rex::Logger::debug("Loading $mod");
99 86 ▶ eval "use $mod";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101 86 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 84 84
102 0 Rex::Logger::info("$mod not found.");
103 0 Rex::Logger::debug("$@");
104 0 next;
105 }
106  
107 84 $hardware_information{$mod_string} = $mod->get();
108  
109 84 Rex::Commands::profiler()->end("hardware: $mod_string");
110  
111 }
112  
113 39 return %hardware_information;
114 }
115  
116 69 1;
« lib/Rex/Helper/Misc.pm ↑ Summary lib/Rex/Interface/Shell.pm »