Sha256: 4f726352449b5051a39eb225fe4e38f0a95c1872a3e31f7dc7b381982424e87d

Contents?: true

Size: 1.58 KB

Versions: 36

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Solaris
      class Dmi < BaseResolver
        init_resolver

        class << self
          private

          def post_resolve(fact_name, _options)
            @fact_list.fetch(fact_name) { read_facts(fact_name) }
          end

          SMBIOS_PARAMS = {
            'SMB_TYPE_BIOS' => {
              bios_version: 'Version String: (.+)',
              bios_vendor: 'Vendor: (.+)',
              bios_release_date: 'Release Date: (.+)'
            },
            'SMB_TYPE_SYSTEM' => {
              manufacturer: 'Manufacturer: (.+)',
              product_name: 'Product: (.+)',
              serial_number: 'Serial Number: (.+)',
              product_uuid: 'UUID: (.+)'
            },
            'SMB_TYPE_CHASSIS' => {
              chassis_asset_tag: 'Asset Tag: (.+)',
              chassis_type: '(?:Chassis )?Type: (.+)'
            }
          }.freeze

          def read_facts(fact_name)
            param = SMBIOS_PARAMS.find { |_key, hash| hash[fact_name] }
            return nil unless param

            output = exec_smbios(param[0])
            facts = param[1]
            return unless output

            facts.each do |name, regx|
              @fact_list[name] = output.match(/#{regx}/)&.captures&.first
            end

            @fact_list[fact_name]
          end

          def exec_smbios(args)
            return unless File.executable?('/usr/sbin/smbios')

            Facter::Core::Execution.execute("/usr/sbin/smbios -t #{args}", logger: log)
          end
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/resolvers/solaris/dmi.rb
facter-4.9.0 lib/facter/resolvers/solaris/dmi.rb
facter-4.8.0 lib/facter/resolvers/solaris/dmi.rb
facter-4.7.1 lib/facter/resolvers/solaris/dmi.rb
facter-4.7.0 lib/facter/resolvers/solaris/dmi.rb
facter-4.6.1 lib/facter/resolvers/solaris/dmi.rb
facter-4.6.0 lib/facter/resolvers/solaris/dmi.rb
facter-4.5.2 lib/facter/resolvers/solaris/dmi.rb
facter-4.5.1 lib/facter/resolvers/solaris/dmi.rb
facter-4.5.0 lib/facter/resolvers/solaris/dmi.rb
facter-4.4.3 lib/facter/resolvers/solaris/dmi.rb
facter-4.4.2 lib/facter/resolvers/solaris/dmi.rb
facter-4.4.1 lib/facter/resolvers/solaris/dmi.rb
facter-4.4.0 lib/facter/resolvers/solaris/dmi.rb
facter-4.3.1 lib/facter/resolvers/solaris/dmi.rb
facter-4.3.0 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.14 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.13 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.12 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.11 lib/facter/resolvers/solaris/dmi.rb