Sha256: 016820d10eaaaa5740336c0348d9544d5232d2f676beef2ea247ea22ee55d644

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

#!/usr/bin/env ruby

require 'flapjack/filters/base'

module Flapjack
  module Filters

    # * If the service event’s state is ok and the previous state was ok, don’t alert
    # * If the service event's state is ok and the previous notification was a recovery, don't alert
    # * If the service event's state is ok and the previous state was not ok and for less than 30
    # seconds, don't alert
    # * If the service event's state is ok and there is unscheduled downtime set, end the unscheduled
    #   downtime
    class Ok
      include Base

      def block?(event)
        result = false

        if event.ok?
          if event.previous_state == 'ok'
            @logger.debug("Filter: Ok: existing state was ok, and the previous state was ok, so blocking")
            result = true
          end

          entity_check = Flapjack::Data::EntityCheck.for_event_id(event.id, :redis => @redis)

          last_notification = entity_check.last_notification
          @logger.debug("Filter: Ok: last notification: #{last_notification.inspect}")
          if last_notification[:type] == 'recovery'
            @logger.debug("Filter: Ok: last notification was a recovery, so blocking")
            result = true
          end

          if event.previous_state != 'ok'
            if event.previous_state_duration < 30
              @logger.debug("Filter: Ok: previous non ok state was for less than 30 seconds, so blocking")
              result = true
            end
          end

          # end any unscheduled downtime
          entity_check.end_unscheduled_maintenance(Time.now.to_i)
        end

        @logger.debug("Filter: Ok: #{result ? "block" : "pass"}")
        result
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
flapjack-0.7.22 lib/flapjack/filters/ok.rb
flapjack-0.7.21 lib/flapjack/filters/ok.rb
flapjack-0.7.20 lib/flapjack/filters/ok.rb
flapjack-0.7.19 lib/flapjack/filters/ok.rb