Module: TaskServer

Extended by:
Opstat::Logging
Defined in:
lib/opstat-master/master.rb

Overview

TODO don’t allow ip_addres of loopback

Class Method Summary collapse

Methods included from Opstat::Logging

log_level, oplogger

Class Method Details

.save(queue_data) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/opstat-master/master.rb', line 7

def self.save(queue_data)
  oplogger.debug queue_data

  hostname = queue_data["hostname"]
  ip = queue_data['ip_address']
  client_version = queue_data['version']
  send_data_interval = queue_data['send_data_interval']

  queue_data["collected_data"].each do |data|
    host = Host.find_or_create_by(hostname: hostname, ip_address: ip)
    plugin = Plugin.find_or_create_by(type: data['plugin'], host_id: host.id)
	host['send_data_interval'] = send_data_interval
	plugin['interval'] = data['interval']
	plugin_dead_ratio = 2
	unless plugin['interval'].nil?
	  if plugin['interval'] > host['send_data_interval']
 plugin_is_alive_interval = data['interval'] * plugin_dead_ratio
	  else
 plugin_is_alive_interval = host['send_data_interval'] * plugin_dead_ratio
	  end
	  plugin['is_alive_time'] = Time.now + plugin_is_alive_interval
	end

    plugin.save
	  
    ##TODO reconsider if it is really needed
  #client_host.touch
      ##TODO reconsider if it is really needed
    #  client_host_plugin.touch
    Opstat::Parsers::Master.instance.parse_and_save(:host => host, :plugin_data => data, :plugin => plugin)
  end
end