Subversion Repositories computer_asset_manager_v1

Rev

Rev 97 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

<?php



/*
 * Function will take an array of lines representing the output of a dmidecode file
 * and pick and choose the values we want to put into CAMP attributes.
 * It will return an array of key/value pairs to be added into the attributes table
 * 
 */

function dmidecode2array( $contents ) {

// allows us to group the dmi types by function
$dmiGroups = array(
      "bios" => "0,13",
      "system" => "1,12,15,23,32",
      "baseboard" => "2,10,41",
      "chassis" => "3",
      "processor" => "4",
      "memory" => "5,6,16,17",
      "cache" => "7",
      "connector" => "8",
      "slot" => "9"
);

// This contains the standard DMI types, ie no OEM stuff

$standardDMITypes = array( 
      "0" => "BIOS",
      "1" => "System",
      "2" => "Baseboard",
      "3" => "Chassis",
      "4" => "Processor",
      "5" => "Memory Controller",
      "6" => "Memory Module",
      "7" => "Cache",
      "8" => "Port Connector",
      "9" => "System Slots",
      "10" => "On Board Devices",
      "11" => "OEM Strings",
      "12" => "System Configuration Options",
      "13" => "BIOS Language",
      "14" => "Group Associations",
      "15" => "System Event Log",
      "16" => "Physical Memory Array",
      "17" => "Memory Device",
      "18" => "32-bit Memory Error",
      "19" => "Memory Array Mapped Address",
      "20" => "Memory Device Mapped Address",
      "21" => "Built-in Pointing Device",
      "22" => "Portable Battery",
      "23" => "System Reset",
      "24" => "Hardware Security",
      "25" => "System Power Controls",
      "26" => "Voltage Probe",
      "27" => "Cooling Device",
      "28" => "Temperature Probe",
      "29" => "Electrical Current Probe",
      "30" => "Out-of-band Remote Access",
      "31" => "Boot Integrity Services",
      "32" => "System Boot",
      "33" => "64-bit Memory Error",
      "34" => "Management Device",
      "35" => "Management Device Component",
      "36" => "Management Device Threshold Data",
      "37" => "Memory Channel",
      "38" => "IPMI Device",
      "39" => "Power Supply",
      "40" => "Additional Information",
      "41" => "Onboard Devices Extended Information",
      "42" => "Management Controller Host Interface"
);
   
   // verify this is something we can work with
   preg_match('/dmidecode ([0-9.]+)/', $contents[0], $results);
   if ( $results[1] != "3.0" ) {
      return "This is only verified with dmidecode v3.0, v$results[1] found\n";
   }
   // first, let's parse it into a hash
   $currentHandle = '';
   $currentType;
   $data;
   for ( $i = 0; $i < count($contents); $i++ ) {
      if ( preg_match('/^Handle ([0-9a-zx]+).*DMI type[^0-9]*(\d+),/i', $contents[$i], $outputArray) ) {
         //print "matched\n"; print_r($outputArray); die;
         $currentType = $outputArray[2];
         $currentHandle = $outputArray[1];
         if ( isset( $standardDMITypes[$currentType] ) || array_key_exists( $currentType,$standardDMITypes ) ) {
            $name = $contents[$i+1];
            $data[$currentType][$currentHandle]['name'] = $name;
            $i += 2; // skip the line with the name, and go to the next line
         } else {
            $currentType = $currentHandle = '';
         }
      }
      if ( $currentHandle &&  preg_match('/^\s+(.*):\s+(.*)$/i', $contents[$i], $outputArray) ) {
         $data[$currentType][$currentHandle][$outputArray[1]] = $outputArray[2];
      }
   }
   return $data;
}
 
$contents = file( 'dmidecode/xen4.dmidecode', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
$out = dmidecode2array( $contents );
print_r( $out );