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.2.10 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.9 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.8 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.7 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.6 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.5 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.4 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.3 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.2 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.1 lib/facter/resolvers/solaris/dmi.rb
facter-4.2.0 lib/facter/resolvers/solaris/dmi.rb
facter-4.1.1 lib/facter/resolvers/solaris/dmi.rb
facter-4.1.0 lib/facter/resolvers/solaris/dmi.rb
facter-4.0.52 lib/facter/resolvers/solaris/dmi.rb
facter-4.0.51 lib/facter/resolvers/solaris/dmi.rb
facter-4.0.50 lib/facter/resolvers/solaris/dmi.rb