aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/alert.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-11-21 11:57:17 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-11-21 11:57:17 +0000
commit877afea59e9d85cecbefa2fe01df5adc6fa252b1 (patch)
treeedd06426ddde9a076e9644d04442b661d4d4e849 /lib/mauve/alert.rb
parent9f4910bef307cb9c0c78c4e45710956f3521774c (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/alert.rb')
-rw-r--r--lib/mauve/alert.rb45
1 files changed, 1 insertions, 44 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 52c098c..4629191 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -190,50 +190,7 @@ module Mauve
source_list = Mauve::Configuration.current.source_lists[listname]
return false unless source_list.is_a?(SourceList)
- host = self.subject
-
- #
- # Pick out hostnames from URIs.
- #
- if host =~ /^[a-z][a-z0-9+-]+:\/\//
- begin
- uri = URI.parse(host)
- host = uri.host unless uri.host.nil?
- rescue URI::InvalidURIError => ex
- # ugh
- logger.warn "Did not recognise URI #{host}"
- end
- end
-
- return true if source_list.list.any? do |l|
- case l
- when String
- host == l
- when Regexp
- host =~ l
- when IPAddr
- begin
- l.include?(IPAddr.new(host))
- rescue ArgumentError => err
- # rescue random IPAddr argument errors
- false
- end
- else
- false
- end
- end
-
- return false unless source_list.list.any?{|l| l.is_a?(IPAddr)}
-
- @subject_ips ||= MauveResolv.get_ips_for(host).collect{|i| IPAddr.new(i)}
-
- return false if @subject_ips.nil? or @subject_ips.empty?
-
- return source_list.list.select{|i| i.is_a?(IPAddr)}.any? do |list_ip|
- @subject_ips.any?{|ip| list_ip.include?(ip)}
- end
-
- return false
+ source_list.include?(self.subject)
end
# Returns the alert level