Class: Cloudscale::Monitor::InitCharts

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudscale/monitor/agent/init_charts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agentInstanceId, path) ⇒ InitCharts

Returns a new instance of InitCharts.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cloudscale/monitor/agent/init_charts.rb', line 17

def initialize(agentInstanceId, path)
  if (agentInstanceId == nil)
    raise "InitCharts.new(): AgentInstanceId may not be null"
  end

  @log = Logger.new(STDOUT)
  @log.info("Initializing Charts")
  @client = RestClientWrapper.instance

  file = File.read(path);
  plugin = YAML.load(JSON.parse(file).to_yaml)
  plugin.each do | key, value |
    init_chart(value, agentInstanceId)
  end
end

Instance Attribute Details

#agentInstanceIdObject

Returns the value of attribute agentInstanceId.



15
16
17
# File 'lib/cloudscale/monitor/agent/init_charts.rb', line 15

def agentInstanceId
  @agentInstanceId
end

#clientObject

Returns the value of attribute client.



15
16
17
# File 'lib/cloudscale/monitor/agent/init_charts.rb', line 15

def client
  @client
end

#customerObject

Returns the value of attribute customer.



15
16
17
# File 'lib/cloudscale/monitor/agent/init_charts.rb', line 15

def customer
  @customer
end

#logObject

Returns the value of attribute log.



15
16
17
# File 'lib/cloudscale/monitor/agent/init_charts.rb', line 15

def log
  @log
end

#serverObject

Returns the value of attribute server.



15
16
17
# File 'lib/cloudscale/monitor/agent/init_charts.rb', line 15

def server
  @server
end

Instance Method Details

#init_chart(chart, agentInstanceId) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cloudscale/monitor/agent/init_charts.rb', line 33

def init_chart(chart, agentInstanceId)
  chart["agentInstanceId"] = agentInstanceId

  chart["queries"].each { | query |
    query["command"].sub! '[[agentInstanceId]]', agentInstanceId
  }

  test_chart = @client.searchOne("charts", "findByAgentInstanceIdAndChartId", { :agentInstanceId => agentInstanceId, :chartId => chart["chartId"]})
  if (test_chart == nil)
    client.post("charts", chart)
  else
    client.patch("charts", RestClientWrapper.load_entity_id(test_chart), chart)
  end
end