Class: Eye::Trigger

Inherits:
Object
  • Object
show all
Extended by:
Dsl::Validation
Includes:
Logger::Helpers
Defined in:
lib/eye/trigger.rb

Direct Known Subclasses

Flapping

Defined Under Namespace

Classes: Flapping

Constant Summary collapse

TYPES =

ex: { :type => :flapping, :times => 2, :within => 30.seconds}

{:flapping => "Flapping"}

Instance Attribute Summary collapse

Attributes included from Dsl::Validation

#defaults, #should_bes, #validates, #variants

Attributes included from Logger::Helpers

#logger

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Dsl::Validation

inherited, param, validate

Constructor Details

#initialize(options = {}, logger_prefix = nil) ⇒ Trigger

Returns a new instance of Trigger.



26
27
28
29
30
31
# File 'lib/eye/trigger.rb', line 26

def initialize(options = {}, logger_prefix = nil)
  @options = options
  @logger = Eye::Logger.new(logger_prefix, "trigger")

  debug "add #{options}"
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



10
11
12
# File 'lib/eye/trigger.rb', line 10

def message
  @message
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/eye/trigger.rb', line 10

def options
  @options
end

Class Method Details

.create(options = {}, logger_prefix = nil) ⇒ Object



18
19
20
# File 'lib/eye/trigger.rb', line 18

def self.create(options = {}, logger_prefix = nil)
  get_class(options[:type]).new(options, logger_prefix)
end

.get_class(type) ⇒ Object



12
13
14
15
16
# File 'lib/eye/trigger.rb', line 12

def self.get_class(type)
  klass = eval("Eye::Trigger::#{TYPES[type]}") rescue nil
  raise "Unknown trigger #{type}" unless klass
  klass
end

.validate!(options = {}) ⇒ Object



22
23
24
# File 'lib/eye/trigger.rb', line 22

def self.validate!(options = {})
  get_class(options[:type]).validate(options)
end

Instance Method Details

#check(states_history) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/eye/trigger.rb', line 33

def check(states_history)
  @states_history = states_history

  res = good?

  if res
    debug 'check flapping'
  else
    debug "!!! #{self.class} recognized !!!"
  end
  
  res
end

#good?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/eye/trigger.rb', line 47

def good?
  raise 'realize me'
end