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.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/resources/host.rb', line 41

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 address, will return an array



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

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

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

Returns:

  • (Boolean)


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

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 address, the host is resolvable

Returns:

  • (Boolean)


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

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



72
73
74
# File 'lib/resources/host.rb', line 72

def to_s
  "Host #{@hostname}"
end