lib/flapjack/executive.rb in flapjack-0.7.2 vs lib/flapjack/executive.rb in flapjack-0.7.3

- old
+ new

@@ -280,38 +280,36 @@ notification = Flapjack::Data::Notification.for_event( event, :type => notification_type, :max_notified_severity => max_notified_severity) messages = notification.messages(:contacts => contacts) - messages = apply_notification_rules(messages) + messages = apply_notification_rules(messages, event.state) enqueue_messages(messages) - end # time restrictions match? # nil rule.time_restrictions matches # times (start, end) within time restrictions will have any UTC offset removed and will be # considered to be in the timezone of the contact def rule_occurring_now?(rule, opts) contact = opts[:contact] return true if rule.time_restrictions.nil? or rule.time_restrictions.empty? - time_zone = contact.timezone(:default => @default_contact_timezone) - usertime = time_zone.now + timezone = contact.timezone(:default => @default_contact_timezone) + usertime = timezone.now match = rule.time_restrictions.any? do |tr| - # add contact's timezone to the time restriction hash - tr = Flapjack::Data::NotificationRule.time_restriction_to_ice_cube_hash(tr, time_zone) - - schedule = IceCube::Schedule.from_hash(tr) - schedule.occurring_at?(usertime) + # add contact's timezone to the time restriction schedule + schedule = Flapjack::Data::NotificationRule. + time_restriction_to_icecube_schedule(tr, timezone) + schedule && schedule.occurring_at?(usertime) end !!match end # delete messages based on entity name(s), tags, severity, time of day - def apply_notification_rules(messages) + def apply_notification_rules(messages, severity) # first get all rules matching entity and time @logger.debug "apply_notification_rules: got messages with size #{messages.size}" # don't consider notification rules if the contact has none @@ -340,21 +338,20 @@ have_specific = matchers.detect do |matcher| matcher.entities or matcher.entity_tags end if have_specific # delete the rule for all entities - matchers.map! do |matcher| - matcher.entities.nil? and matcher.entity_tags.nil? ? nil : matcher + matchers.reject! do |matcher| + matcher.entities.nil? && matcher.entity_tags.nil? end end end [message, matchers, options] end # delete media based on blackholes tuple = tuple.find_all do |message, matchers, options| - severity = message.notification.event.state # or use message.notification.contents['state'] matchers.none? {|matcher| matcher.blackhole?(severity) } end @logger.debug "apply_notification_rules: num messages after removing blackhole matches: #{tuple.size}" @@ -374,16 +371,10 @@ when [state, max_notified_severity].include?('warning') severity = 'warning' end options[:no_rules_for_contact] || matchers.any? {|matcher| - mms = matcher.media_for_severity(severity) - unless mms - answer = false - else - answer = mms.include?(message.medium) - end - answer + (matcher.media_for_severity(severity) || []).include?(message.medium) } end @logger.debug "apply_notification_rules: num messages after pruning for severity-media constraints: #{tuple.size}"