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
55
56
57
58
# File 'lib/resources/host.rb', line 41

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

  return skip_resource 'The UDP protocol for the `host` resource is not supported yet.' if @proto == 'udp'

  @host_provider = nil
  if inspec.os.linux?
    @host_provider = LinuxHostProvider.new(inspec)
  elsif inspec.os.windows?
    @host_provider = WindowsHostProvider.new(inspec)
  elsif inspec.os.darwin?
    @host_provider = DarwinHostProvider.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



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

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

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

Returns:

  • (Boolean)


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

def reachable?(port = nil, proto = nil, timeout = nil)
  raise "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)


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

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



76
77
78
# File 'lib/resources/host.rb', line 76

def to_s
  "Host #{@hostname}"
end