Class: Heartcheck::Checks::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/heartcheck/checks/base.rb

Direct Known Subclasses

Firewall, Process

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

call in Heartcheck.set


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/heartcheck/checks/base.rb', line 10

def initialize
  @dynamic_services = nil
  @error_proc       = nil
  @errors           = []
  @functional       = false
  @dev              = false
  @name             = self.class.name.split('::').last.downcase
  @services         = []
  @timeout          = 0
  @validate_proc    = nil
end

Instance Attribute Details

#devObject Also known as: dev?

Returns the value of attribute dev


4
5
6
# File 'lib/heartcheck/checks/base.rb', line 4

def dev
  @dev
end

#functionalObject Also known as: functional?

Returns the value of attribute functional


4
5
6
# File 'lib/heartcheck/checks/base.rb', line 4

def functional
  @functional
end

#nameObject

Returns the value of attribute name


4
5
6
# File 'lib/heartcheck/checks/base.rb', line 4

def name
  @name
end

#timeoutObject

Returns the value of attribute timeout


4
5
6
# File 'lib/heartcheck/checks/base.rb', line 4

def timeout
  @timeout
end

Instance Method Details

#add_service(service) ⇒ Object


34
35
36
# File 'lib/heartcheck/checks/base.rb', line 34

def add_service(service)
  @services << service
end

#checkObject


46
47
48
49
50
51
52
53
# File 'lib/heartcheck/checks/base.rb', line 46

def check
  validation
  hash = { name => { 'status' => (@errors.empty? ? 'ok' : 'error') } }
  hash[name]['message'] = error_message unless @errors.empty?

  Logger.info Oj.dump(hash)
  hash
end

#informationsObject


55
56
57
58
59
# File 'lib/heartcheck/checks/base.rb', line 55

def informations
  info
rescue => e
  { 'error' => e.message }
end

#on_error(&block) ⇒ Object


22
23
24
# File 'lib/heartcheck/checks/base.rb', line 22

def on_error(&block)
  @error_proc = block if block_given?
end

#register_dynamic_services(&block) ⇒ Object


30
31
32
# File 'lib/heartcheck/checks/base.rb', line 30

def register_dynamic_services(&block)
  @dynamic_services = block if block_given?
end

#servicesObject


38
39
40
41
42
43
44
# File 'lib/heartcheck/checks/base.rb', line 38

def services
  if @dynamic_services
    @services + @dynamic_services.call
  else
    @services
  end
end

#to_validate(&block) ⇒ Object


26
27
28
# File 'lib/heartcheck/checks/base.rb', line 26

def to_validate(&block)
  @validate_proc = block if block_given?
end