Class: Cloudscale::Preops::Preop

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudscale/monitor/preops/preop.rb

Direct Known Subclasses

Monitor::GeneralPreop, PluginPreop

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#logObject

Returns the value of attribute log.



13
14
15
# File 'lib/cloudscale/monitor/preops/preop.rb', line 13

def log
  @log
end

#registryObject

Returns the value of attribute registry.



13
14
15
# File 'lib/cloudscale/monitor/preops/preop.rb', line 13

def registry
  @registry
end

Instance Method Details

#initObject



15
16
17
18
19
# File 'lib/cloudscale/monitor/preops/preop.rb', line 15

def init
  @log = Logger.new(STDOUT)
  @registry = Monitor::Registry.instance
  @rest_client = RestClientWrapper.instance
end

#init_charts(path) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cloudscale/monitor/preops/preop.rb', line 21

def init_charts(path)
  log.info("Starting monitoring chart synchronization...")

  agentInstanceId = @registry.agent_instance_id
  
  plugin = YAML.load(JSON.parse(File.read(path)).to_yaml)
  plugin.each do | key, chart |
    chart["agentInstanceId"] = agentInstanceId

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

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

  log.info("Successfully synchronized charts...")
end

#init_menus(path) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/cloudscale/monitor/preops/preop.rb', line 45

def init_menus(path)
  log.info("Starting monitoring menu synchronization...")

  agentInstanceId = @registry.agent_instance_id

  plugin = YAML.load(JSON.parse(File.read(path)).to_yaml)
  plugin.each do | key, menuItem |
    menuItem["agentInstanceId"] = agentInstanceId
    test_menu = @rest_client.searchOne("menus", "findByAgentInstanceIdAndMenuId", { :agentInstanceId => agentInstanceId, :menuId => menuItem["menuId"]})
    if (test_menu == nil)
      @rest_client.post("menus", menuItem)
    else
      @rest_client.patch("menus", RestClientWrapper.load_entity_id(test_menu), menuItem)
    end
  end

  log.info("Successfully synchronized menus...")
end