From 1f39546155f568923149df3e3c6adcf4b2bd3169 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Tue, 20 Nov 2012 14:42:28 +0000 Subject: Moved inside_bytemark? into its own method, added trivial test-cases. --- lib/custodian/alerter.rb | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/custodian/alerter.rb b/lib/custodian/alerter.rb index 2a86bbe..72bf37a 100644 --- a/lib/custodian/alerter.rb +++ b/lib/custodian/alerter.rb @@ -46,17 +46,42 @@ class Alerter + # + # Is the named target inside the Bytemark IP-range? + # + def inside_bytemark?( target ) + + # + # Test trange, and format the appropriate message. + # + inside = false + + if ( BYTEMARK_RANGES.any?{|range| range.include?(IPAddr.new(target))} ) + inside = true + end + + inside + end + + + # + # Expand to a message indicating whether a hostname is inside the Bytemark network. + # or not. # - # Expand to a message indicating whether a hostname is inside - # the Bytemark network. # def expand_inside_bytemark( host ) + # + # If the host is a URL then we need to work with the hostname component alone. + # + # We'll also make the host a link that can be clicked in the alert we raise. + # target = host if ( target =~ /https?:\/\/([^\/]+)/ ) target = $1.dup + host = "#{host}" end @@ -65,7 +90,6 @@ class Alerter # resolved = nil - # # Resolve the target to an IP, unless it is already an address. # @@ -84,22 +108,9 @@ class Alerter # - # Make any HTTP target a link in the details. - # - if ( host =~ /^http/ ) - host = "#{host}" - end - + # Return the formatted message # - # Test trange, and format the appropriate message. - # - inside = false; - if ( BYTEMARK_RANGES.any?{|range| range.include?(IPAddr.new(resolved.to_s))} ) - inside = true - end - - - if ( inside ) + if ( inside_bytemark?( resolved.to_s ) ) if ( resolved == target ) return "

#{host} is inside the Bytemark network.

" else -- cgit v1.2.1