diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-16 16:07:14 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-16 16:07:14 +0000 |
commit | 715ae9c45b11a2f1a2c62c3d69ae5d76e73d3865 (patch) | |
tree | c7ddeda2508ae3ab99d0f12d4aa18ed93a549fa5 | |
parent | 82e2f2376118408ab35d564dc9f2ac14271c41aa (diff) |
Remove redundent text in alerts if the target was an IP
-rw-r--r-- | lib/custodian/alerter.rb | 18 | ||||
-rwxr-xr-x | t/test-alerter.rb | 17 |
2 files changed, 30 insertions, 5 deletions
diff --git a/lib/custodian/alerter.rb b/lib/custodian/alerter.rb index da3571e..f78d299 100644 --- a/lib/custodian/alerter.rb +++ b/lib/custodian/alerter.rb @@ -83,10 +83,24 @@ class Alerter # # Test trange, and format the appropriate message. # + inside = false; if ( BYTEMARK_RANGES.any?{|range| range.include?(IPAddr.new(resolved.to_s))} ) - return "<p>#{host} resolves to #{resolved} which is inside the Bytemark network.</p>" + inside = true + end + + + if ( inside ) + 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 - return "<p>#{host} resolves to #{resolved} which is not inside the Bytemark network.</p>" + if ( resolved == target ) + return "<p>#{host} is OUTSIDE the Bytemark network.</p>" + else + return "<p>#{host} resolves to #{resolved} which is OUTSIDE the Bytemark network.</p>" + end end end diff --git a/t/test-alerter.rb b/t/test-alerter.rb index 97e19b5..f826205 100755 --- a/t/test-alerter.rb +++ b/t/test-alerter.rb @@ -39,14 +39,13 @@ class TestAlerter < Test::Unit::TestCase obj = Alerter.new( {} ) assert( obj ) end - end # # Test location-detection. # - def test_locations_inside_outside + def test_location_detection # # Hash of hostnames and version of address. @@ -84,10 +83,21 @@ class TestAlerter < Test::Unit::TestCase if ( text =~ /is inside/ ) assert( inside == true ) end - if ( text =~ /is not/ ) + if ( text =~ /OUTSIDE/ ) assert( inside == false ) end end + + # + # OK now look for the text returned + # + obj = Alerter.new( nil ) + details = obj.expand_inside_bytemark( "46.43.50.217" ) + assert( details.match( /46.43.50.217 is inside the Bytemark network/ ) ) + + details = obj.expand_inside_bytemark( "www.linnrecords.com" ) + assert( details.match( /resolves to 46.43.50.217 which is inside the Bytemark network/ ) ) + end @@ -120,5 +130,6 @@ class TestAlerter < Test::Unit::TestCase # details = obj.document_address( "800.683.853.348" ) assert( details.nil? ) + end end |