Class: Inspec::Resources::DarwinHostProvider
Instance Attribute Summary
Attributes inherited from HostProvider
#inspec
Instance Method Summary
collapse
#initialize
Instance Method Details
#missing_requirements(protocol) ⇒ Object
144
145
146
147
148
149
150
151
152
|
# File 'lib/resources/host.rb', line 144
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
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/resources/host.rb', line 154
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
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/resources/host.rb', line 168
def resolve(hostname)
cmd = inspec.command("host -t AAAA #{hostname}")
if cmd.exit_status.to_i != 0
cmd = inspec.command("host -t A #{hostname}")
end
return nil if cmd.exit_status.to_i != 0
resolve = /^.* has IPv\d address\s+(?<ip>\S+)\s*$/.match(cmd.stdout.chomp)
[resolve[1]] if resolve
end
|