line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Inventory::DMIDecode; |
6
|
|
|
|
|
|
|
|
7
|
39
|
|
|
39
|
|
69935
|
use v5.12.5; |
|
39
|
|
|
|
|
149
|
|
8
|
39
|
|
|
39
|
|
204
|
use warnings; |
|
39
|
|
|
|
|
93
|
|
|
39
|
|
|
|
|
1007
|
|
9
|
39
|
|
|
39
|
|
862
|
use Data::Dumper; |
|
39
|
|
|
|
|
6929
|
|
|
39
|
|
|
|
|
2731
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
12
|
|
|
|
|
|
|
|
13
|
39
|
|
|
39
|
|
872
|
use Rex::Inventory::DMIDecode::BaseBoard; |
|
39
|
|
|
|
|
109
|
|
|
39
|
|
|
|
|
1664
|
|
14
|
39
|
|
|
39
|
|
870
|
use Rex::Inventory::DMIDecode::Bios; |
|
39
|
|
|
|
|
105
|
|
|
39
|
|
|
|
|
1664
|
|
15
|
39
|
|
|
39
|
|
883
|
use Rex::Inventory::DMIDecode::CPU; |
|
39
|
|
|
|
|
139
|
|
|
39
|
|
|
|
|
1677
|
|
16
|
39
|
|
|
39
|
|
935
|
use Rex::Inventory::DMIDecode::Memory; |
|
39
|
|
|
|
|
109
|
|
|
39
|
|
|
|
|
1732
|
|
17
|
39
|
|
|
39
|
|
911
|
use Rex::Inventory::DMIDecode::MemoryArray; |
|
39
|
|
|
|
|
216
|
|
|
39
|
|
|
|
|
1965
|
|
18
|
39
|
|
|
39
|
|
844
|
use Rex::Inventory::DMIDecode::SystemInformation; |
|
39
|
|
|
|
|
116
|
|
|
39
|
|
|
|
|
1697
|
|
19
|
39
|
|
|
39
|
|
721
|
use Rex::Commands::Run; |
|
39
|
|
|
|
|
88
|
|
|
39
|
|
|
|
|
277
|
|
20
|
39
|
|
|
39
|
|
267
|
use Rex::Helper::Run; |
|
39
|
|
|
|
|
99
|
|
|
39
|
|
|
|
|
53306
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
54
|
|
|
54
|
0
|
628
|
my $that = shift; |
24
|
54
|
|
33
|
|
|
790
|
my $proto = ref($that) || $that; |
25
|
54
|
|
|
|
|
301
|
my $self = {@_}; |
26
|
|
|
|
|
|
|
|
27
|
54
|
|
|
|
|
398
|
bless( $self, $proto ); |
28
|
|
|
|
|
|
|
|
29
|
54
|
|
|
|
|
799
|
$self->_read_dmidecode(); |
30
|
|
|
|
|
|
|
|
31
|
54
|
|
|
|
|
2221
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub get_tree { |
35
|
122
|
|
|
122
|
0
|
485
|
my ( $self, $section ) = @_; |
36
|
|
|
|
|
|
|
|
37
|
122
|
50
|
|
|
|
357
|
if ($section) { |
38
|
122
|
|
|
|
|
904
|
return $self->{"__dmi"}->{$section}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
return $self->{"__dmi"}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get_base_board { |
45
|
3
|
|
|
3
|
0
|
1295
|
my ($self) = @_; |
46
|
|
|
|
|
|
|
|
47
|
3
|
|
|
|
|
16
|
return Rex::Inventory::DMIDecode::BaseBoard->new( dmi => $self ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_bios { |
51
|
3
|
|
|
3
|
0
|
12
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
|
53
|
3
|
|
|
|
|
13
|
return Rex::Inventory::DMIDecode::Bios->new( dmi => $self ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_system_information { |
57
|
54
|
|
|
54
|
0
|
502
|
my ($self) = @_; |
58
|
|
|
|
|
|
|
|
59
|
54
|
|
|
|
|
2015
|
return Rex::Inventory::DMIDecode::SystemInformation->new( dmi => $self ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub get_cpus { |
63
|
|
|
|
|
|
|
|
64
|
3
|
|
|
3
|
0
|
13
|
my ($self) = @_; |
65
|
3
|
|
|
|
|
5
|
my @cpus = (); |
66
|
3
|
|
|
|
|
9
|
my $tree = $self->get_tree("Processor Information"); |
67
|
3
|
|
|
|
|
5
|
my $idx = 0; |
68
|
3
|
|
|
|
|
5
|
for my $cpu ( @{$tree} ) { |
|
3
|
|
|
|
|
7
|
|
69
|
3
|
50
|
|
|
|
13
|
if ( $cpu->{"Status"} =~ m/Populated/ ) { |
70
|
3
|
|
|
|
|
125
|
push( @cpus, |
71
|
|
|
|
|
|
|
Rex::Inventory::DMIDecode::CPU->new( dmi => $self, index => $idx ) ); |
72
|
|
|
|
|
|
|
} |
73
|
3
|
|
|
|
|
5
|
++$idx; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
3
|
|
|
|
|
10
|
return @cpus; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub get_memory_modules { |
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
3
|
0
|
15
|
my ($self) = @_; |
83
|
3
|
|
|
|
|
4
|
my @mems = (); |
84
|
3
|
|
|
|
|
7
|
my $tree = $self->get_tree("Memory Device"); |
85
|
3
|
|
|
|
|
6
|
my $idx = 0; |
86
|
3
|
|
|
|
|
4
|
for my $mem ( @{$tree} ) { |
|
3
|
|
|
|
|
7
|
|
87
|
12
|
100
|
|
|
|
36
|
if ( $mem->{"Size"} =~ m/\d+/ ) { |
88
|
3
|
|
|
|
|
13
|
push( @mems, |
89
|
|
|
|
|
|
|
Rex::Inventory::DMIDecode::Memory->new( dmi => $self, index => $idx ) ); |
90
|
|
|
|
|
|
|
} |
91
|
12
|
|
|
|
|
20
|
++$idx; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
10
|
return @mems; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub get_memory_arrays { |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
3
|
0
|
13
|
my ($self) = @_; |
101
|
3
|
|
|
|
|
5
|
my @mems = (); |
102
|
3
|
|
|
|
|
6
|
my $tree = $self->get_tree("Physical Memory Array"); |
103
|
3
|
|
|
|
|
4
|
my $idx = 0; |
104
|
3
|
|
|
|
|
5
|
for my $mema ( @{$tree} ) { |
|
3
|
|
|
|
|
5
|
|
105
|
3
|
|
|
|
|
13
|
push( |
106
|
|
|
|
|
|
|
@mems, |
107
|
|
|
|
|
|
|
Rex::Inventory::DMIDecode::MemoryArray->new( |
108
|
|
|
|
|
|
|
dmi => $self, |
109
|
|
|
|
|
|
|
index => $idx |
110
|
|
|
|
|
|
|
) |
111
|
|
|
|
|
|
|
); |
112
|
3
|
|
|
|
|
5
|
++$idx; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
3
|
|
|
|
|
6
|
return @mems; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _read_dmidecode { |
120
|
|
|
|
|
|
|
|
121
|
54
|
|
|
54
|
|
292
|
my ($self) = @_; |
122
|
|
|
|
|
|
|
|
123
|
54
|
|
|
|
|
155
|
my @lines; |
124
|
54
|
100
|
|
|
|
315
|
if ( $self->{lines} ) { |
125
|
3
|
|
|
|
|
5
|
@lines = @{ $self->{lines} }; |
|
3
|
|
|
|
|
118
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
else { |
128
|
51
|
50
|
|
|
|
366
|
unless ( can_run("dmidecode") ) { |
129
|
51
|
|
|
|
|
1576
|
Rex::Logger::debug("Please install dmidecode on the target system."); |
130
|
51
|
|
|
|
|
767
|
return; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
0
|
eval { @lines = i_run "dmidecode"; }; |
|
0
|
|
|
|
|
0
|
|
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
0
|
if ($@) { |
136
|
0
|
|
|
|
|
0
|
Rex::Logger::debug("Error running dmidecode"); |
137
|
0
|
|
|
|
|
0
|
return; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
3
|
|
|
|
|
31
|
chomp @lines; |
141
|
|
|
|
|
|
|
|
142
|
3
|
|
|
|
|
7
|
my %section = (); |
143
|
3
|
|
|
|
|
6
|
my $section = ""; |
144
|
3
|
|
|
|
|
5
|
my $new_section = 0; |
145
|
3
|
|
|
|
|
8
|
my $sub_section = ""; |
146
|
|
|
|
|
|
|
|
147
|
3
|
|
|
|
|
7
|
for my $l (@lines) { |
148
|
|
|
|
|
|
|
|
149
|
735
|
100
|
|
|
|
1458
|
next if $l =~ m/^Handle/; |
150
|
675
|
100
|
|
|
|
1124
|
next if $l =~ m/^#/; |
151
|
672
|
100
|
|
|
|
1113
|
next if $l =~ m/^SMBIOS/; |
152
|
669
|
100
|
|
|
|
1351
|
next if $l =~ m/^$/; |
153
|
609
|
100
|
|
|
|
1024
|
last if $l =~ m/^End Of Table$/; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# for openbsd |
156
|
606
|
|
|
|
|
929
|
$l =~ s/ /\t/g; |
157
|
|
|
|
|
|
|
|
158
|
606
|
100
|
|
|
|
1202
|
unless ( substr( $l, 0, 1 ) eq "\t" ) { |
159
|
66
|
|
|
|
|
98
|
$section = $l; |
160
|
66
|
|
|
|
|
76
|
$new_section = 1; |
161
|
66
|
|
|
|
|
99
|
next; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
540
|
|
|
|
|
733
|
my $line = $l; |
165
|
540
|
|
|
|
|
1521
|
$line =~ s/^\t+//g; |
166
|
540
|
|
|
|
|
1199
|
$line =~ s/\s+$//g; |
167
|
|
|
|
|
|
|
|
168
|
540
|
50
|
|
|
|
1049
|
next if $l =~ m/^$/; |
169
|
|
|
|
|
|
|
|
170
|
540
|
100
|
|
|
|
1145
|
if ( $l =~ m/^\t[a-zA-Z0-9]/ ) { |
|
|
50
|
|
|
|
|
|
171
|
489
|
50
|
66
|
|
|
2250
|
if ( exists $section{$section} && !ref( $section{$section} ) ) { |
|
|
100
|
66
|
|
|
|
|
172
|
0
|
|
|
|
|
0
|
my $content = $section{$section}; |
173
|
0
|
|
|
|
|
0
|
$section{$section} = []; |
174
|
0
|
|
|
|
|
0
|
my @arr = (); |
175
|
0
|
|
|
|
|
0
|
my ( $key, $val ) = split( /: /, $line, 2 ); |
176
|
0
|
|
|
|
|
0
|
$key =~ s/:$//; |
177
|
0
|
|
|
|
|
0
|
$sub_section = $key; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
#push (@{$section{$section}}, $content); |
180
|
0
|
|
|
|
|
0
|
push( @{ $section{$section} }, { $key => $val } ); |
|
0
|
|
|
|
|
0
|
|
181
|
0
|
|
|
|
|
0
|
$new_section = 0; |
182
|
0
|
|
|
|
|
0
|
next; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
elsif ( exists $section{$section} && ref( $section{$section} ) ) { |
185
|
453
|
100
|
|
|
|
800
|
if ($new_section) { |
186
|
24
|
|
|
|
|
29
|
push( @{ $section{$section} }, {} ); |
|
24
|
|
|
|
|
55
|
|
187
|
24
|
|
|
|
|
40
|
$new_section = 0; |
188
|
|
|
|
|
|
|
} |
189
|
453
|
|
|
|
|
1111
|
my ( $key, $val ) = split( /: /, $line, 2 ); |
190
|
453
|
|
|
|
|
810
|
$key =~ s/:$//; |
191
|
453
|
|
|
|
|
609
|
$sub_section = $key; |
192
|
453
|
|
|
|
|
658
|
my $href = $section{$section}->[-1]; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
#push (@{$section{$section}}, {$key => $val}); |
195
|
453
|
|
|
|
|
871
|
$href->{$key} = $val; |
196
|
453
|
|
|
|
|
796
|
next; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
36
|
|
|
|
|
101
|
my ( $key, $val ) = split( /: /, $line, 2 ); |
200
|
36
|
50
|
|
|
|
74
|
if ( !$val ) { $key =~ s/:$//; } |
|
0
|
|
|
|
|
0
|
|
201
|
36
|
|
|
|
|
48
|
$sub_section = $key; |
202
|
36
|
|
|
|
|
110
|
$section{$section} = [ { $key => $val } ]; |
203
|
36
|
|
|
|
|
68
|
$new_section = 0; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
elsif ( $l =~ m/^\t\t[a-zA-Z0-9]/ ) { |
206
|
51
|
|
|
|
|
84
|
my $href = $section{$section}->[-1]; |
207
|
51
|
100
|
|
|
|
107
|
if ( !ref( $href->{$sub_section} ) ) { |
208
|
21
|
|
|
|
|
36
|
$href->{$sub_section} = []; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
51
|
|
|
|
|
72
|
push( @{ $href->{$sub_section} }, $line ); |
|
51
|
|
|
|
|
131
|
|
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
3
|
|
|
|
|
49
|
$self->{"__dmi"} = \%section; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |