Class: HealthTools

Inherits:
Object
  • Object
show all
Defined in:
lib/health_tools.rb

Defined Under Namespace

Classes: Service

Class Method Summary collapse

Class Method Details

.add_component(data) ⇒ Object



9
10
11
# File 'lib/health_tools.rb', line 9

def self.add_component(data)
  HTTParty.post(ENV['server_host'] + '/api/component', body: data)
end

.check(data_content) ⇒ Object



13
14
15
# File 'lib/health_tools.rb', line 13

def self.check(data_content)
  self.reply_health(data_content)
end

.component(data) ⇒ Object



5
6
7
# File 'lib/health_tools.rb', line 5

def self.component(data)
  self.add_component(data)
end

.convert_type(data) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/health_tools.rb', line 29

def self.convert_type(data)
  hash = {}
  data.each do |key, value|
    value = value.to_s
    hash.store(key, value)
  end
  hash
end

.get_checksum(data) ⇒ Object



24
25
26
27
# File 'lib/health_tools.rb', line 24

def self.get_checksum(data)
  data = self.convert_type(data)
  Digest::SHA2.hexdigest(data.to_s)
end

.reply_health(data) ⇒ Object



17
18
19
20
21
22
# File 'lib/health_tools.rb', line 17

def self.reply_health(data)
  data.store("service_code", ENV['service_code'])
  data.store("start_time", DateTime.now.strftime("%d/%m/%Y %H:%M"))
  data.store("checksum", get_checksum(data))
  HTTParty.post(ENV['server_host'] + '/api/report', body: data)
end