Class: Inspec::Resources::LinuxHostProvider

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

Instance Attribute Summary

Attributes inherited from HostProvider

#inspec

Instance Method Summary collapse

Methods inherited from HostProvider

#initialize

Constructor Details

This class inherits a constructor from Inspec::Resources::HostProvider

Instance Method Details

#ping(hostname, _port = nil, _proto = nil) ⇒ Object

ping is difficult to achieve, since we are not sure



125
126
127
128
129
130
# File 'lib/resources/host.rb', line 125

def ping(hostname, _port = nil, _proto = nil)
  # fall back to ping, but we can only test ICMP packages with ping
  # therefore we have to skip the test, if we do not have everything on the node to run the test
  ping = inspec.command("ping -w 1 -c 1 #{hostname}")
  ping.exit_status.to_i != 0 ? false : true
end

#resolve(hostname) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/resources/host.rb', line 132

def resolve(hostname)
  # TODO: we rely on getent hosts for now, but it prefers to return IPv6, only then IPv4
  cmd = inspec.command("getent hosts #{hostname}")
  return nil if cmd.exit_status.to_i != 0

  # extract ip adress
  resolve = /^\s*(?<ip>\S+)\s+(.*)\s*$/.match(cmd.stdout.chomp)
  [resolve[1]] if resolve
end