From 8ea13fef151d9bcd3f56a3320cd19fb0a838648d Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Thu, 15 Nov 2012 11:28:10 +0000 Subject: Don't resolve IPs --- lib/custodian/alerter.rb | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'lib/custodian') diff --git a/lib/custodian/alerter.rb b/lib/custodian/alerter.rb index f5caa6a..8bbd47e 100644 --- a/lib/custodian/alerter.rb +++ b/lib/custodian/alerter.rb @@ -43,29 +43,43 @@ class Alerter # resolved = nil + # - # Resolve the target to an IP + # Resolve the target to an IP, unless it is already an address. # - begin - Socket.getaddrinfo(target, 'echo').each do |a| - resolved = a[3] if ( a ) + if ( ( target =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || + ( target =~ /^([0-9a-f:]+)$/ ) ) + resolved = target + else + begin + Socket.getaddrinfo(target, 'echo').each do |a| + resolved = a[3] if ( a ) + end + rescue SocketError + resolved = nil end - rescue SocketError end + # + # Did we get an error? + # return "" unless ( !resolved.nil? ) + + # + # Make any HTTP target a link in the details. + # if ( host =~ /^http/ ) host = "#{host}" end # - # Test trange + # Test trange, and format the appropriate message. # if ( BYTEMARK_RANGES.any?{|range| range.include?(IPAddr.new(resolved.to_s))} ) return "

#{host} resolves to #{resolved} which is inside the Bytemark network.

" else - return "

#{host} resolves to #{resolved} which is not inside the Bytemark network.

" + return "

#{host} resolves to #{resolved} which is not inside the Bytemark network.

" end end -- cgit v1.2.1