File Coverage

lib/Rex/Inventory.pm
Criterion Covered Total %
statement 35 122 28.6
branch 0 20 0.0
condition 0 3 0.0
subroutine 12 20 60.0
pod 0 2 0.0
total 47 167 28.1


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Inventory;
6              
7 1     1   15 use v5.12.5;
  1         3  
8 1     1   6 use warnings;
  1         2  
  1         41  
9              
10             our $VERSION = '1.14.2.2'; # TRIAL VERSION
11              
12 1     1   6 use Rex::Inventory::DMIDecode;
  1         2  
  1         21  
13 1     1   59 use Rex::Inventory::Hal;
  1         4  
  1         13  
14 1     1   36 use Rex::Inventory::Proc;
  1         2  
  1         14  
15 1     1   35 use Rex::Commands::Network;
  1         2  
  1         6  
16 1     1   6 use Rex::Commands::Run;
  1         2  
  1         5  
17 1     1   11 use Rex::Commands::Gather;
  1         2  
  1         4  
18 1     1   18 use Rex::Commands::LVM;
  1         2  
  1         10  
19 1     1   7 use Rex::Commands::Fs;
  1         3  
  1         5  
20              
21 1     1   13 use Rex::Inventory::HP::ACU;
  1         6  
  1         30  
22 1     1   33 use Data::Dumper;
  1         3  
  1         1175  
23              
24             sub new {
25 0     0 0   my $that = shift;
26 0   0       my $proto = ref($that) || $that;
27 0           my $self = {@_};
28              
29 0           bless( $self, $proto );
30              
31 0           return $self;
32             }
33              
34             sub get {
35              
36 0     0 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 0         if ( scalar @cpus == 0 ) {
61              
62             # get cpu info from /proc
63 0 0         if ( is_dir("/proc") ) {
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 };
  0            
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 0         if ( my $hp_raid = Rex::Inventory::HP::ACU->get() ) {
87              
88             # hp raid entdeckt
89 0           for my $key ( keys %{$hp_raid} ) {
  0            
90              
91 0           my %raid_shelfs;
92 0           for my $shelf ( keys %{ $hp_raid->{$key}->{"array"} } ) {
  0            
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 0         if ( $l_drive_data->{"size"} =~ m/TB$/ ) {
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 0         dev => $l_drive_data->{"disk_name"},
115             shelf => $shelf,
116             }
117             );
118             }
119              
120             $raid_shelfs{$shelf} = {
121             type => $shelf_data->{"interface_type"},
122 0 0         status => ( $shelf_data->{"status"} eq "OK" ? 1 : 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 0         ( $hp_raid->{$key}->{"cache_status"} eq "OK" ? 1 : 0 ),
136             shelfs => \%raid_shelfs,
137             }
138             );
139              
140             }
141             }
142             };
143              
144 0           my ($fusion_inventory_xmlref);
145 0 0         if ( can_run("fusioninventory-agent") ) {
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             cpus => sub {
157 0     0     my $ret = [];
158 0 0         push( @{$ret}, ( ref $_ ne "HASH" ? $_->get_all() : $_ ) ) for @cpus;
  0            
159 0           return $ret;
160             }
161             ->(),
162             dimms => sub {
163 0     0     my $ret = [];
164 0           push( @{$ret}, $_->get_all() ) for @dimms;
  0            
165 0           return $ret;
166             }
167             ->(),
168             mem_arrays => sub {
169 0     0     my $ret = [];
170 0           push( @{$ret}, $_->get_all() ) for @mem_arrays;
  0            
171 0           return $ret;
172             }
173             ->(),
174             net => sub {
175 0     0     my $ret = [];
176 0           push( @{$ret}, $_->get_all() ) for @net_devs;
  0            
177 0           return $ret;
178             }
179             ->(),
180             storage => sub {
181 0     0     my $ret = [];
182 0           push( @{$ret}, $_->get_all() ) for @storage;
  0            
183 0           return $ret;
184             }
185             ->(),
186             volumes => sub {
187 0     0     my $ret = [];
188 0           push( @{$ret}, $_->get_all() ) for @volumes;
  0            
189 0           return $ret;
190             }
191 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;