Class: Inspec::Resources::LinuxHostProvider
Instance Attribute Summary
Attributes inherited from HostProvider
#inspec
Instance Method Summary
collapse
#resolve_with_dig, #resolve_with_getent
#initialize
Instance Method Details
#missing_requirements(protocol) ⇒ Object
222
223
224
225
226
227
228
229
230
|
# File 'lib/resources/host.rb', line 222
def missing_requirements(protocol)
missing = []
if protocol == 'tcp' && (!inspec.command('nc').exist? && !inspec.command('ncat').exist?)
missing << 'netcat must be installed'
end
missing
end
|
#ping(hostname, port, protocol) ⇒ Object
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
# File 'lib/resources/host.rb', line 232
def ping(hostname, port, protocol)
if protocol == 'tcp'
resp = inspec.command(tcp_check_command(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
259
260
261
|
# File 'lib/resources/host.rb', line 259
def resolve(hostname)
resolve_with_getent(hostname)
end
|
#tcp_check_command(hostname, port) ⇒ Object
247
248
249
250
251
252
253
254
255
256
257
|
# File 'lib/resources/host.rb', line 247
def tcp_check_command(hostname, port)
if inspec.command('nc').exist?
base_cmd = 'nc'
elsif inspec.command('ncat').exist?
base_cmd = 'ncat'
else
return
end
"echo | #{base_cmd} -v -w 1 #{hostname} #{port}"
end
|