Class: Inspec::Resources::Host

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

Instance Method Summary collapse

Constructor Details

#initialize(hostname, params = {}) ⇒ Host

Returns a new instance of Host.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/resources/host.rb', line 37

def initialize(hostname, params = {})
  @hostname = hostname
  @port = params[:port]   || nil
  @proto = params[:proto] || nil

  @host_provider = nil
  if inspec.os.linux?
    @host_provider = LinuxHostProvider.new(inspec)
  elsif inspec.os.windows?
    @host_provider = WindowsHostProvider.new(inspec)
  else
    return skip_resource 'The `host` resource is not supported on your OS yet.'
  end
end

Instance Method Details

#ipaddressObject

returns all A records of the IP adress, will return an array



64
65
66
# File 'lib/resources/host.rb', line 64

def ipaddress
  resolve.nil? || resolve.empty? ? nil : resolve
end

#reachable?(port = nil, proto = nil, timeout = nil) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
# File 'lib/resources/host.rb', line 58

def reachable?(port = nil, proto = nil, timeout = nil)
  fail "Use `host` resource with host('#{@hostname}', port: #{port}, proto: '#{proto}') parameters." if !port.nil? || !proto.nil? || !timeout.nil?
  ping.nil? ? false : ping
end

#resolvable?(type = nil) ⇒ Boolean

if we get the IP adress, the host is resolvable

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/resources/host.rb', line 53

def resolvable?(type = nil)
  warn "The `host` resource ignores #{type} parameters. Continue to resolve host." if !type.nil?
  resolve.nil? || resolve.empty? ? false : true
end

#to_sObject



68
69
70
# File 'lib/resources/host.rb', line 68

def to_s
  "Host #{@hostname}"
end