Class: Sensu::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/sensu-handler.rb

Constant Summary collapse

@@autorun =

This works just like Plugin::CLI’s autorun.

self

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.method_added(name) ⇒ Object



32
33
34
35
36
# File 'lib/sensu-handler.rb', line 32

def method_added(name)
  if name == :handle
    @@autorun = self
  end
end

Instance Method Details

#filter(event) ⇒ Object

Overriding filtering logic is optional. Returns truthy if the event should be handled and falsy if it should not.



15
16
17
18
19
20
21
22
# File 'lib/sensu-handler.rb', line 15

def filter(event)
  if event['check']['alert'] == false
    puts 'alert disabled -- filtered event ' + short_name(event)
    exit 0
  end
  refresh = (60.fdiv(event['check']['interval']) * 30).to_i
  event['occurrences'] == 1 || event['occurrences'] % refresh == 0
end

#handle(event) ⇒ Object

Implementing classes should override this.



8
9
10
# File 'lib/sensu-handler.rb', line 8

def handle(event)
  puts 'ignoring event -- no handler defined'
end

#short_name(event) ⇒ Object



24
25
26
# File 'lib/sensu-handler.rb', line 24

def short_name(event)
  event['client']['name'] + '/' + event['check']['name']
end