diff options
author | Steve Kemp <steve@steve.org.uk> | 2015-04-16 09:35:57 +0100 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2015-04-16 09:35:57 +0100 |
commit | 32401d592956845096e85f0d2c95b28e44d7d054 (patch) | |
tree | 5529dc521f62b3152b81d2a33bc989cca03d3ca0 /lib/custodian/alerts | |
parent | 374b92529203571e7c497241d68c03b75b466e4c (diff) |
Resolve hostnames for both A + AAAA.
The Bytemark-specific notifier, using mauve, appends some text to
the bottom of each alert:
http://example.com/ resolves to 1.2.3.4 which is INSIDE|OUTSIDE bytemark
This text was previously limited to the IPv4 address, but now is repeated
for each family which resolves successfully.
This closes #10568.
This fixes #10568.
Diffstat (limited to 'lib/custodian/alerts')
-rw-r--r-- | lib/custodian/alerts/mauve.rb | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/lib/custodian/alerts/mauve.rb b/lib/custodian/alerts/mauve.rb index c3c6521..2b48fbc 100644 --- a/lib/custodian/alerts/mauve.rb +++ b/lib/custodian/alerts/mauve.rb @@ -110,7 +110,7 @@ module Custodian # we're in the working day. # if ((wday != 0) && (wday != 6)) && - (hour >= day_start && hour < day_end) + (hour >= day_start && hour < day_end) working = true end @@ -199,7 +199,7 @@ module Custodian subject = @test.target if (subject =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/) || - (subject =~ /^([0-9a-f:]+)$/) + (subject =~ /^([0-9a-f:]+)$/) res = Custodian::Util::DNS.ip_to_hostname(subject) if res subject = res @@ -289,44 +289,65 @@ module Custodian # - # Resolved IP of the target + # IP addresses we found for the host # - resolved = nil + ips = [] + # # Resolve the target to an IP, unless it is already an address. # if (target =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/) || - (target =~ /^([0-9a-f:]+)$/) - resolved = target + (target =~ /^([0-9a-f:]+)$/) + ips.push(target) else - resolved = Custodian::Util::DNS.hostname_to_ip(target) + + # + # OK if it didn't look like an IP address then attempt to + # look it up, as both IPv4 and IPv6. + # + begin + timeout(30) do + + Resolv::DNS.open do |dns| + + ress = dns.getresources(target, Resolv::DNS::Resource::IN::A) + 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) } + end + end + rescue Timeout::Error => e + return '' + end end # - # Did we get an error? + # Did we fail to lookup any IPs? # - return '' unless !resolved.nil? + return '' if ips.empty? # + # The string we return to the caller. + # + result = '' + + # # Return the formatted message # - if Custodian::Util::Bytemark.inside?(resolved.to_s) - if (resolved == target) - return "<p>#{host} is inside the Bytemark network.</p>" - else - return "<p>#{host} resolves to #{resolved} which is inside the Bytemark network.</p>" - end - else - if (resolved == target) - return "<p>#{host} is OUTSIDE the Bytemark network.</p>" + ips.each do |result| + + if Custodian::Util::Bytemark.inside?(result.to_s) + result += "<p>#{host} resolves to #{result} which is inside the Bytemark network.</p>" else - return "<p>#{host} resolves to #{resolved} which is OUTSIDE the Bytemark network.</p>" + result += "<p>#{host} resolves to #{result} which is OUTSIDE the Bytemark network.</p>" end end + result end |