Puppet: System Administration Automated

Support

DMI Hardware Information Recipe

I wanted to pull the serial number and some other information (like who made the system) out of our Red Hat? systems. I'd already been doing this elsewhere, so I sorta reused my previous work. This uses some python linked against some DMI stuff that works in highly mysterious ways, but that python is already sitting there on any system that talks to RHN.

Unfortunately this only works on Red Hat? Linux and similar systems. At least I know it works on RHEL3 - 5. Also, I haven't (yet) added any logic to figure out which of the various "asset" tags are most useful; there seems to be a lot of variety between manufacturers how they tag that information.

The actual ruby code:

require 'facter'

if FileTest.exists?("/usr/share/rhn/up2date_client/hardware.py")
  output = %x{/usr/bin/python /usr/share/rhn/up2date_client/hardware.py}
  output.split(/\n\n/).each do |chunk|
    if chunk =~ /'class' : 'DMI'/
      chunk.each do |line|
        line.chomp!
        if line =~ /^'([^']*)'\s*:\s*'([^']*)'$/
          key = $1
          data = $2
          # split asset up into different sub-chunks
          if key == "asset"
            data.scan(/\(([^:]+):\s+([^)]+)\)/) do |assetkey,assetdata|
              Facter.add("dmi_hardware_asset_#{assetkey}") { setcode { assetdata } }
            end
          elsif key != "class" # "DMI" -- just the bit we used to find the right block
            Facter.add("dmi_hardware_#{key}") { setcode { data } }
          end
        end
      end
    end
  end
end

A sample of the raw data from an HP blade; the asset "chassis" is the blade enclosure and the "system" is the serial number for the system itself:

'vendor' : 'HP'
'bios_vendor' : 'HP'
'system' : 'ProLiant BL20p G3 '
'bios_release' : '02/14/2006'
'asset' : '(chassis: AB1CDEF23G) (system: A12BCDE34F) '
'bios_version' : 'I08'
'class' : 'DMI'

A sample from a Dell:

'product' : '0K0710'
'bios_release' : '07/11/2003'
'vendor' : 'Dell Computer Corporation'
'board' : 'Dell Computer Corporation'
'bios_version' : 'A15'
'bios_vendor' : 'Dell Computer Corporation'
'class' : 'DMI'
'system' : 'PowerEdge 2650              '
'asset' : '(chassis: 12ABC34) (board: ..AB1234567C8D9E.) (system: 12ABC34) '

A VMware guest (some versions of RHEL leave out the "chassis" asset tag for a VM):

'product' : '440BX Desktop Reference Platform'
'vendor' : 'VMware, Inc.'
'bios_vendor' : 'Phoenix Technologies LTD'
'system' : 'VMware Virtual Platform None'
'bios_release' : '04/17/2006'
'board' : 'Intel Corporation'
'bios_version' : '6.00'
'class' : 'DMI'
'asset' : '(chassis: No Asset Tag) (system: VMware-aa bb cc dd ee ff 11 22-33 44 55 66 77 88 99 aa) '

And and IBM server:

'product' : ''
'bios_release' : '09/24/2004'
'vendor' : 'IBM'
'board' : 'IBM'
'bios_version' : '-[APE117AUS-1.02]-'
'bios_vendor' : 'IBM'
'class' : 'DMI'
'system' : 'eserver xSeries 336 -[883721U]- '
'asset' : '(system: ABCD123) '

Final output in facter looks like:

dmi_hardware_asset_chassis => ABC123
dmi_hardware_asset_system => 321ABCD
dmi_hardware_bios_release => 04/17/2006
dmi_hardware_bios_vendor => Phoenix Technologies LTD
dmi_hardware_bios_version => 6.00
dmi_hardware_board => Intel Corporation
dmi_hardware_product => 440BX Desktop Reference Platform
dmi_hardware_system => VMware Virtual Platform None
dmi_hardware_vendor => VMware, Inc.