dmidecode – Dump Desktop Management Interface data

The Desktop Management Interface provides a standardized description of a computer’s hardware, including characteristics such as BIOS serial number and hardware connectors. dmidecode provides a dump of the DMI data available from the BIOS.

This facts return values from dmidecode, please note that facter has some facts coming out of dmidecode, but they do not work on all Linux distribution and versions (for example of RHE4 and lower), however this method should work on any Linux distribution that has dmidecode installed. you can choose which values you are interested at, please modify the list, but make sure you keep the syntax:

if FileTest.exists?("/usr/sbin/dmidecode")

# Add remove things to query here
query = { 'BIOS Information' => 'Vendor:', 'System Information' =>  [ 'Manufacturer:', 'Product Name:' , 'Serial Number:', 'Version:' ], 'Chassis Information' => 'Type:', 'Processor Information' => ['Version:', 'Max Speed:'], 'Memory Controller Information' => [ 'Maximum Memory Module Size:', 'Maximum Total Memory Size:' ] }

# Run dmidecode only once
output=%x{/usr/sbin/dmidecode 2>/dev/null}

query.each_pair do |key,v|
  v.each do |value|
    output.split("Handle").each do |line|
      if line =~ /#{key}/  and line =~ /#{value} (\w.*)\n*./
        result = $1
         Facter.add(value.chomp(':')) do
         confine :kernel => :linux
        setcode do
          result
       end
     end
    end
   end
  end
 end
end