| Line 64... |
Line 64... |
| 64 |
$value = substr( $falsetrue, $value, 0, 1 );
|
64 |
$value = substr( $falsetrue, $value, 0, 1 );
|
| 65 |
break;
|
65 |
break;
|
| 66 |
} // switch
|
66 |
} // switch
|
| 67 |
return $value;
|
67 |
return $value;
|
| 68 |
}
|
68 |
}
|
| 69 |
|
- |
|
| 70 |
/*
|
- |
|
| 71 |
* Trims a value, then compares it to several 'null' possibilities
|
- |
|
| 72 |
* if it is a null, returns empty string, otherwise returns value
|
- |
|
| 73 |
*/
|
- |
|
| 74 |
function cleanUpDMIValue( $value ) {
|
- |
|
| 75 |
$value = trim( $value );
|
- |
|
| 76 |
switch (strtolower( $value )) {
|
- |
|
| 77 |
case 'unknown':
|
- |
|
| 78 |
case 'unspecified' :
|
- |
|
| 79 |
case 'not available':
|
- |
|
| 80 |
case 'to be filled by o.e.m.':
|
- |
|
| 81 |
case 'not specified': return '';
|
- |
|
| 82 |
}
|
- |
|
| 83 |
return $value;
|
- |
|
| 84 |
}
|
- |
|
| 85 |
|
- |
|
| 86 |
/*
|
- |
|
| 87 |
* Read value from array of hash, return array of "$outputKey\tvalue" for each entry found
|
- |
|
| 88 |
* If nothing found, returns empty array
|
- |
|
| 89 |
* if $unique is true, returns first non-empty value found
|
- |
|
| 90 |
* if $outputKey is not defined, uses $key
|
- |
|
| 91 |
*/
|
- |
|
| 92 |
function getDMIInformation( $data, $type, $key, $outputKey = '', $unique = true ) {
|
- |
|
| 93 |
$return = array();
|
- |
|
| 94 |
foreach ( $data[$type] as $handle ) {
|
- |
|
| 95 |
if ( isset( $handle[$key]) ) {
|
- |
|
| 96 |
$a = cleanUpDMIValue( $handle[$key] );
|
- |
|
| 97 |
if ( $a ) {
|
- |
|
| 98 |
$return[] = ( $outputKey ? $outputKey : $key ) . "\t" . $a;
|
- |
|
| 99 |
if ( $unique ) {
|
- |
|
| 100 |
return $return;
|
- |
|
| 101 |
}
|
- |
|
| 102 |
}
|
- |
|
| 103 |
}
|
- |
|
| 104 |
}
|
- |
|
| 105 |
return $return;
|
- |
|
| 106 |
}
|
- |
|
| 107 |
|
- |
|
| 108 |
/*
|
- |
|
| 109 |
* adds $value to array
|
- |
|
| 110 |
* if $value is scalar, simply adds it
|
- |
|
| 111 |
* if $value is array, adds every row
|
- |
|
| 112 |
* returns modified array
|
- |
|
| 113 |
*/
|
- |
|
| 114 |
function mergeArrays( $array, $value ) {
|
- |
|
| 115 |
if ( $value ) {
|
- |
|
| 116 |
switch (gettype( $value ) ) {
|
- |
|
| 117 |
case 'array' : foreach ( $value as $thisVal ) {
|
- |
|
| 118 |
$array[] = $thisVal;
|
- |
|
| 119 |
}
|
- |
|
| 120 |
break;
|
- |
|
| 121 |
case 'boolean' :
|
- |
|
| 122 |
case 'integer' :
|
- |
|
| 123 |
case 'double' :
|
- |
|
| 124 |
case 'string' : $array[] = $value;
|
- |
|
| 125 |
} // switch
|
- |
|
| 126 |
}
|
- |
|
| 127 |
return $array;
|
- |
|
| 128 |
} //mergeArrays
|
- |
|
| 129 |
|
- |
|
| 130 |
/*
|
- |
|
| 131 |
* Function will take an array of lines representing the output of a dmidecode file
|
- |
|
| 132 |
* and pick and choose the values we want to put into CAMP attributes.
|
- |
|
| 133 |
* It will return an array of key/value pairs to be added into the attributes table
|
- |
|
| 134 |
*
|
- |
|
| 135 |
* NOTE: this is a summary of values we decided to store. dmidecode files have a lot of
|
- |
|
| 136 |
* additional information we chose not to include
|
- |
|
| 137 |
*
|
- |
|
| 138 |
*/
|
- |
|
| 139 |
|
- |
|
| 140 |
function dmidecode2array( $contents ) {
|
- |
|
| 141 |
|
- |
|
| 142 |
// allows us to group the dmi types by function. not implemented
|
- |
|
| 143 |
$dmiGroups = array(
|
- |
|
| 144 |
"bios" => "0,13",
|
- |
|
| 145 |
"system" => "1,12,15,23,32",
|
- |
|
| 146 |
"baseboard" => "2,10,41",
|
- |
|
| 147 |
"chassis" => "3",
|
- |
|
| 148 |
"processor" => "4",
|
- |
|
| 149 |
"memory" => "5,6,16,17",
|
- |
|
| 150 |
"cache" => "7",
|
- |
|
| 151 |
"connector" => "8",
|
- |
|
| 152 |
"slot" => "9"
|
- |
|
| 153 |
);
|
- |
|
| 154 |
|
- |
|
| 155 |
// This contains the standard DMI types, ie no OEM stuff. For reference, not used in code
|
- |
|
| 156 |
|
- |
|
| 157 |
$standardDMITypes = array(
|
- |
|
| 158 |
"0" => "BIOS",
|
- |
|
| 159 |
"1" => "System",
|
- |
|
| 160 |
"2" => "Baseboard",
|
- |
|
| 161 |
"3" => "Chassis",
|
- |
|
| 162 |
"4" => "Processor",
|
- |
|
| 163 |
"5" => "Memory Controller",
|
- |
|
| 164 |
"6" => "Memory Module",
|
- |
|
| 165 |
"7" => "Cache",
|
- |
|
| 166 |
"8" => "Port Connector",
|
- |
|
| 167 |
"9" => "System Slots",
|
- |
|
| 168 |
"10" => "On Board Devices",
|
- |
|
| 169 |
"11" => "OEM Strings",
|
- |
|
| 170 |
"12" => "System Configuration Options",
|
- |
|
| 171 |
"13" => "BIOS Language",
|
- |
|
| 172 |
"14" => "Group Associations",
|
- |
|
| 173 |
"15" => "System Event Log",
|
- |
|
| 174 |
"16" => "Physical Memory Array",
|
- |
|
| 175 |
"17" => "Memory Device",
|
- |
|
| 176 |
"18" => "32-bit Memory Error",
|
- |
|
| 177 |
"19" => "Memory Array Mapped Address",
|
- |
|
| 178 |
"20" => "Memory Device Mapped Address",
|
- |
|
| 179 |
"21" => "Built-in Pointing Device",
|
- |
|
| 180 |
"22" => "Portable Battery",
|
- |
|
| 181 |
"23" => "System Reset",
|
- |
|
| 182 |
"24" => "Hardware Security",
|
- |
|
| 183 |
"25" => "System Power Controls",
|
- |
|
| 184 |
"26" => "Voltage Probe",
|
- |
|
| 185 |
"27" => "Cooling Device",
|
- |
|
| 186 |
"28" => "Temperature Probe",
|
- |
|
| 187 |
"29" => "Electrical Current Probe",
|
- |
|
| 188 |
"30" => "Out-of-band Remote Access",
|
- |
|
| 189 |
"31" => "Boot Integrity Services",
|
- |
|
| 190 |
"32" => "System Boot",
|
- |
|
| 191 |
"33" => "64-bit Memory Error",
|
- |
|
| 192 |
"34" => "Management Device",
|
- |
|
| 193 |
"35" => "Management Device Component",
|
- |
|
| 194 |
"36" => "Management Device Threshold Data",
|
- |
|
| 195 |
"37" => "Memory Channel",
|
- |
|
| 196 |
"38" => "IPMI Device",
|
- |
|
| 197 |
"39" => "Power Supply",
|
- |
|
| 198 |
"40" => "Additional Information",
|
- |
|
| 199 |
"41" => "Onboard Devices Extended Information",
|
- |
|
| 200 |
"42" => "Management Controller Host Interface"
|
- |
|
| 201 |
);
|
- |
|
| 202 |
|
- |
|
| 203 |
// verify this is something we can work with, First line should be the version of dmidecode found
|
- |
|
| 204 |
if ( preg_match('/dmidecode ([0-9.]+)/', $contents[0], $results) ) {
|
- |
|
| 205 |
$dmidecodeVersion = $results[1];
|
- |
|
| 206 |
} else {
|
- |
|
| 207 |
return "Not a valid dmidecode file";
|
- |
|
| 208 |
}
|
- |
|
| 209 |
// first, let's parse it into a hash
|
- |
|
| 210 |
$currentHandle = '';
|
- |
|
| 211 |
$currentType;
|
- |
|
| 212 |
$data = array();
|
- |
|
| 213 |
for ( $i = 0; $i < count($contents); $i++ ) {
|
- |
|
| 214 |
if ( preg_match('/^Handle ([0-9a-zx]+).*DMI type[^0-9]*(\d+),/i', $contents[$i], $outputArray) ) {
|
- |
|
| 215 |
//print "matched\n"; print_r($outputArray); die;
|
- |
|
| 216 |
$currentType = $outputArray[2];
|
- |
|
| 217 |
$currentHandle = $outputArray[1];
|
- |
|
| 218 |
if ( isset( $standardDMITypes[$currentType] ) || array_key_exists( $currentType,$standardDMITypes ) ) {
|
- |
|
| 219 |
$name = $contents[$i+1];
|
- |
|
| 220 |
$data[$currentType][$currentHandle]['name'] = $name;
|
- |
|
| 221 |
$i += 2; // skip the line with the name, and go to the next line
|
- |
|
| 222 |
} else {
|
- |
|
| 223 |
$currentType = $currentHandle = '';
|
- |
|
| 224 |
}
|
- |
|
| 225 |
}
|
- |
|
| 226 |
if ( $currentHandle && preg_match('/^\s+(.*):\s+(.*)$/i', $contents[$i], $outputArray) ) {
|
- |
|
| 227 |
$data[$currentType][$currentHandle][$outputArray[1]] = $outputArray[2];
|
- |
|
| 228 |
}
|
- |
|
| 229 |
}
|
- |
|
| 230 |
# well, we have at least one entry, so let's go
|
- |
|
| 231 |
$return = array();
|
- |
|
| 232 |
// manufacturer info
|
- |
|
| 233 |
$return = mergeArrays( $return, getDMIInformation( $data, '1','Manufacturer' ) );
|
- |
|
| 234 |
$return = mergeArrays( $return, getDMIInformation( $data, '1','Product Name', 'Model' ) );
|
- |
|
| 235 |
$return = mergeArrays( $return, getDMIInformation( $data, '1','Serial Number' ) );
|
- |
|
| 236 |
$return = mergeArrays( $return, getDMIInformation( $data, '1','UUID' ) );
|
- |
|
| 237 |
// physical machine
|
- |
|
| 238 |
$return = mergeArrays( $return, getDMIInformation( $data, '3','Type', 'Enclosure Type' ) );
|
- |
|
| 239 |
$return = mergeArrays( $return, getDMIInformation( $data, '3','Asset Tag', 'Enclosure Asset Tag' ) );
|
- |
|
| 240 |
$return = mergeArrays( $return, getDMIInformation( $data, '3','Height', 'Enclosure Height' ) );
|
- |
|
| 241 |
|
- |
|
| 242 |
// firmware version
|
- |
|
| 243 |
$return = mergeArrays( $return, getDMIInformation( $data, '0','Vendor', 'Firmware Vendor' ) );
|
- |
|
| 244 |
$return = mergeArrays( $return, getDMIInformation( $data, '0','Release Date', 'Firmware Release' ) );
|
- |
|
| 245 |
$return = mergeArrays( $return, getDMIInformation( $data, '0','Version', 'Firmware Version' ) );
|
- |
|
| 246 |
$return = mergeArrays( $return, getDMIInformation( $data, '0','Firmware Revision', 'Firmware Revision' ) );
|
- |
|
| 247 |
// processor information. NOTE: assumes all sockets populated and all processors the saem
|
- |
|
| 248 |
if ( isset( $data['4'] ) ) // count the number of sockets
|
- |
|
| 249 |
$return[] = "CPU Count\t" . count( $data['4'] );
|
- |
|
| 250 |
$return = mergeArrays( $return, getDMIInformation( $data, '4','Family', 'CPU Family' ) );
|
- |
|
| 251 |
$return = mergeArrays( $return, getDMIInformation( $data, '4','Manufacturer', 'CPU Manufacturer' ) );
|
- |
|
| 252 |
$return = mergeArrays( $return, getDMIInformation( $data, '4','Version', 'CPU Version' ) );
|
- |
|
| 253 |
$return = mergeArrays( $return, getDMIInformation( $data, '4','Current Speed', 'CPU Speed' ) );
|
- |
|
| 254 |
$return = mergeArrays( $return, getDMIInformation( $data, '4','Core Count', 'CPU Cores (ea)' ) );
|
- |
|
| 255 |
$return = mergeArrays( $return, getDMIInformation( $data, '4','Thread Count', 'CPU Threads (ea)' ) );
|
- |
|
| 256 |
|
- |
|
| 257 |
/*
|
- |
|
| 258 |
* memory information. We want details on each slot for this, so we have to go through each entry, one at a time.
|
- |
|
| 259 |
* For readability, we also want to take several values and turn them into one human
|
- |
|
| 260 |
* readable string for each socket. So, we go through each entry in the memory socket, determine if it is populated
|
- |
|
| 261 |
* then concat it together for a pretty output
|
- |
|
| 262 |
*/
|
- |
|
| 263 |
|
- |
|
| 264 |
if ( isset( $data['17'] ) ) {
|
- |
|
| 265 |
$return[] = "Memory Slots\t" . count( $data['17'] );
|
- |
|
| 266 |
$totalRAM = 0; // we'll accumulate the total size as we find slots populated
|
- |
|
| 267 |
foreach ( $data['17'] as $entry ) { // type 17 has one entry for every DIMM slot
|
- |
|
| 268 |
$mem = array(); // fill this up with the values we want to turn into a string, then we'll implode it into the string
|
- |
|
| 269 |
$mem[] = trim($entry['Locator'] ? $entry['Locator'] : ($entry['Bank Locator'] ? $entry['Bank Locator'] : '' ));
|
- |
|
| 270 |
if ( $entry['Size'] == 'No Module Installed' ) {
|
- |
|
| 271 |
$mem[] = 'Unpopulated';
|
- |
|
| 272 |
} else {
|
- |
|
| 273 |
$mem[] = trim($entry['Size']); // size can be kilo, meg, gig, tera, so convert it to mega
|
- |
|
| 274 |
if ( preg_match('/(\d+)\s+(GB|MB|TB|kb)/i', $entry['Size'] , $outputArray) ) {
|
- |
|
| 275 |
switch ( strtolower( $outputArray[2] ) ) {
|
- |
|
| 276 |
case 'gb' :
|
- |
|
| 277 |
$outputArray[1] *= 1024;
|
- |
|
| 278 |
break;
|
- |
|
| 279 |
case 'tb' :
|
- |
|
| 280 |
$outputArray[1] *= 1024 * 1024;
|
- |
|
| 281 |
break;
|
- |
|
| 282 |
case 'kb' :
|
- |
|
| 283 |
$outputArray[1] /= 1024;
|
- |
|
| 284 |
break;
|
- |
|
| 285 |
}
|
- |
|
| 286 |
$totalRAM += $outputArray[1];
|
- |
|
| 287 |
}
|
- |
|
| 288 |
$mem[] = trim($entry['Form Factor']);
|
- |
|
| 289 |
$mem[] = trim($entry['Type']);
|
- |
|
| 290 |
$mem[] = trim($entry['Data Width']);
|
- |
|
| 291 |
if ( isset( $entry['Configured Clock Speed']) && isset($entry['Speed']) && cleanUpDMIValue($entry['Configured Clock Speed']) && cleanUpDMIValue($entry['Speed']) )
|
- |
|
| 292 |
$mem[] = cleanUpDMIValue($entry['Configured Clock Speed'] . '/' . cleanUpDMIValue($entry['Speed']) );
|
- |
|
| 293 |
if ( isset($entry['Manufacturer']) && cleanUpDMIValue($entry['Manufacturer']) )
|
- |
|
| 294 |
$mem[] = cleanUpDMIValue($entry['Manufacturer']);
|
- |
|
| 295 |
if ( isset($entry['Part Number']) && cleanUpDMIValue( $entry['Part Number'] ) )
|
- |
|
| 296 |
$mem[] = 'p/n ' . cleanUpDMIValue($entry['Part Number']);
|
- |
|
| 297 |
if ( isset($entry['Serial Number']) && trim($entry['Serial Number']) != 'Not Specified' )
|
- |
|
| 298 |
$mem[] = 's/n ' . cleanUpDMIValue($entry['Serial Number']);
|
- |
|
| 299 |
}
|
- |
|
| 300 |
$return[] = "Memory\t" . implode( ', ', $mem );
|
- |
|
| 301 |
}
|
- |
|
| 302 |
$return[] = "Memory Total\t$totalRAM MB";
|
- |
|
| 303 |
}
|
- |
|
| 304 |
|
- |
|
| 305 |
/*
|
- |
|
| 306 |
* power supplies. Most workstations will not even have an entry here, but for servers we will have details on each individual
|
- |
|
| 307 |
* power supply, including the part number, serial number, etc..., so like memory, we want a detailed listing with a human
|
- |
|
| 308 |
* readable string for each psu
|
- |
|
| 309 |
*/
|
- |
|
| 310 |
if ( isset( $data['39'] ) ) {
|
- |
|
| 311 |
$return[] = "Power Supply Count\t" . count( $data['39'] );
|
- |
|
| 312 |
foreach ( $data['39'] as $entry ) {
|
- |
|
| 313 |
if ( preg_match('/^Present/i', $entry['Status'] ) ) {
|
- |
|
| 314 |
$psu = array();
|
- |
|
| 315 |
$psu[] = trim($entry['Name']);
|
- |
|
| 316 |
$psu[] = trim($entry['Max Power Capacity']);
|
- |
|
| 317 |
$psu[] = trim($entry['Manufacturer']);
|
- |
|
| 318 |
$psu[] = 'p/n ' . trim($entry['Model Part Number']);
|
- |
|
| 319 |
$psu[] = 's/n ' . trim($entry['Serial Number']);
|
- |
|
| 320 |
$return[] = "Power Supply\t" . implode( ', ', $psu );
|
- |
|
| 321 |
}
|
- |
|
| 322 |
}
|
- |
|
| 323 |
}
|
- |
|
| 324 |
return array( $return );
|
- |
|
| 325 |
} // dmidecode2array
|
- |
|
| 326 |
|
- |
|
| 327 |
/*
|
- |
|
| 328 |
* Test code for dmidecode input
|
- |
|
| 329 |
*/
|
- |
|
| 330 |
/*
|
- |
|
| 331 |
$filename = $argv[1];
|
- |
|
| 332 |
if ( $filename ) {
|
- |
|
| 333 |
$contents = file( $filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
|
- |
|
| 334 |
$out = dmidecode2array( $contents );
|
- |
|
| 335 |
print_r( $out );
|
- |
|
| 336 |
} else {
|
- |
|
| 337 |
print "You must pass the file as the first command line parameter\n";
|
- |
|
| 338 |
}
|
- |
|
| 339 |
*/
|
- |
|
| 340 |
|
- |
|
| 341 |
/****************************************************************************************
|
69 |
/****************************************************************************************
|
| 342 |
* Functions to process an array the device_attrib table
|
70 |
* Functions to process an array the device_attrib table
|
| 343 |
***************************************************************************************/
|
71 |
***************************************************************************************/
|
| 344 |
|
72 |
|
| 345 |
/*
|
73 |
/*
|
| Line 454... |
Line 182... |
| 454 |
*/
|
182 |
*/
|
| 455 |
function parseTabDelimFile ( $contents, $createAttributeIfNotFound = false, $createDeviceIfNotFound = false, $default_device_id='', $default_site_id='', $default_client_id='' ) {
|
183 |
function parseTabDelimFile ( $contents, $createAttributeIfNotFound = false, $createDeviceIfNotFound = false, $default_device_id='', $default_site_id='', $default_client_id='' ) {
|
| 456 |
$data = tabDelimToArray( $contents );
|
184 |
$data = tabDelimToArray( $contents );
|
| 457 |
// we'll put our SQL into an array, then dump it.
|
185 |
// we'll put our SQL into an array, then dump it.
|
| 458 |
$sql = array();
|
186 |
$sql = array();
|
| - |
|
187 |
/*
|
| - |
|
188 |
print "<pre>";
|
| - |
|
189 |
var_dump( $createAttributeIfNotFound, $createDeviceIfNotFound, $default_device_id, $default_site_id, $default_client_id );
|
| - |
|
190 |
print "</pre>";
|
| - |
|
191 |
return $sql;
|
| - |
|
192 |
*/
|
| 459 |
// the following two arrays will store attributes and devices as we find them
|
193 |
// the following two arrays will store attributes and devices as we find them
|
| 460 |
// we can then FIRST look them up here, in memory, and go to database only when we don't know them
|
194 |
// we can then FIRST look them up here, in memory, and go to database only when we don't know them
|
| 461 |
$attributesFromDatabase = array(); // uniquely store our attributes here
|
195 |
$attributesFromDatabase = array(); // uniquely store our attributes here
|
| 462 |
$deviceFromDatabase = array();
|
196 |
$deviceFromDatabase = array();
|
| 463 |
for ( $i = 0; $i < count( $data ); $i++ ) { // go through each line and grab fields we need
|
197 |
for ( $i = 0; $i < count( $data ); $i++ ) { // go through each line and grab fields we need
|