Class: SensuGenerator::Consul
- Inherits:
-
Object
- Object
- SensuGenerator::Consul
show all
- Defined in:
- lib/sensu_generator/consul.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Consul
Returns a new instance of Consul.
8
9
10
11
12
13
14
15
|
# File 'lib/sensu_generator/consul.rb', line 8
def initialize
@config = config
Diplomat.configure do |consul|
config.get[:consul].each do |k, v|
consul.public_send("#{k}=", v)
end
end
end
|
Instance Attribute Details
#config=(value) ⇒ Object
Sets the attribute config
6
7
8
|
# File 'lib/sensu_generator/consul.rb', line 6
def config=(value)
@config = value
end
|
#logger=(value) ⇒ Object
Sets the attribute logger
6
7
8
|
# File 'lib/sensu_generator/consul.rb', line 6
def logger=(value)
@logger = value
end
|
Instance Method Details
#get_service_props(svc) ⇒ Object
26
27
28
29
|
# File 'lib/sensu_generator/consul.rb', line 26
def get_service_props(svc)
result = Diplomat::Service.get(svc, :all)
result.class == Array ? result.map {|el| el.remove_consul_indexes} : result.remove_consul_indexes
end
|
#kv_svc_props(svc: name, key: nil) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/sensu_generator/consul.rb', line 31
def kv_svc_props(svc: name, key: nil)
opts = key ? nil : {recurse: true}
response = Diplomat::Kv.get("#{svc}/#{key}", opts)
key ? JSON(response) : response rescue
if response
if response.match(/\s+/) || key.to_s == config.get[:kv_tags_path] response.gsub(/\s+/, '').split(',')
else
response
end
else
[]
end
end
|
#sensu_servers ⇒ Object
17
18
19
20
|
# File 'lib/sensu_generator/consul.rb', line 17
def sensu_servers
get_service_props(config.get[:sensu][:service]).map {|el| el.ServiceAddress}.uniq.
map {|addr| SensuServer.new(address: addr)}
end
|
#services ⇒ Object
22
23
24
|
# File 'lib/sensu_generator/consul.rb', line 22
def services
Diplomat::Service.get_all.to_h
end
|