diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-11-21 11:57:17 +0000 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-11-21 11:57:17 +0000 |
commit | 877afea59e9d85cecbefa2fe01df5adc6fa252b1 (patch) | |
tree | edd06426ddde9a076e9644d04442b661d4d4e849 /lib/mauve/source_list.rb | |
parent | 9f4910bef307cb9c0c78c4e45710956f3521774c (diff) |
Removed duplicate code from Alert#in_source_list, and
SourceList#include. Also cut down on DNS queries, and IPAddr
conversions.
Diffstat (limited to 'lib/mauve/source_list.rb')
-rw-r--r-- | lib/mauve/source_list.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/mauve/source_list.rb b/lib/mauve/source_list.rb index 0596177..ad84670 100644 --- a/lib/mauve/source_list.rb +++ b/lib/mauve/source_list.rb @@ -123,6 +123,13 @@ module Mauve end end + host_as_ip = nil + begin + host_as_ip = IPAddr.new(host) + rescue ArgumentError + # Rescue IPAddr argument errors, i.e. host is not an IP address. + end + return true if self.list.any? do |l| case l when String @@ -130,17 +137,17 @@ module Mauve when Regexp host =~ l when IPAddr - begin - l.include?(IPAddr.new(host)) - rescue ArgumentError - # rescue random IPAddr argument errors - false - end + host_as_ip.is_a?(IPAddr) and l.include?(host_as_ip) else false end end + # + # To cut down the amount of DNS queries, we'll bail out at this point. + # + return false + return false unless self.list.any?{|l| l.is_a?(IPAddr)} ips = MauveResolv.get_ips_for(host).collect{|i| IPAddr.new(i)} |