96 |
rodolico |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
/*
|
|
|
6 |
* Function will take an array of lines representing the output of a dmidecode file
|
|
|
7 |
* and pick and choose the values we want to put into CAMP attributes.
|
|
|
8 |
* It will return an array of key/value pairs to be added into the attributes table
|
|
|
9 |
*
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
function dmidecode2array( $contents ) {
|
|
|
13 |
|
|
|
14 |
// allows us to group the dmi types by function
|
|
|
15 |
$dmiGroups = array(
|
|
|
16 |
"bios" => "0,13",
|
|
|
17 |
"system" => "1,12,15,23,32",
|
|
|
18 |
"baseboard" => "2,10,41",
|
|
|
19 |
"chassis" => "3",
|
|
|
20 |
"processor" => "4",
|
|
|
21 |
"memory" => "5,6,16,17",
|
|
|
22 |
"cache" => "7",
|
|
|
23 |
"connector" => "8",
|
|
|
24 |
"slot" => "9"
|
|
|
25 |
);
|
|
|
26 |
|
|
|
27 |
// This contains the standard DMI types, ie no OEM stuff
|
|
|
28 |
|
|
|
29 |
$standardDMITypes = array(
|
|
|
30 |
"0" => "BIOS",
|
|
|
31 |
"1" => "System",
|
|
|
32 |
"2" => "Baseboard",
|
|
|
33 |
"3" => "Chassis",
|
|
|
34 |
"4" => "Processor",
|
|
|
35 |
"5" => "Memory Controller",
|
|
|
36 |
"6" => "Memory Module",
|
|
|
37 |
"7" => "Cache",
|
|
|
38 |
"8" => "Port Connector",
|
|
|
39 |
"9" => "System Slots",
|
|
|
40 |
"10" => "On Board Devices",
|
|
|
41 |
"11" => "OEM Strings",
|
|
|
42 |
"12" => "System Configuration Options",
|
|
|
43 |
"13" => "BIOS Language",
|
|
|
44 |
"14" => "Group Associations",
|
|
|
45 |
"15" => "System Event Log",
|
|
|
46 |
"16" => "Physical Memory Array",
|
|
|
47 |
"17" => "Memory Device",
|
|
|
48 |
"18" => "32-bit Memory Error",
|
|
|
49 |
"19" => "Memory Array Mapped Address",
|
|
|
50 |
"20" => "Memory Device Mapped Address",
|
|
|
51 |
"21" => "Built-in Pointing Device",
|
|
|
52 |
"22" => "Portable Battery",
|
|
|
53 |
"23" => "System Reset",
|
|
|
54 |
"24" => "Hardware Security",
|
|
|
55 |
"25" => "System Power Controls",
|
|
|
56 |
"26" => "Voltage Probe",
|
|
|
57 |
"27" => "Cooling Device",
|
|
|
58 |
"28" => "Temperature Probe",
|
|
|
59 |
"29" => "Electrical Current Probe",
|
|
|
60 |
"30" => "Out-of-band Remote Access",
|
|
|
61 |
"31" => "Boot Integrity Services",
|
|
|
62 |
"32" => "System Boot",
|
|
|
63 |
"33" => "64-bit Memory Error",
|
|
|
64 |
"34" => "Management Device",
|
|
|
65 |
"35" => "Management Device Component",
|
|
|
66 |
"36" => "Management Device Threshold Data",
|
|
|
67 |
"37" => "Memory Channel",
|
|
|
68 |
"38" => "IPMI Device",
|
|
|
69 |
"39" => "Power Supply",
|
|
|
70 |
"40" => "Additional Information",
|
|
|
71 |
"41" => "Onboard Devices Extended Information",
|
|
|
72 |
"42" => "Management Controller Host Interface"
|
|
|
73 |
);
|
|
|
74 |
|
|
|
75 |
// verify this is something we can work with
|
|
|
76 |
preg_match('/dmidecode ([0-9.]+)/', $contents[0], $results);
|
|
|
77 |
if ( $results[1] != "3.0" ) {
|
|
|
78 |
return "This is only verified with dmidecode v3.0, v$results[1] found\n";
|
|
|
79 |
}
|
|
|
80 |
// first, let's parse it into a hash
|
|
|
81 |
$currentHandle = '';
|
|
|
82 |
$currentType;
|
|
|
83 |
$data;
|
|
|
84 |
for ( $i = 0; $i < count($contents); $i++ ) {
|
|
|
85 |
if ( preg_match('/^Handle ([0-9a-zx]+).*DMI type[^0-9]*(\d+),/i', $contents[$i], $outputArray) ) {
|
|
|
86 |
//print "matched\n"; print_r($outputArray); die;
|
|
|
87 |
$currentType = $outputArray[2];
|
|
|
88 |
$currentHandle = $outputArray[1];
|
|
|
89 |
if ( isset( $standardDMITypes[$currentType] ) || array_key_exists( $currentType,$standardDMITypes ) ) {
|
|
|
90 |
$name = $contents[$i+1];
|
|
|
91 |
$data[$currentType][$currentHandle]['name'] = $name;
|
|
|
92 |
$i += 2; // skip the line with the name, and go to the next line
|
|
|
93 |
} else {
|
|
|
94 |
$currentType = $currentHandle = '';
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
if ( $currentHandle && preg_match('/^\s+(.*):\s+(.*)$/i', $contents[$i], $outputArray) ) {
|
|
|
98 |
$data[$currentType][$currentHandle][$outputArray[1]] = $outputArray[2];
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
return $data;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
$contents = file( 'dmidecode/xen4.dmidecode', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
|
|
|
105 |
$out = dmidecode2array( $contents );
|
|
|
106 |
print_r( $out );
|