From 70b13e92297905631629a05e827d70e98c3f422d Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Tue, 8 Aug 2017 15:37:36 +0300 Subject: Sanity-check DNS on a per-protocol basis. When a failure occurs in looking up IPv4 addresses we confirm that, similarly when/if IPv6 lookups fail we confirm that before raising the alert. --- lib/custodian/protocoltest/http.rb | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/custodian/protocoltest/http.rb b/lib/custodian/protocoltest/http.rb index 88ac568..32073f8 100644 --- a/lib/custodian/protocoltest/http.rb +++ b/lib/custodian/protocoltest/http.rb @@ -59,7 +59,7 @@ module Custodian # raise an alert, but if it is this false-error then we # will silently disable this test-run. # - def ignore_failure? + def ignore_failure?( protocol ) # IP addresses we found for the host ips = [] @@ -85,11 +85,16 @@ module Custodian Resolv::DNS.open do |dns| - ress = dns.getresources(target, Resolv::DNS::Resource::IN::A) - ress.map { |r| ips.push(r.address.to_s) } + if ( protocol == :ipv4 ) + ress = dns.getresources(target, Resolv::DNS::Resource::IN::A) + ress.map { |r| ips.push(r.address.to_s) } + elsif ( protocol == :ipv6 ) - ress = dns.getresources(target, Resolv::DNS::Resource::IN::AAAA) - ress.map { |r| ips.push(r.address.to_s) } + ress = dns.getresources(target, Resolv::DNS::Resource::IN::AAAA) + ress.map { |r| ips.push(r.address.to_s) } + else + raise ArgumentError, "Sanity-checking DNS-failure of unknown type" + end end end rescue Timeout::Error => _e @@ -409,7 +414,7 @@ module Custodian rescue Curl::Err::TooManyRedirectsError errors << "#{protocol_msg}: More than 10 redirections." rescue Curl::Err::HostResolutionError => x - resolution_errors << "#{protocol_msg}: #{x.class}: #{x.message}\n #{x.backtrace.join("\n ")}." + resolution_errors << "#{protocol_msg}: #{x.class}: #{x.message}\n #{x.backtrace.join("\n ")}." unless ignore_failure?( resolve_mode) rescue => x errors << "#{protocol_msg}: #{x.class}: #{x.message}\n #{x.backtrace.join("\n ")}." @@ -432,9 +437,6 @@ module Custodian # uh-oh! Resolution failed on both protocols! if resolution_errors.length > 1 - - return Custodian::TestResult::TEST_SKIPPED if ignore_failure? - errors << "DNS Error when resolving host - #{resolution_errors.join(',')}" end -- cgit v1.2.1