Class: What::Modules::Base
- Inherits:
-
Object
- Object
- What::Modules::Base
- Includes:
- Celluloid
- Defined in:
- lib/what/modules/base.rb
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
Instance Method Summary collapse
-
#check ⇒ Object
This method should be overridden.
-
#details ⇒ Object
This method may be overridden, to provide extra details based on the results of the check.
-
#health ⇒ Object
This method must be overridden.
-
#identifier ⇒ Object
A unique identifier that we can use to match results up with this specific instance.
-
#initialize(params, output) ⇒ Base
constructor
A new instance of Base.
- #initialize_module ⇒ Object
- #name ⇒ Object
- #shared_status ⇒ Object
- #start_monitoring ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(params, output) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/what/modules/base.rb', line 7 def initialize(params, output) defaults = (self.class)::DEFAULTS rescue {} @name = params['name'] @config = defaults.merge(params['config'] || {}) @max = params['max'] || 'alert' @interval = params['interval'] || Config['interval'] @output = output @failures = 0 initialize_module end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
5 6 7 |
# File 'lib/what/modules/base.rb', line 5 def interval @interval end |
Instance Method Details
#check ⇒ Object
This method should be overridden. The implementation here is for backwards compatibility with older modules that implement check! instead of check.
54 55 56 |
# File 'lib/what/modules/base.rb', line 54 def check check! end |
#details ⇒ Object
This method may be overridden, to provide extra details based on the results of the check.
65 66 67 |
# File 'lib/what/modules/base.rb', line 65 def details {} end |
#health ⇒ Object
This method must be overridden.
59 60 61 |
# File 'lib/what/modules/base.rb', line 59 def health raise "Module #{self.class.name} doesn't override 'health'" end |
#identifier ⇒ Object
A unique identifier that we can use to match results up with this specific instance. This is necessary because Celluloid weirds identity.
47 48 49 |
# File 'lib/what/modules/base.rb', line 47 def identifier object_id end |
#initialize_module ⇒ Object
18 19 |
# File 'lib/what/modules/base.rb', line 18 def initialize_module end |
#name ⇒ Object
41 42 43 |
# File 'lib/what/modules/base.rb', line 41 def name Helpers.underscore(self.class.name.split('::').last) end |
#shared_status ⇒ Object
82 83 84 85 86 87 |
# File 'lib/what/modules/base.rb', line 82 def shared_status status = {} status['name'] = @name if @name status['type'] = name # FIXME status end |
#start_monitoring ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/what/modules/base.rb', line 21 def start_monitoring @output[identifier] = nil loop do check @output[identifier] = status sleep interval end rescue Exception => e # stop looping -- the Monitor will restart if necessary @failures += 1 output = shared_status.merge( "health" => "alert", "error" => "#{e.class}: #{e.}", "failures" => @failures ) puts "Error in module:\n#{YAML.dump(output)}" @output[identifier] = output end |
#status ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/what/modules/base.rb', line 69 def status status = shared_status status['health'] = if @max == 'ok' || health == 'ok' 'ok' elsif @max == 'warning' || health == 'warning' 'warning' else 'alert' end status['details'] = details status end |