class Inspec::Resources::System

this resource returns additional system informatio

Public Instance Methods

hostname(opt = nil) click to toggle source

returns the hostname of the local system

# File lib/inspec/resources/sys_info.rb, line 30
def hostname(opt = nil)
  os = inspec.os
  if os.linux?
    linux_hostname(opt)
  elsif os.darwin?
    mac_hostname(opt)
  elsif os.windows?
    if !opt.nil?
      skip_resource "The `sys_info.hostname` resource is not supported with that option on your OS."
    else
      inspec.powershell("$env:computername").stdout.chomp
    end
  else
    skip_resource "The `sys_info.hostname` resource is not supported on your OS yet."
  end
end
linux_hostname(opt = nil) click to toggle source
# File lib/inspec/resources/sys_info.rb, line 47
def linux_hostname(opt = nil)
  if opt
    opt = case opt
          when "f", "long", "fqdn", "full"
            " -f"
          when "d", "domain"
            " -d"
          when "i", "ip_address"
            " -I"
          when "s", "short"
            " -s"
          else
            "ERROR"
          end
  end
  if opt == "ERROR"
    skip_resource "The `sys_info.hostname` resource is not supported with that option on your OS."
  else
    inspec.command("hostname#{opt}").stdout.chomp
  end
end
mac_hostname(opt = nil) click to toggle source
# File lib/inspec/resources/sys_info.rb, line 69
def mac_hostname(opt = nil)
  if opt
    opt = case opt
          when "f", "long", "fqdn", "full"
            " -f"
          when "s", "short"
            " -s"
          else
            "ERROR"
          end
  end
  if opt == "ERROR"
    skip_resource "The `sys_info.hostname` resource is not supported with that option on your OS."
  else
    inspec.command("hostname#{opt}").stdout.chomp
  end
end
manufacturer() click to toggle source

returns the Manufacturer of the local system

# File lib/inspec/resources/sys_info.rb, line 88
def manufacturer
  os = inspec.os
  if os.darwin?
    "Apple Inc."
  elsif os.linux?
    inspec.command("cat /sys/class/dmi/id/sys_vendor").stdout.chomp
  elsif os.windows?
    inspec.powershell("Get-CimInstance -ClassName Win32_ComputerSystem | Select Manufacturer -ExpandProperty Manufacturer").stdout.chomp
  else
    skip_resource "The `sys_info.manufacturer` resource is not supported on your OS yet."
  end
end
model() click to toggle source

returns the ServerModel of the local system

# File lib/inspec/resources/sys_info.rb, line 102
def model
  os = inspec.os
  if os.darwin?
    inspec.command("sysctl -n hw.model").stdout.chomp
  elsif os.linux?
    inspec.command("cat /sys/class/dmi/id/product_name").stdout.chomp
  elsif os.windows?
    inspec.powershell("Get-CimInstance -ClassName Win32_ComputerSystem | Select Model -ExpandProperty Model").stdout.chomp
  else
    skip_resource "The `sys_info.model` resource is not supported on your OS yet."
  end
end
to_s() click to toggle source
# File lib/inspec/resources/sys_info.rb, line 115
def to_s
  "System Information"
end