aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-11-23 10:23:51 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-11-23 10:23:51 +0000
commit7ee5acc25e47a0d1c8d27acb8ce4e80ad48087b6 (patch)
tree4b1eac4b1c48fc910f1824742011129832a5472c
parent9a02180c2aa902d41d142cf7faead4029bc641e3 (diff)
Added minimal_dns_lookups configuration directive to allow alert-group
DNS lookups to occur when needed.
-rw-r--r--lib/mauve/configuration.rb14
-rw-r--r--lib/mauve/source_list.rb3
-rw-r--r--test/tc_mauve_source_list.rb15
3 files changed, 29 insertions, 3 deletions
diff --git a/lib/mauve/configuration.rb b/lib/mauve/configuration.rb
index 457fb4d..8a2ed74 100644
--- a/lib/mauve/configuration.rb
+++ b/lib/mauve/configuration.rb
@@ -40,6 +40,7 @@ module Mauve
#
attr_reader :bytemark_auth_url, :bytemark_calendar_url, :remote_http_timeout, :remote_https_verify_mode, :failed_login_delay
attr_reader :max_acknowledgement_time, :working_hours, :dead_zone, :daytime_hours
+ attr_reader :minimal_dns_lookups
#
@@ -70,6 +71,11 @@ module Mauve
self.failed_login_delay = 1
#
+ # Reduce the amount of DNS lookups when matching alerts to groups.
+ #
+ self.minimal_dns_lookups = false
+
+ #
# Maximum amount of time to acknowledge for
#
self.max_acknowledgement_time = 15.days
@@ -247,6 +253,14 @@ module Mauve
end
+ def minimal_dns_lookups=(bool)
+ if bool.is_a?(TrueClass) or bool.to_s.strip =~ /^(1|y(es)?|t(rue))/
+ @minimal_dns_lookups = true
+ else
+ @minimal_dns_lookups = false
+ end
+ end
+
end
diff --git a/lib/mauve/source_list.rb b/lib/mauve/source_list.rb
index ad84670..869d99a 100644
--- a/lib/mauve/source_list.rb
+++ b/lib/mauve/source_list.rb
@@ -5,6 +5,7 @@ require 'uri'
require 'mauve/mauve_time'
require 'mauve/mauve_resolv'
require 'mauve/generic_http_api_client'
+require 'mauve/configuration'
module Mauve
@@ -146,7 +147,7 @@ module Mauve
#
# To cut down the amount of DNS queries, we'll bail out at this point.
#
- return false
+ return false if true == Configuration.current.minimal_dns_lookups
return false unless self.list.any?{|l| l.is_a?(IPAddr)}
diff --git a/test/tc_mauve_source_list.rb b/test/tc_mauve_source_list.rb
index 5b1aa70..6241a2f 100644
--- a/test/tc_mauve_source_list.rb
+++ b/test/tc_mauve_source_list.rb
@@ -1,10 +1,9 @@
$:.unshift "../lib/"
require 'th_mauve'
-require 'mauve/source_list'
require 'th_mauve_resolv'
+require 'mauve/source_list'
require 'webmock'
-require 'pp'
class TcMauveSourceList < Mauve::UnitTest
@@ -90,6 +89,18 @@ class TcMauveSourceList < Mauve::UnitTest
assert( sl.includes?("www2.example.com"), "www2.example.com not found in #{sl.list}" )
end
+ def test_ip_crossmatch_fail_when_minimal_dns_is_available
+ Configuration.current.minimal_dns_lookups = true
+
+ sl = SourceList.new("test")
+ assert_nothing_raised { sl += "test-1.example.com" }
+ assert( !sl.includes?("www.example.com"), "www.example.com not found in #{sl.list}" )
+
+ sl = SourceList.new("test")
+ assert_nothing_raised { sl += "2001::/3" }
+ assert( !sl.includes?("www2.example.com"), "www2.example.com not found in #{sl.list}" )
+ end
+
def test_remote_source_list
stub_request(:get, "http://localhost/network/monitor_ip/by_tag/Managed").
to_return(:status => 200, :body => %w(1.2.3.4 1.2.3.5).join("\n"))