lib/Rex/Inventory/SMBios.pm

filter: Statementstmt 34.4% 40 / 116 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 59.0% 13 / 22 Podpod 0.0% 0 / 8 totaltotal 29.9% 53 / 177 CC 19 SCAR 39.1
CC
19
Cov
28%
_read_smbios
156.0
get_cpus
12.0
get_memory_modules
12.0
CRAP 50.0
« lib/Rex/Pkg/Arch.pm ↑ Summary lib/Rex/PkgConf.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Inventory::SMBios;
6  
7 39 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 39 our $VERSION = '1.16.1'; # VERSION
11  
12 39 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 39 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 39 ▶use Rex::Commands::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 39 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 39 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 39 ▶use Rex::Inventory::SMBios::BaseBoard;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 39 ▶use Rex::Inventory::SMBios::Bios;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 39 ▶use Rex::Inventory::SMBios::CPU;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 39 ▶use Rex::Inventory::SMBios::Memory;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 39 ▶use Rex::Inventory::SMBios::MemoryArray;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 39 ▶use Rex::Inventory::SMBios::SystemInformation;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
26 0 my $that = shift;
27 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
28 0 my $self = {@_};
29  
30 0 bless( $self, $proto );
31  
32 0 $self->_read_smbios();
33  
34 0 return $self;
35 }
36  
37 0 ▶sub get_tree {
Subroutine get_tree: not called CC=2 SCAR=17.9
Pod undocumented
38 0 my ( $self, $section ) = @_;
39  
40 0 ▶ if ($section) {
Branch: 1 branch
BranchTrueFalseTotal
if ($section) 0 0 0
41 0 return $self->{"__dmi"}->{$section};
42 }
43  
44 0 return $self->{"__dmi"};
45 }
46  
47 0 ▶sub get_base_board {
Subroutine get_base_board: not called CC=1 SCAR=6.9
Pod undocumented
48 0 my ($self) = @_;
49 0 return Rex::Inventory::SMBios::BaseBoard->new( dmi => $self );
50 }
51  
52 0 ▶sub get_bios {
Subroutine get_bios: not called CC=1 SCAR=6.9
Pod undocumented
53 0 my ($self) = @_;
54 0 return Rex::Inventory::SMBios::Bios->new( dmi => $self );
55 }
56  
57 0 ▶sub get_system_information {
Subroutine get_system_information: not called CC=1 SCAR=6.9
Pod undocumented
58 0 my ($self) = @_;
59 0 return Rex::Inventory::SMBios::SystemInformation->new( dmi => $self );
60 }
61  
62 0 ▶sub get_cpus {
Subroutine get_cpus: not called CC=3 SCAR=24.8
Pod undocumented
63  
64 0 my ($self) = @_;
65 0 my @cpus = ();
66 0 my $tree = $self->get_tree("processor");
67 0 my $idx = 0;
68 0 for my $cpu ( @{$tree} ) {
69 0 ▶ if ( $cpu->{"Socket Status"} =~ m/Populated/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cpu->{"Socket Status"} =~ /Populated/u) 0 0 0
70 0 push( @cpus,
71 Rex::Inventory::SMBios::CPU->new( dmi => $self, index => $idx ) );
72 }
73 0 ++$idx;
74 }
75  
76 0 return @cpus;
77  
78 }
79  
80 0 ▶sub get_memory_modules {
Subroutine get_memory_modules: not called CC=3 SCAR=24.8
Pod undocumented
81  
82 0 my ($self) = @_;
83 0 my @mems = ();
84 0 my $tree = $self->get_tree("memory device");
85 0 my $idx = 0;
86 0 for my $mem ( @{$tree} ) {
87 0 ▶ if ( $mem->{"Size"} =~ m/\d+/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mem->{"Size"} =~ /\d+/u) 0 0 0
88 0 push( @mems,
89 Rex::Inventory::SMBios::Memory->new( dmi => $self, index => $idx ) );
90 }
91 0 ++$idx;
92 }
93  
94 0 return @mems;
95  
96 }
97  
98 0 ▶sub get_memory_arrays {
Subroutine get_memory_arrays: not called CC=2 SCAR=17.9
Pod undocumented
99  
100 0 my ($self) = @_;
101 0 my @mems = ();
102 0 my $tree = $self->get_tree("physical memory array");
103 0 my $idx = 0;
104 0 for my $mema ( @{$tree} ) {
105 0 push( @mems,
106 Rex::Inventory::SMBios::MemoryArray->new( dmi => $self, index => $idx ) );
107 0 ++$idx;
108 }
109  
110 0 return @mems;
111  
112 }
113  
114 0 ▶sub _read_smbios {
Subroutine _read_smbios: not called CC=12 SCAR=50.5
115 0 my ($self) = @_;
116  
117 0 my @data = i_run( "smbios", fail_ok => 1 );
118  
119 0 ▶ if ( $CHILD_ERROR != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Rex::Inventory::SMBios::CHILD_ERROR != 0) 0 0 0
120 0 Rex::Logger::debug('Error running smbios. Output:');
121 0 Rex::Logger::debug( join "\n", @data );
122 0 return;
123 }
124  
125 0 my ( $current_section, %section, $key, $val, %cur_data );
126 0 for my $line (@data) {
127 0 ▶ next if ( $line =~ /^$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^$/u 0 0 0
128 0 ▶ next if ( $line =~ /^\s*$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/u 0 0 0
129 0 ▶ next if ( $line =~ /^ID/ );
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^ID/u 0 0 0
130  
131 0 ▶ if ( $line =~ m/^\d/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\d/u) 0 0 0
132 0 ▶ push( @{ $section{$current_section} }, {%cur_data} ) if (%cur_data);
Branch: 1 branch
BranchTrueFalseTotal
if %cur_data 0 0 0
133  
134 0 ($current_section) = ( $line =~ m/\(([^\)]+)\)/ );
135  
136 0 ▶ if ( !exists $section{$current_section} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $section{$current_section}) 0 0 0
137 0 $section{$current_section} = [];
138 }
139  
140 0 %cur_data = ();
141 0 next;
142 }
143  
144 # outer section
145 0 ▶ if ( $line =~ /^\s\s[a-z]/i ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /^\s\s[a-z]/iu) { } 0 0 0
elsif ($line =~ /^\t[a-z]/iu) { } 0 0 0
146 0 $line =~ s/^\s*//;
147 0 ( $key, $val ) = split( /: /, $line );
148 0 $cur_data{$key} = $val;
149 }
150 elsif ( $line =~ /^\t[a-z]/i ) {
151 0 ▶ if ( !ref( $cur_data{$key} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $cur_data{$key}) 0 0 0
152 0 $cur_data{$key} = [];
153 }
154  
155 0 $line =~ s/^\s*//;
156 0 push( @{ $cur_data{$key} }, $line );
157 }
158  
159 }
160  
161 # push the last
162 0 push( @{ $section{$current_section} }, {%cur_data} );
163  
164 0 $self->{"__dmi"} = \%section;
165 }
166  
167 39 1;
« lib/Rex/Pkg/Arch.pm ↑ Summary lib/Rex/PkgConf.pm »