| 1 | # | ||||||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | package Rex::Inventory::DMIDecode; | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 40 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 40 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | 40 | ▶ | use Rex::Inventory::DMIDecode::BaseBoard; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | 40 | ▶ | use Rex::Inventory::DMIDecode::Bios; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 40 | ▶ | use Rex::Inventory::DMIDecode::CPU; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 40 | ▶ | use Rex::Inventory::DMIDecode::Memory; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 40 | ▶ | use Rex::Inventory::DMIDecode::MemoryArray; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 18 | 40 | ▶ | use Rex::Inventory::DMIDecode::SystemInformation; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 19 | 40 | ▶ | use Rex::Commands::Run; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 20 | 40 | ▶ | use Rex::Helper::Run; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 54 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 23 | 54 | my $that = shift; | |||||||||||||||||||||||||||||||
| 24 | 54 | ▶ | my $proto = ref($that) || $that; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $that || $that
MC/DC0%0/2
ref $that || $that
ref $that
$that
Truth table33%1/3
A || B
A= ref $thatB= $that
| |||||||||||||||||||||||||||||||||
| 25 | 54 | my $self = {@_}; | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 54 | bless( $self, $proto ); | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 54 | $self->_read_dmidecode(); | |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 54 | return $self; | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 122 | ▶ | sub get_tree { | ||||||||||||||||||||||||||||||
|
Subroutine
get_tree: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 35 | 122 | my ( $self, $section ) = @_; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 122 | ▶ | if ($section) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 122 | return $self->{"__dmi"}->{$section}; | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||
| 41 | 0 | return $self->{"__dmi"}; | |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | sub get_base_board { | ||||||||||||||||||||||||||||||
|
Subroutine
get_base_board: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 45 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | 3 | return Rex::Inventory::DMIDecode::BaseBoard->new( dmi => $self ); | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 3 | ▶ | sub get_bios { | ||||||||||||||||||||||||||||||
|
Subroutine
get_bios: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 51 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 3 | return Rex::Inventory::DMIDecode::Bios->new( dmi => $self ); | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 54 | ▶ | sub get_system_information { | ||||||||||||||||||||||||||||||
|
Subroutine
get_system_information: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 57 | 54 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 54 | return Rex::Inventory::DMIDecode::SystemInformation->new( dmi => $self ); | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 3 | ▶ | sub get_cpus { | ||||||||||||||||||||||||||||||
|
Subroutine
get_cpus: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 65 | 3 | my @cpus = (); | |||||||||||||||||||||||||||||||
| 66 | 3 | my $tree = $self->get_tree("Processor Information"); | |||||||||||||||||||||||||||||||
| 67 | 3 | my $idx = 0; | |||||||||||||||||||||||||||||||
| 68 | 3 | for my $cpu ( @{$tree} ) { | |||||||||||||||||||||||||||||||
| 69 | 3 | ▶ | if ( $cpu->{"Status"} =~ m/Populated/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | 3 | push( @cpus, | |||||||||||||||||||||||||||||||
| 71 | Rex::Inventory::DMIDecode::CPU->new( dmi => $self, index => $idx ) ); | ||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||
| 73 | 3 | ++$idx; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 3 | return @cpus; | |||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | 3 | ▶ | sub get_memory_modules { | ||||||||||||||||||||||||||||||
|
Subroutine
get_memory_modules: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 83 | 3 | my @mems = (); | |||||||||||||||||||||||||||||||
| 84 | 3 | my $tree = $self->get_tree("Memory Device"); | |||||||||||||||||||||||||||||||
| 85 | 3 | my $idx = 0; | |||||||||||||||||||||||||||||||
| 86 | 3 | for my $mem ( @{$tree} ) { | |||||||||||||||||||||||||||||||
| 87 | 12 | ▶ | if ( $mem->{"Size"} =~ m/\d+/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 88 | 3 | push( @mems, | |||||||||||||||||||||||||||||||
| 89 | Rex::Inventory::DMIDecode::Memory->new( dmi => $self, index => $idx ) ); | ||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||
| 91 | 12 | ++$idx; | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 3 | return @mems; | |||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 3 | ▶ | sub get_memory_arrays { | ||||||||||||||||||||||||||||||
|
Subroutine
get_memory_arrays: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 101 | 3 | my @mems = (); | |||||||||||||||||||||||||||||||
| 102 | 3 | my $tree = $self->get_tree("Physical Memory Array"); | |||||||||||||||||||||||||||||||
| 103 | 3 | my $idx = 0; | |||||||||||||||||||||||||||||||
| 104 | 3 | for my $mema ( @{$tree} ) { | |||||||||||||||||||||||||||||||
| 105 | 3 | push( | |||||||||||||||||||||||||||||||
| 106 | @mems, | ||||||||||||||||||||||||||||||||
| 107 | Rex::Inventory::DMIDecode::MemoryArray->new( | ||||||||||||||||||||||||||||||||
| 108 | dmi => $self, | ||||||||||||||||||||||||||||||||
| 109 | index => $idx | ||||||||||||||||||||||||||||||||
| 110 | ) | ||||||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||||||
| 112 | 3 | ++$idx; | |||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | 3 | return @mems; | |||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 54 | ▶ | sub _read_dmidecode { | ||||||||||||||||||||||||||||||
|
Subroutine
_read_dmidecode: called CC=21 SCAR=32.8
| |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 54 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 54 | my @lines; | |||||||||||||||||||||||||||||||
| 124 | 54 | ▶ | if ( $self->{lines} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 125 | 3 | @lines = @{ $self->{lines} }; | |||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | else { | ||||||||||||||||||||||||||||||||
| 128 | 51 | ▶ | unless ( can_run("dmidecode") ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 129 | 51 | Rex::Logger::debug("Please install dmidecode on the target system."); | |||||||||||||||||||||||||||||||
| 130 | 51 | return; | |||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | 0 | eval { @lines = i_run "dmidecode"; }; | |||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 136 | 0 | Rex::Logger::debug("Error running dmidecode"); | |||||||||||||||||||||||||||||||
| 137 | 0 | return; | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | 3 | chomp @lines; | |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 3 | my %section = (); | |||||||||||||||||||||||||||||||
| 143 | 3 | my $section = ""; | |||||||||||||||||||||||||||||||
| 144 | 3 | my $new_section = 0; | |||||||||||||||||||||||||||||||
| 145 | 3 | my $sub_section = ""; | |||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 3 | for my $l (@lines) { | |||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | 735 | ▶ | next if $l =~ m/^Handle/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 150 | 675 | ▶ | next if $l =~ m/^#/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 151 | 672 | ▶ | next if $l =~ m/^SMBIOS/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 152 | 669 | ▶ | next if $l =~ m/^$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 153 | 609 | ▶ | last if $l =~ m/^End Of Table$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | # for openbsd | ||||||||||||||||||||||||||||||||
| 156 | 606 | $l =~ s/ /\t/g; | |||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||
| 158 | 606 | ▶ | unless ( substr( $l, 0, 1 ) eq "\t" ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 159 | 66 | $section = $l; | |||||||||||||||||||||||||||||||
| 160 | 66 | $new_section = 1; | |||||||||||||||||||||||||||||||
| 161 | 66 | next; | |||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||
| 164 | 540 | my $line = $l; | |||||||||||||||||||||||||||||||
| 165 | 540 | $line =~ s/^\t+//g; | |||||||||||||||||||||||||||||||
| 166 | 540 | $line =~ s/\s+$//g; | |||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | 540 | ▶ | next if $l =~ m/^$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||
| 170 | 540 | ▶ | if ( $l =~ m/^\t[a-zA-Z0-9]/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 171 | 489 | ▶ | if ( exists $section{$section} && !ref( $section{$section} ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
exists $section{$section} and not ref $section{$section}
MC/DC0%0/2
exists $section{$section} and not ref $section{$section}
exists $section{$section}
not ref $section{$section}
Truth table66%2/3
A and not(B)
A= exists $section{$section}B= not ref $section{$section}
| |||||||||||||||||||||||||||||||||
| 172 | 0 | my $content = $section{$section}; | |||||||||||||||||||||||||||||||
| 173 | 0 | $section{$section} = []; | |||||||||||||||||||||||||||||||
| 174 | 0 | my @arr = (); | |||||||||||||||||||||||||||||||
| 175 | 0 | my ( $key, $val ) = split( /: /, $line, 2 ); | |||||||||||||||||||||||||||||||
| 176 | 0 | $key =~ s/:$//; | |||||||||||||||||||||||||||||||
| 177 | 0 | $sub_section = $key; | |||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||
| 179 | #push (@{$section{$section}}, $content); | ||||||||||||||||||||||||||||||||
| 180 | 0 | push( @{ $section{$section} }, { $key => $val } ); | |||||||||||||||||||||||||||||||
| 181 | 0 | $new_section = 0; | |||||||||||||||||||||||||||||||
| 182 | 0 | next; | |||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||
| 184 | ▶ | elsif ( exists $section{$section} && ref( $section{$section} ) ) { | |||||||||||||||||||||||||||||||
|
Condition66%2/3
exists $section{$section} and ref $section{$section}
MC/DC50%1/2
exists $section{$section} and ref $section{$section}
exists $section{$section}
ref $section{$section}
Truth table66%2/3
A and B
A= exists $section{$section}B= ref $section{$section}
| |||||||||||||||||||||||||||||||||
| 185 | 453 | ▶ | if ($new_section) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 186 | 24 | push( @{ $section{$section} }, {} ); | |||||||||||||||||||||||||||||||
| 187 | 24 | $new_section = 0; | |||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||
| 189 | 453 | my ( $key, $val ) = split( /: /, $line, 2 ); | |||||||||||||||||||||||||||||||
| 190 | 453 | $key =~ s/:$//; | |||||||||||||||||||||||||||||||
| 191 | 453 | $sub_section = $key; | |||||||||||||||||||||||||||||||
| 192 | 453 | my $href = $section{$section}->[-1]; | |||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||
| 194 | #push (@{$section{$section}}, {$key => $val}); | ||||||||||||||||||||||||||||||||
| 195 | 453 | $href->{$key} = $val; | |||||||||||||||||||||||||||||||
| 196 | 453 | next; | |||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | 36 | my ( $key, $val ) = split( /: /, $line, 2 ); | |||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ( !$val ) { $key =~ s/:$//; } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 201 | 36 | $sub_section = $key; | |||||||||||||||||||||||||||||||
| 202 | 36 | $section{$section} = [ { $key => $val } ]; | |||||||||||||||||||||||||||||||
| 203 | 36 | $new_section = 0; | |||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | elsif ( $l =~ m/^\t\t[a-zA-Z0-9]/ ) { | ||||||||||||||||||||||||||||||||
| 206 | 51 | my $href = $section{$section}->[-1]; | |||||||||||||||||||||||||||||||
| 207 | 51 | ▶ | if ( !ref( $href->{$sub_section} ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 208 | 21 | $href->{$sub_section} = []; | |||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||
| 211 | 51 | push( @{ $href->{$sub_section} }, $line ); | |||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||
| 216 | 3 | $self->{"__dmi"} = \%section; | |||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||
| 220 | 40 | 1; | |||||||||||||||||||||||||||||||