Class: Inspec::Resources::LinuxHostProvider
Instance Attribute Summary
Attributes inherited from HostProvider
#inspec
Instance Method Summary
collapse
#initialize
Instance Method Details
#missing_requirements(protocol) ⇒ Object
182
183
184
185
186
187
188
189
190
|
# File 'lib/resources/host.rb', line 182
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# File 'lib/resources/host.rb', line 192
def ping(hostname, port, protocol)
if protocol == 'tcp'
resp = inspec.command("echo | nc -v -w 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
207
208
209
210
211
212
213
214
215
|
# File 'lib/resources/host.rb', line 207
def resolve(hostname)
cmd = inspec.command("getent hosts #{hostname}")
return nil if cmd.exit_status.to_i != 0
resolve = /^\s*(?<ip>\S+)\s+(.*)\s*$/.match(cmd.stdout.chomp)
[resolve[1]] if resolve
end
|