Class: Sensu::Extension::Occurrences
- Inherits:
-
Filter
- Object
- Filter
- Sensu::Extension::Occurrences
- Defined in:
- lib/sensu/extensions/occurrences.rb
Instance Method Summary collapse
- #description ⇒ Object
-
#event_filtered?(event) ⇒ Array
Determine if an event occurrence count meets the user defined requirements in the event check definition.
- #name ⇒ Object
- #run(event) {|event_filtered?(event)| ... } ⇒ Object
Instance Method Details
#description ⇒ Object
10 11 12 |
# File 'lib/sensu/extensions/occurrences.rb', line 10 def description "filter events using event occurrences" end |
#event_filtered?(event) ⇒ Array
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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 ⇒ Object
6 7 8 |
# File 'lib/sensu/extensions/occurrences.rb', line 6 def name "occurrences" end |
#run(event) {|event_filtered?(event)| ... } ⇒ Object
44 45 46 |
# File 'lib/sensu/extensions/occurrences.rb', line 44 def run(event) yield event_filtered?(event) end |