lib/Rex/Inventory.pm

filter: Statementstmt 29.8% 37 / 124 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 12 / 20 Podpod 0.0% 0 / 2 totaltotal 28.6% 49 / 171 CC 21 SCAR 41.3
CC
21
Cov
25%
get
182.0
__ANON__
12.0
new
6.0
CRAP 62.1
« lib/Rex/Inventory/Hal.pm ↑ Summary lib/Rex/Service/FreeBSD.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Inventory;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Inventory::DMIDecode;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Inventory::Hal;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Rex::Inventory::Proc;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Rex::Commands::Network;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Rex::Commands::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Rex::Commands::Gather;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Rex::Commands::LVM;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Rex::Commands::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Rex::Inventory::HP::ACU;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
25 0 my $that = shift;
26 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
27 0 my $self = {@_};
28  
29 0 bless( $self, $proto );
30  
31 0 return $self;
32 }
33  
34 0 ▶sub get {
Subroutine get: not called CC=13 SCAR=52.0
Pod undocumented
35  
36 0 my ($self) = @_;
37  
38 0 my $dmi = Rex::Inventory::DMIDecode->new;
39 0 my ( $base_board, $bios, @cpus, @dimms, @mem_arrays, $sys_info );
40  
41 0 $base_board = $dmi->get_base_board;
42 0 $bios = $dmi->get_bios;
43 0 @cpus = $dmi->get_cpus;
44 0 @dimms = $dmi->get_memory_modules;
45 0 @mem_arrays = $dmi->get_memory_arrays;
46 0 $sys_info = $dmi->get_system_information;
47  
48 0 my $hal = {};
49 0 my ( @net_devs, @storage, @volumes );
50  
51 0 eval {
52 0 $hal = Rex::Inventory::Hal->new;
53  
54 0 @net_devs = $hal->get_network_devices;
55 0 @storage = $hal->get_storage_devices;
56 0 @volumes = $hal->get_storage_volumes;
57 };
58  
59 0 eval {
60 0 ▶ if ( scalar @cpus == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @cpus == 0) 0 0 0
61  
62 # get cpu info from /proc
63 0 ▶ if ( is_dir("/proc") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_dir("/proc")) 0 0 0
64 0 Rex::Logger::info(
65 "Got no cpu information from dmidecode. Falling back to /proc/cpuinfo"
66 );
67 0 my $proc_i = Rex::Inventory::Proc->new;
68 0 @cpus = @{ $proc_i->get_cpus };
69 }
70 }
71 };
72  
73 0 my @routes = route;
74 0 my @netstat = netstat;
75 0 my $default_gw = default_gateway;
76  
77 0 my ( @pvs, @vgs, @lvs );
78 0 eval {
79 0 @pvs = pvs;
80 0 @vgs = vgs;
81 0 @lvs = lvs;
82 };
83  
84 0 my @raid_controller;
85 0 eval {
86 0 ▶ if ( my $hp_raid = Rex::Inventory::HP::ACU->get() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hp_raid = "Rex::Inventory::HP::ACU"->get) 0 0 0
87  
88 # hp raid entdeckt
89 0 for my $key ( keys %{$hp_raid} ) {
90  
91 0 my %raid_shelfs;
92 0 for my $shelf ( keys %{ $hp_raid->{$key}->{"array"} } ) {
93 0 my $shelf_data = $hp_raid->{$key}->{"array"}->{$shelf};
94  
95 0 my @raid_logical_drives;
96 0 for my $l_drive (
97 0 keys %{ $hp_raid->{$key}->{"array"}->{$shelf}->{"logical_drive"} } )
98 {
99 my $l_drive_data =
100 $hp_raid->{$key}->{"array"}->{$shelf}->{"logical_drive"}
101 0 ->{$l_drive};
102 0 my ($size) = ( $l_drive_data->{"size"} =~ m/^([0-9\.]+)/ );
103 0 my $multi = 1024 * 1024 * 1024;
104 0 ▶ if ( $l_drive_data->{"size"} =~ m/TB$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l_drive_data->{"size"} =~ /TB$/u) 0 0 0
105 0 $multi *= 1024;
106 }
107  
108 push(
109 @raid_logical_drives,
110 {
111 status => ( $l_drive_data->{"status"} eq "OK" ? 1 : 0 ),
112 raid_level => $l_drive_data->{"fault_tolerance"},
113 size => sprintf( "%i", $size * $multi ),
114 0 ▶ dev => $l_drive_data->{"disk_name"},
Branch: 1 branch
BranchTrueFalseTotal
$l_drive_data->{'status'} eq 'OK' ? : 0 0 0
115 shelf => $shelf,
116 }
117 );
118 }
119  
120 $raid_shelfs{$shelf} = {
121 type => $shelf_data->{"interface_type"},
122 0 ▶ status => ( $shelf_data->{"status"} eq "OK" ? 1 : 0 ),
Branch: 1 branch
BranchTrueFalseTotal
$shelf_data->{'status'} eq 'OK' ? : 0 0 0
123 logical_drives => \@raid_logical_drives,
124 };
125  
126 }
127  
128 push(
129 @raid_controller,
130 {
131 type => $hp_raid->{$key}->{"description"},
132 model => $hp_raid->{$key}->{"model"},
133 serial_number => $hp_raid->{$key}->{"serial_number"},
134 cache_status =>
135 0 ▶ ( $hp_raid->{$key}->{"cache_status"} eq "OK" ? 1 : 0 ),
Branch: 1 branch
BranchTrueFalseTotal
$hp_raid->{$key}{'cache_status'} eq 'OK' ? : 0 0 0
136 shelfs => \%raid_shelfs,
137 }
138 );
139  
140 }
141 }
142 };
143  
144 0 my ($fusion_inventory_xmlref);
145 0 ▶ if ( can_run("fusioninventory-agent") ) {
Branch: 1 branch
BranchTrueFalseTotal
if (can_run("fusioninventory-agent")) 0 0 0
146 0 require XML::Simple;
147 0 my $xml = XML::Simple->new;
148 0 my $fusion_inventory = run "fusioninventory-agent --stdout 2>/dev/null";
149 0 $fusion_inventory_xmlref = $xml->XMLin($fusion_inventory);
150 }
151  
152 return {
153 base_board => ( $base_board ? $base_board->get_all() : {} ),
154 bios => $bios->get_all(),
155 system_info => $sys_info->get_all(),
156 0 ▶ cpus => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
157 0 my $ret = [];
158 0 ▶ push( @{$ret}, ( ref $_ ne "HASH" ? $_->get_all() : $_ ) ) for @cpus;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ne 'HASH' ? : 0 0 0
159 0 return $ret;
160 }
161 ->(),
162 0 ▶ dimms => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
163 0 my $ret = [];
164 0 push( @{$ret}, $_->get_all() ) for @dimms;
165 0 return $ret;
166 }
167 ->(),
168 0 ▶ mem_arrays => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
169 0 my $ret = [];
170 0 push( @{$ret}, $_->get_all() ) for @mem_arrays;
171 0 return $ret;
172 }
173 ->(),
174 0 ▶ net => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
175 0 my $ret = [];
176 0 push( @{$ret}, $_->get_all() ) for @net_devs;
177 0 return $ret;
178 }
179 ->(),
180 0 ▶ storage => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
181 0 my $ret = [];
182 0 push( @{$ret}, $_->get_all() ) for @storage;
183 0 return $ret;
184 }
185 ->(),
186 0 ▶ volumes => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
187 0 my $ret = [];
188 0 push( @{$ret}, $_->get_all() ) for @volumes;
189 0 return $ret;
190 }
191 0 ▶ ->(),
Branch: 1 branch
BranchTrueFalseTotal
$base_board ? : 0 0 0
192 raid => {
193 controller => \@raid_controller,
194 },
195 lvm => {
196 physical_volumes => \@pvs,
197 volume_groups => \@vgs,
198 logical_volumes => \@lvs,
199 },
200 configuration => {
201 network => {
202 routes => \@routes,
203 current_connections => \@netstat,
204 default_gateway => $default_gw,
205 current_configuration => network_interfaces(),
206 },
207 host => {
208 name => [ run "hostname -s" ]->[0],
209 domain => [ run "hostname -d" || qw() ]->[0],
210 kernel => [ run "uname -r" || qw() ]->[0],
211 },
212 },
213 fusion_inventory => $fusion_inventory_xmlref,
214 };
215  
216 }
217  
218 1 1;
« lib/Rex/Inventory/Hal.pm ↑ Summary lib/Rex/Service/FreeBSD.pm »