module Kanrisuru::Core::Dmi
Constants
- AdditionalInformation
Type 40: Additional Information
- BIOS
Type 0:
BIOS
Information- BIOSLanguage
Type 13:
BIOS
Language Information- Baseboard
Type 2:
Baseboard
Information- BootIntegrityServices
Type 31: Boot Integrity Services Entry Point
- BuiltInPointingDevice
Type 21: Built-In Pointing Device
- Cache
Type 7:
Cache
Information- Chassis
Type 3:
Chassis
Information- CoolingDevice
Type 27: Cooling Device
- ElectricalCurrentProbe
Type 29: Electrical Current Probe
- GroupAssociation
Type 14:
Group
Associations- HardwareSecurity
Type 24: Hardware Security
- IPMIDevice
Type 38: IPMI Device Information
- ManagementControllerHostInterface
- ManagementDevice
Type 34: Management Device
- ManagementDeviceComponent
Type 35: Management Device Component
- ManagementDeviceThresholdData
Type 36: Management Device Threshold Data
- MemoryArrayMappedAddress
Type 19: Memory Array Mapped Address
- MemoryChannel
- MemoryChannelDevice
Type 37: Memory Channel
- MemoryController
Type 5: Memory Controller Information
- MemoryDevice
Type 17: Memory Device
- MemoryDeviceMappedAddress
Type 20: Memory Device Mapped Address
- MemoryError32Bit
Type 18: 32-bit Memory
Error
Information- MemoryError64Bit
Type 33: 64-bit Memory
Error
- MemoryModule
Type 6: Memory Module Information
- OEMStrings
Type 11: OEM Strings
- OnBoardDevice
Type 10: On Board Device Information
- OnboardDevicesExtendedInformation
Type 41: On Board Devices Extended Information
- OutOfBandRemoteAccess
Type 30: Out-of-band
Remote
Access- PhysicalMemoryArray
Type 16: Physical Memory Array
- PortConnector
Type 8: Port Connector Information
- PortableBattery
Type 22: Portable Battery
- Processor
Type 4:
Processor
Information- ProtocolRecord
Type 42: Management Controller Host Interface
- System
Type 1: Sytem Information
- SystemBoot
Type 32:
System
Boot- SystemConfigurationOptions
Type 12:
System
Configuration Options- SystemEventLog
Type 15:
System
Event Log- SystemPowerControls
Type 25:
System
Power Controls- SystemPowerSupply
Type 39:
System
Power Supply- SystemReset
Type 23:
System
Reset- SystemSlots
Type 9: Sytem Slots
- TPMDevice
Type 43: TPM Device
- TemperatureProbe
Type 28: Temperature Probe
- VoltageProbe
Type 26: Voltage Probe
Public Instance Methods
# File lib/kanrisuru/core/dmi.rb, line 364 def dmi(opts = {}) command = Kanrisuru::Command.new('dmidecode') dmi_type_opts(command, opts) execute_shell(command) Kanrisuru::Result.new(command) do |cmd| lines = cmd.to_a rows = [] current_struct = nil wrapped_field_line = nil lines.each do |line| next if Kanrisuru::Util.blank?(line) case line when /^Handle/ if current_struct rows << current_struct current_struct = nil wrapped_field_line = nil end values = line.split(', ') handle = values[0].split('Handle ')[1] type = values[1].split(/(\d+)/)[1].to_i type = Kanrisuru::Util::DmiType[type] next if Kanrisuru::Util.blank?(type) bytes = values[2].split(/(\d+)/)[1] current_struct = dmi_type_to_struct(type) current_struct.dmi_handle = handle current_struct.dmi_type = type current_struct.dmi_size = bytes.to_i when /:/ values = line.split(': ') field = values[0].strip value = values[1] ? values[1].strip : '' dmi_append_field(current_struct, field, value) case line when 'Characteristics:' current_struct.characteristics = [] wrapped_field_line = :characteristics when 'Flags:' current_struct.flags = [] wrapped_field_line = :flags when 'Supported SRAM Types:' current_struct.supported_sram_types = [] wrapped_field_line = :supported_sram_types when 'Features:' current_struct.features = [] wrapped_field_line = :features when 'Strings:' current_struct.strings = [] wrapped_field_line = :strings end else current_struct[wrapped_field_line] << line.strip if wrapped_field_line end end rows << current_struct if current_struct rows end end
Private Instance Methods
# File lib/kanrisuru/core/dmi.rb, line 440 def dmi_append_field(struct, field, value) field = dmi_field_translate(struct, field) field = field.to_sym if struct.respond_to?(field) case struct.dmi_type when 'OEM Strings' if struct.strings struct[field] << value else struct.strings = [value] end else struct[field] = value end else Kanrisuru.logger.warn("Field does not exist for: #{struct.dmi_type}: #{field} => #{value}") end end
# File lib/kanrisuru/core/dmi.rb, line 460 def dmi_field_translate(struct, field) field = field.downcase field = field.gsub(/\s/, '_') field = field.gsub('-', '_') field = field.gsub(':', '') case struct.dmi_type when 'Memory Device' case field when 'size' return 'mem_size' end when 'System Slots' case field when 'length' return 'slot_length' end when 'OEM Strings' case field when /^string/ return 'strings' end when 'Boot Integrity Services' case field when '16_bit_entry_point_address' return 'sixteen_bit_entry_point_address' when '32_bit_entry_point_address' return 'thirty_two_bit_entry_point_address' end end field end
# File lib/kanrisuru/core/dmi.rb, line 510 def dmi_type_opts(command, opts) return unless Kanrisuru::Util.present?(opts[:types]) types = opts[:types] types = types.instance_of?(Array) ? types : [types] types.each do |type| type = parse_dmi_type(type) command.append_arg('--type', type) end end
# File lib/kanrisuru/core/dmi.rb, line 494 def dmi_type_to_struct(type) type = case type when '32-bit Memory Error' 'Memory Error 32 Bit' when '64-bit Memory Error' 'Memory Error 64 Bit' else type end type_camelized = Kanrisuru::Util.camelize(type.gsub(/\s/, '')) struct_class = Kanrisuru::Core::Dmi.const_get(type_camelized) struct_class.new end
# File lib/kanrisuru/core/dmi.rb, line 522 def parse_dmi_type(type) raise ArgumentError, 'Invalid DMI type' unless Kanrisuru::Util::DmiType.valid?(type) if type.instance_of?(Integer) type else Kanrisuru::Util::DmiType[type] end end