lib/flapjack/data/notification.rb in flapjack-1.1.0 vs lib/flapjack/data/notification.rb in flapjack-1.2.0rc1

- old
+ new

@@ -1,9 +1,7 @@ #!/usr/bin/env ruby -require 'oj' - require 'flapjack/data/contact' require 'flapjack/data/event' require 'flapjack/data/message' module Flapjack @@ -64,11 +62,11 @@ 'state_duration' => opts[:state_duration], 'type' => opts[:type] || type_for_event(event), 'severity' => opts[:severity], 'tags' => tag_data } - redis.rpush(queue, Oj.dump(notif)) + redis.rpush(queue, Flapjack.dump_json(notif)) end def self.next(queue, opts = {}) raise "Redis connection not set" unless redis = opts[:redis] @@ -80,11 +78,11 @@ else raw = redis.lpop(queue) return unless raw end begin - parsed = ::Oj.load( raw ) + parsed = ::Flapjack.load_json( raw ) rescue Oj::Error => e if options[:logger] options[:logger].warn("Error deserialising notification json: #{e}, raw json: #{raw.inspect}") end return nil @@ -131,22 +129,22 @@ contact_id = contact.id rules = contact.notification_rules media = contact.media logger.debug "Notification#messages: creating messages for contact: #{contact_id} " + - "event_id: \"#{@event_id}\" state: #{@state} event_tags: #{@tags.to_json} media: #{media.inspect}" + "event_id: \"#{@event_id}\" state: #{@state} event_tags: #{Flapjack.dump_json(@tags)} media: #{media.inspect}" rlen = rules.length logger.debug "found #{rlen} rule#{(rlen == 1) ? '' : 's'} for contact #{contact_id}" media_to_use = if rules.empty? media else # matchers are rules of the contact that have matched the current event # for time, entity and tags matchers = rules.select do |rule| logger.debug("considering rule with entities: #{rule.entities}, entities regex: #{rule.regex_entities}, - tags: #{rule.tags.to_json} and regex tags: #{rule.regex_tags.to_json}") + tags: #{Flapjack.dump_json(rule.tags)} and regex tags: #{Flapjack.dump_json(rule.regex_tags)}") rule_has_tags = rule.tags ? (rule.tags.length > 0) : false rule_has_regex_tags = rule.regex_tags ? (rule.regex_tags.length > 0) : false rule_has_entities = rule.entities ? (rule.entities.length > 0) : false rule_has_regex_entities = rule.regex_entities ? (rule.regex_entities.length > 0) : false @@ -160,11 +158,11 @@ :logger => logger) end logger.debug "#{matchers.length} matchers remain for this contact after time, entity and tags are matched:" matchers.each do |matcher| - logger.debug " - #{matcher.to_json}" + logger.debug " - #{matcher.to_jsonapi}" end # delete any general matchers if there are more specific matchers left if matchers.any? {|matcher| matcher.is_specific? } @@ -173,21 +171,21 @@ matchers.reject! {|matcher| !matcher.is_specific? } if num_matchers != matchers.length logger.debug("removal of general matchers when entity specific matchers are present: number of matchers changed from #{num_matchers} to #{matchers.length} for contact id: #{contact_id}") matchers.each do |matcher| - logger.debug " - #{matcher.to_json}" + logger.debug " - #{matcher.to_jsonapi}" end end end # delete media based on blackholes blackhole_matchers = matchers.map {|matcher| matcher.blackhole?(@severity) ? matcher : nil }.compact if blackhole_matchers.length > 0 logger.debug "dropping this media as #{blackhole_matchers.length} blackhole matchers are present:" blackhole_matchers.each {|bm| - logger.debug " - #{bm.to_json}" + logger.debug " - #{bm.to_jsonapi}" } next else logger.debug "no blackhole matchers matched" end @@ -262,10 +260,10 @@ @last_state = opts['last_state'] @last_summary = opts['last_summary'] @state_duration = opts['state_duration'] @type = opts['type'] @severity = opts['severity'] - @tags = opts['tags'].is_a?(Array) ? Flapjack::Data::TagSet.new(opts['tags']) : nil + @tags = opts['tags'].is_a?(Array) ? Set.new(opts['tags']) : nil end # # time restrictions match? # nil rule.time_restrictions matches # times (start, end) within time restrictions will have any UTC offset removed and will be