diff options
Diffstat (limited to 'lib/custodian')
| -rw-r--r-- | lib/custodian/alerter.rb | 47 | 
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 | 
