forked from criteo/consul-templaterb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodes.html.erb
52 lines (50 loc) · 1.96 KB
/
nodes.html.erb
1
2
3
4
5
6
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<%= render_file('common/header.html.erb', title: 'Nodes') %><%
service_tag_filter = ENV['SERVICES_TAG_FILTER'] || nil
# Services to hide
services_blacklist_raw = (ENV['EXCLUDE_SERVICES'] || 'lbl7.*,netsvc-probe.*,consul-probed.*').split(',')
services_blacklist = services_blacklist_raw.map { |v| Regexp.new(v) }
service_per_node = {}
services.each do |service_name, tags|
if !services_blacklist.any? {|r| r.match(service_name)}
service(service_name, tag: service_tag_filter).sort {|a,b| a['Node']['Node'] <=> b['Node']['Node'] }.each do |snode|
node_services = service_per_node[snode['Node']['Node']] || []
node_services.push(snode)
service_per_node[snode['Node']['Node']] = node_services
end
end
end %>
<h1 id="nodes">List all nodes for DC, sorted by name</h1>
<ul class="list-group">
<% nodes.sort {|a,b| a['Node'] <=> b['Node'] }.each do |snode|
%><li id="node_<%= snode['ID'] %>" class="list-group-item">
<a href="ssh://<%= snode['Address']%>"><%= snode['Address'] %></a> <%= snode['Node'] %><%
snode['Meta'].each do |k,v|
if v && !v.empty?
%><span class="badge badge-pill badge-primary float-right"><%= k %>: <%= v%></span><%
end
end if snode['Meta']
%><div><%
if service_per_node.key?(snode['Node'])
service_per_node[snode['Node']].each do |service|
tags = service['Service']['Tags'].sort
addr = service.service_address
port_num = service['Service']['Port'].to_i
port = port_num && port_num > 0 ? ":#{port_num}" : ''
url = if tags.include? 'https'
"https://#{addr}#{port}"
elsif tags.include? 'http'
"http://#{addr}#{port}"
elsif tags.include? 'ftp'
"ftp://#{addr}#{port}"
else
nil
end
%> <a class="badge badge-secondary" href='<%= url %>'>
<%= service['Service']['Service'] %>: <%= port_num %>
</a>
<% end
end
%></div></li>
<% end %>
</ul>
<%= render_file 'common/footer.html.erb' %>