Class: Inspec::Resources::DarwinHostProvider

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

Instance Attribute Summary

Attributes inherited from HostProvider

#inspec

Instance Method Summary collapse

Methods inherited from UnixHostProvider

#resolve_with_dig, #resolve_with_getent

Methods inherited from HostProvider

#initialize

Constructor Details

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

Instance Method Details

#missing_requirements(protocol) ⇒ Object



192
193
194
195
196
197
198
199
200
# File 'lib/resources/host.rb', line 192

def missing_requirements(protocol)
  missing = []

  if protocol == 'tcp'
    missing << 'netcat must be installed' unless inspec.command('nc').exist?
  end

  missing
end

#ping(hostname, port, protocol) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/resources/host.rb', line 202

def ping(hostname, port, protocol)
  if protocol == 'tcp'
    resp = inspec.command("nc -vz -G 1 #{hostname} #{port}")
  else
    resp = inspec.command("ping -W 1 -c 1 #{hostname}")
  end

  {
    success: resp.exit_status.to_i.zero?,
    connection: resp.stderr,
    socket: resp.stdout,
  }
end

#resolve(hostname) ⇒ Object



216
217
218
# File 'lib/resources/host.rb', line 216

def resolve(hostname)
  resolve_with_dig(hostname)
end