class Sensu::Extension::Occurrences

Public Instance Methods

description() click to toggle source
# File lib/sensu/extensions/occurrences.rb, line 10
def description
  "filter events using event occurrences"
end
event_filtered?(event) click to toggle source

Determine if an event occurrence count meets the user defined requirements in the event check definition. Users can specify a minimum number of `occurrences` before an event will be passed to a handler. Users can also specify a `refresh` time, in seconds, to reset where recurrences are counted from.

@param event [Hash] @return [Array] containing filter output and status.

# File lib/sensu/extensions/occurrences.rb, line 22
def event_filtered?(event)
  check = event[:check]
  occurrences = check[:occurrences] || 1
  refresh = check[:refresh] || 1800
  if event[:action] == :resolve && event[:occurrences_watermark] >= occurrences
    return ["enough occurrences", 1]
  elsif occurrences.is_a?(Integer) && refresh.is_a?(Integer)
    if event[:occurrences] < occurrences
      return ["not enough occurrences", 0]
    end
    if event[:occurrences] > occurrences &&
        [:create, :flapping].include?(event[:action])
      interval = check[:interval] || 60
      count = refresh.fdiv(interval).to_i
      unless count == 0 || (event[:occurrences] - occurrences) % count == 0
        return ["only handling every #{count} occurrences", 0]
      end
    end
  end
  ["enough occurrences", 1]
end
name() click to toggle source
# File lib/sensu/extensions/occurrences.rb, line 6
def name
  "occurrences"
end
run(event) { |event_filtered?(event)| ... } click to toggle source
# File lib/sensu/extensions/occurrences.rb, line 44
def run(event)
  yield event_filtered?(event)
end