summaryrefslogtreecommitdiff
path: root/lib/custodian/alerter.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-20 14:42:28 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-20 14:42:28 +0000
commit78f5a2cfaa0b32c33260c0a84c4bc5d85047ff16 (patch)
tree48221670dc895520067ad8adf0f04cdb2dee6cfb /lib/custodian/alerter.rb
parent62850ade3f55c6150b75adf9f0e613c9deb45989 (diff)
Moved inside_bytemark? into its own method, added trivial test-cases.
Diffstat (limited to 'lib/custodian/alerter.rb')
-rw-r--r--lib/custodian/alerter.rb47
1 files changed, 29 insertions, 18 deletions
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 = "<a href=\"#{host}\">#{host}</a>"
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 = "<a href=\"#{host}\">#{host}</a>"
- 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 "<p>#{host} is inside the Bytemark network.</p>"
else