lib/flapjack/data/entity.rb in flapjack-0.7.1 vs lib/flapjack/data/entity.rb in flapjack-0.7.2
- old
+ new
@@ -76,16 +76,34 @@
# NB: if we're worried about user input, https://github.com/mudge/re2
# has bindings for a non-backtracking RE engine that runs in linear
# time
def self.find_all_name_matching(pattern, options = {})
raise "Redis connection not set" unless redis = options[:redis]
+ begin
+ regex = /#{pattern}/
+ rescue => e
+ if @logger
+ @logger.info("Jabber#self.find_all_name_matching - unable to use /#{pattern}/ as a regex pattern: #{e}")
+ end
+ return nil
+ end
redis.keys('entity_id:*').inject([]) {|memo, check|
a, entity_name = check.split(':')
- if (entity_name =~ /#{pattern}/) && !memo.include?(entity_name)
+ if (entity_name =~ regex) && !memo.include?(entity_name)
memo << entity_name
end
memo
}.sort
+ end
+
+ def self.find_all_with_checks(options)
+ raise "Redis connection not set" unless redis = options[:redis]
+ redis.keys("check:*").map {|s| s.match(/.*:(.*):.*/)[1] }.to_set
+ end
+
+ def self.find_all_with_failing_checks(options)
+ raise "Redis connection not set" unless redis = options[:redis]
+ redis.zrange("failed_checks", 0, -1).map {|s| s.match(/(.*):.*/)[1] }.to_set
end
def contacts
contact_ids = @redis.smembers("contacts_for:#{id}")