lib/flapjack/data/notification.rb in flapjack-0.7.28 vs lib/flapjack/data/notification.rb in flapjack-0.7.29

- old
+ new

@@ -59,14 +59,12 @@ 'duration' => event.duration, 'count' => event.counter, 'last_state' => last_state[:state], 'last_summary' => last_state[:summary], 'state_duration' => opts[:state_duration], - 'type' => opts[:type] || type_for_event(event), 'severity' => opts[:severity], - 'tags' => tag_data } redis.rpush(queue, Oj.dump(notif)) end @@ -92,17 +90,21 @@ end self.new( parsed ) end def ok? - @state && ['ok', 'up'].include?(@state.downcase) + @state && ['ok', 'up'].include?(@state) end def acknowledgement? - @state && ['acknowledgement'].include?(@state.downcase) + @state && ['acknowledgement'].include?(@state) end + def test? + @state && ['test_notifications'].include?(@state) + end + def contents @contents ||= {'event_id' => @event_id, 'state' => @state, 'summary' => @summary, 'duration' => @duration, @@ -121,11 +123,11 @@ return [] if contacts.nil? || contacts.empty? default_timezone = opts[:default_timezone] logger = opts[:logger] - @messages ||= contacts.collect {|contact| + @messages ||= contacts.collect do |contact| contact_id = contact.id rules = contact.notification_rules media = contact.media logger.debug "Notification#messages: creating messages for contact: #{contact_id} " + @@ -193,40 +195,43 @@ end logger.debug "media_to_use: #{media_to_use}" # here begins rollup madness - media_to_use.each_pair.inject([]) { |ret, (media, address)| + media_to_use.each_pair.inject([]) do |ret, (media, address)| rollup_type = nil - contact.add_alerting_check_for_media(media, @event_id) unless ok? || acknowledgement? + contact.add_alerting_check_for_media(media, @event_id) unless ok? || acknowledgement? || test? # expunge checks in (un)scheduled maintenance from the alerting set cleaned = contact.clean_alerting_checks_for_media(media) logger.debug("cleaned alerting checks for #{media}: #{cleaned}") - alerting_checks = contact.count_alerting_checks_for_media(media) - rollup_threshold = contact.rollup_threshold_for_media(media) - case - when rollup_threshold.nil? - # back away slowly - when alerting_checks >= rollup_threshold - next ret if contact.drop_rollup_notifications_for_media?(media) - contact.update_sent_rollup_alert_keys_for_media(media, :delete => ok?) - rollup_type = 'problem' - when (alerting_checks + cleaned >= rollup_threshold) - # alerting checks was just cleaned such that it is now below the rollup threshold - rollup_type = 'recovery' + # pagerduty is an example of a medium which should never be rolled up + unless ['pagerduty'].include?(media) + alerting_checks = contact.count_alerting_checks_for_media(media) + rollup_threshold = contact.rollup_threshold_for_media(media) + case + when rollup_threshold.nil? + # back away slowly + when alerting_checks >= rollup_threshold + next ret if contact.drop_rollup_notifications_for_media?(media) + contact.update_sent_rollup_alert_keys_for_media(media, :delete => ok?) + rollup_type = 'problem' + when (alerting_checks + cleaned >= rollup_threshold) + # alerting checks was just cleaned such that it is now below the rollup threshold + rollup_type = 'recovery' + end + logger.debug "rollup decisions: #{@event_id} #{@state} #{media} #{address} rollup_type: #{rollup_type}" end - logger.debug "rollup decisions: #{@event_id} #{@state} #{media} #{address} rollup_type: #{rollup_type}" m = Flapjack::Data::Message.for_contact(contact, :medium => media, :address => address, :rollup => rollup_type) ret << m ret - } - }.compact.flatten + end + end.compact.flatten # @messages ||= contacts.collect do ... end private # created from parsed JSON, so opts keys are in strings @@ -236,19 +241,15 @@ @summary = opts['summary'] @details = opts['details'] @time = opts['time'] @count = opts['count'] @duration = opts['duration'] - @last_state = opts['last_state'] @last_summary = opts['last_summary'] @state_duration = opts['state_duration'] - @type = opts['type'] @severity = opts['severity'] - - tags = opts['tags'] - @tags = tags.is_a?(Array) ? Flapjack::Data::TagSet.new(tags) : nil + @tags = opts['tags'].is_a?(Array) ? Flapjack::Data::TagSet.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