Class: Inspec::Resources::System

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/resources/sys_info.rb

Overview

this resource returns additional system informatio

Instance Method Summary collapse

Instance Method Details

#hostname(opt = nil) ⇒ Object

returns the hostname of the local system



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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

#manufacturerObject

returns the Manufacturer of the local system



88
89
90
91
92
93
94
95
96
97
98
99
# 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

#modelObject

returns the ServerModel of the local system



102
103
104
105
106
107
108
109
110
111
112
113
# 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

#resource_idObject



115
116
117
# File 'lib/inspec/resources/sys_info.rb', line 115

def resource_id
  "sys_info"
end

#to_sObject



119
120
121
# File 'lib/inspec/resources/sys_info.rb', line 119

def to_s
  "System Information"
end