forked from criteo/consul-templaterb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
checks.html.erb
130 lines (129 loc) · 5.22 KB
/
checks.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<%= render_file('common/header.html.erb', title: 'Consul Checks') %>
<%
# This template can be configure the following way with environment variables
# Environment variables to filter services/instances
# SERVICES_TAG_FILTER: basic tag filter for service (default HTTP)
services_tag_filter = ENV['SERVICES_TAG_FILTER']
def status_to_class(status)
if status == 'passing'
'success'
elsif status == 'warning'
'warning'
elsif status == 'critical'
'danger'
else
'info'
end
end
%>
<style>
.check {
transition: opacity 1s ease-out;
}
</style>
<script>//<!--
function updateStates() {
states = ['passing', 'warning', 'critical']
stylesheet = document.getElementById('css-states');
txt = "";
for (var i in states) {
var s = states[i];
is_checked = document.getElementById('show_'+s).checked
var to_append = "." + s + " { ";
if (is_checked) {
to_append += "display: block"
} else {
to_append += "display:none"
}
to_append += " }\r\n"
txt += to_append;
}
stylesheet.textContent = txt;
}
//->
</script>
<div class="container-fluid">
<div class="row">
<nav class="col-2">
<ul>
<%
all_services = services(tag: services_tag_filter)
all_services.each do |service_name, tags|
%>
<li><a title="<%= tags.sort.join(', ') %>" href="#service_<%= service_name %>"><%= service_name %></a></li>
<% end %>
</ul>
</nav>
<main class="col-10">
<div class="float-right">
<span class="state-selector">
<input id="show_passing" type="checkbox" class="checks-visibility" value="passing" checked="checked" onchange="updateStates()"/>
<label for="show_passing"><span class="badge badge-success">Passing</span></label>
</span>
<span class="state-selector">
<input id="show_warning" type="checkbox" class="checks-visibility" value="warning" checked="checked" onchange="updateStates()"/>
<label for="show_warning"><span class="badge badge-warning">Warning</span></label>
</span>
<span class="state-selector">
<input id="show_critical" type="checkbox" class="checks-visibility" value="critical" checked="checked" onchange="updateStates()"/>
<label for="show_critical"><span class="badge badge-danger">Critical</span></label>
</span>
</div>
<h1 id="services">Services <%= services_tag_filter ? " tag: #{services_tag_filter}" : 'No filtering' %></h1>
<% all_services.each do |service_name, tags|
passing = 0
warning = 0
critical = 0
service_state = 'passing'
sum = 0
checks_for_service(service_name).each do |check|
st = check['Status']
sum += 1
case st
when 'warning'
warning += 1
when 'passing'
passing += 1
else
critical += 1
end
end
service_state = 'warning' if warning > 0
service_state = 'critical' if critical > 0
%>
<div class="service <%= service_state %>" id="service_<%= service_name %>">
<h2 class="service-name text-<%= status_to_class(service_state) %>">Service <%= service_name %>
<span class="float-right">
<span class="badge badge-pill badge-success"><%= passing > 0 ? passing : nil %></span>
<span class="badge badge-pill badge-warning"><%= warning > 0 ? warning : nil %></span>
<span class="badge badge-pill badge-danger"><%= critical > 0 ? critical : nil %></span>
</span>
</h2>
<% if sum > 0
%><div class="progress">
<div title="<%= "#{passing} / #{sum}" %>" class="progress-bar bg-success" role="progressbar" style="width:<%= (100.0 * passing / sum).round(2) %>%" aria-valuenow="<%= passing %>" aria-valuemin="0" aria-valuemax="<%= sum %>"></div>
<div title="<%= "#{warning} / #{sum}" %>" class="progress-bar bg-warning" role="progressbar" style="width:<%= (100.0 * warning / sum).round(2) %>%" aria-valuenow="<%= warning %>" aria-valuemin="0" aria-valuemax="<%= sum %>"></div>
<div title="<%= "#{critical} / #{sum}" %>" class="progress-bar bg-danger" role="progressbar" style="width:<%= (100.0 * critical / sum).round(2) %>%" aria-valuenow="<%= critical %>" aria-valuemin="0" aria-valuemax="<%= sum %>"></div>
</div>
<% end %>
<div class="list-group">
<% checks_for_service(service_name).each do |check| %>
<div class="list-group-item check <%= check['Status'] %>" id="<%= check['Node'] + check['CheckID'] %>">
<div class="d-flex align-items-center justify-content-between">
<h5>
<%= check['Name'] %> / <%= check['Node'] %>
</h5>
<span class="badge badge-pill badge-<%= status_to_class(check['Status']) %>"><%= check['Status'] %></span>
</div>
<p><%= ERB::Util.html_escape(check['Notes']) %></p>
<code><%= ERB::Util.html_escape(check['Output']) %></code>
</div>
<% end %>
</div>
</div>
<% end %>
</main>
</div>
</div>
<script>updateStates();</script>
<%= render_file('common/footer.html.erb') %>