Class: What::Modules::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/what/modules/base.rb

Direct Known Subclasses

Disk, Existence, Process, Unicorn, What

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
15
# File 'lib/what/modules/base.rb', line 6

def initialize(params={})
  defaults = (self.class)::DEFAULTS rescue {}
  @name = params['name']
  @config = defaults.merge(params['config'] || {})
  @max = params['max'] || 'alert'
  # Use global interval setting if not set on a
  # per module basis
  @interval = params['interval'] || Config['interval']
  initialize_module
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



4
5
6
# File 'lib/what/modules/base.rb', line 4

def interval
  @interval
end

Instance Method Details

#check!Object



24
25
# File 'lib/what/modules/base.rb', line 24

def check!
end

#detailsObject



46
47
48
# File 'lib/what/modules/base.rb', line 46

def details
  {}
end

#healthObject



42
43
44
# File 'lib/what/modules/base.rb', line 42

def health
  raise "Module #{self.class.name} doesn't override 'health'"
end

#initialize_moduleObject



17
18
# File 'lib/what/modules/base.rb', line 17

def initialize_module
end

#nameObject



20
21
22
# File 'lib/what/modules/base.rb', line 20

def name
  Helpers.underscore(self.class.name.split('::').last)
end

#statusObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/what/modules/base.rb', line 27

def status
  status = {}
  status['name'] = @name if @name
  status['type'] = name # FIXME
  status['health'] = if @max == 'ok' || health == 'ok'
                       'ok'
                     elsif @max == 'warning' || health == 'warning'
                       'warning'
                     else
                       'alert'
                     end
  status['details'] = details
  status
end