0543266c92
- Restructuring of the project directory into client and server components - Renaming of modules and classes to better reflect their purpose and functionality - Moving common utilities and configurations to a shared location - Updating import statements to reflect the new structure - Adding new documentation files for better clarity on various aspects of the project - Removing deprecated or unused code to streamline the codebase - Ensuring that all existing functionality is preserved and that the codebase remains functional after the refactoring.
331 lines
9.4 KiB
HTML
331 lines
9.4 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
{% include 'head.html' %}
|
|
|
|
<style>
|
|
.nav {
|
|
background: #fff;
|
|
padding: 15px;
|
|
margin-bottom: 20px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.nav a {
|
|
margin-right: 20px;
|
|
text-decoration: none;
|
|
color: #0066cc;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.nav a:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
.nav a.active {
|
|
color: #333;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.content {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.table {
|
|
/* flex: 1; */
|
|
flex-grow: none;
|
|
}
|
|
|
|
.log {
|
|
flex: 2;
|
|
flex-grow: 1;
|
|
|
|
}
|
|
|
|
#ntable {
|
|
border-collapse: collapse;
|
|
font-size: 95%;
|
|
/* width: 100%; */
|
|
}
|
|
|
|
#ntable td,
|
|
#ntable th {
|
|
border: 1px solid #ddd;
|
|
text-align: left;
|
|
padding: 0px;
|
|
}
|
|
|
|
#ntable tr:nth-child(even) {
|
|
background-color: #f2f2f2;
|
|
}
|
|
|
|
#ntable tr:hover {
|
|
background-color: #ddd;
|
|
}
|
|
|
|
#ntable th {
|
|
padding-top: 12px;
|
|
padding-bottom: 12px;
|
|
background-color: #9d9d9d;
|
|
color: white;
|
|
}
|
|
|
|
#ntable
|
|
th:not(.sorttable_sorted):not(.sorttable_sorted_reverse):not(.sorttable_nosort):after {
|
|
content: " \2195";
|
|
}
|
|
|
|
/* Modal for connection status messages */
|
|
.connection-modal {
|
|
display: none;
|
|
position: fixed;
|
|
z-index: 1000;
|
|
left: 0;
|
|
top: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0, 0, 0, 0.4);
|
|
}
|
|
|
|
.connection-modal.show {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
}
|
|
|
|
.connection-modal-content {
|
|
background-color: #f9f9f9;
|
|
padding: 20px;
|
|
border: 1px solid #888;
|
|
border-radius: 5px;
|
|
text-align: center;
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
|
min-width: 300px;
|
|
}
|
|
|
|
.connection-modal-content p {
|
|
margin: 10px 0;
|
|
font-size: 16px;
|
|
color: #333;
|
|
}
|
|
</style>
|
|
<script type="text/javascript">
|
|
var cnt = 0;
|
|
var nTable = document;
|
|
var name_idx = {};
|
|
var c = 0;
|
|
|
|
function setup() {
|
|
name_idx = {};
|
|
nTable = document.getElementById("ntable");
|
|
for (var i = 0, row; (row = nTable.rows[i]); i++) {
|
|
if (i == 0) continue;
|
|
name = nTable.rows[i].cells[0].innerText;
|
|
name_idx[name] = nTable.rows[i];
|
|
/* console.log("name_Id[" + name + "]: " + name_idx[name].innerText); */
|
|
}
|
|
}
|
|
|
|
function createRow(data) {
|
|
var row = document.createElement("tr");
|
|
var c_name = document.createElement("td");
|
|
var c_ver = document.createElement("td");
|
|
var c_ipv4addr = document.createElement("td");
|
|
var c_ipv4state = document.createElement("td");
|
|
var c_ipv4latency = document.createElement("td");
|
|
c_ipv4latency.style.textAlign = "right";
|
|
var c_ipv4statets = document.createElement("td");
|
|
c_ipv4statets.style.textAlign = "right";
|
|
var c_ipv6addr = document.createElement("td");
|
|
var c_ipv6state = document.createElement("td");
|
|
var c_ipv6latency = document.createElement("td");
|
|
c_ipv6latency.style.textAlign = "right";
|
|
var c_ipv6statets = document.createElement("td");
|
|
c_ipv6statets.style.textAlign = "right";
|
|
row.appendChild(c_name);
|
|
row.appendChild(c_ver);
|
|
row.appendChild(c_ipv4addr);
|
|
row.appendChild(c_ipv4state);
|
|
row.appendChild(c_ipv4latency);
|
|
row.appendChild(c_ipv4statets);
|
|
row.appendChild(c_ipv6addr);
|
|
row.appendChild(c_ipv6state);
|
|
row.appendChild(c_ipv6latency);
|
|
row.appendChild(c_ipv6statets);
|
|
if (data.dyn) {
|
|
c_name.innerHTML = "<b>" + data.name + "</b>";
|
|
} else {
|
|
c_name.innerHTML = data.name;
|
|
}
|
|
c_ver.innerHTML = data.cver;
|
|
c_ipv4addr.innerHTML = data.connections[0].addr;
|
|
c_ipv4state.innerHTML = data.connections[0].state;
|
|
if (data.connections.length > 1) {
|
|
c_ipv6addr.innerHTML = data.connections[1].addr;
|
|
c_ipv6state.innerHTML = data.connections[1].state;
|
|
}
|
|
var table = document.getElementById("ntablebody"); // find table to append to
|
|
table.appendChild(row); // append row to table
|
|
name_idx[c_name] = row;
|
|
}
|
|
|
|
function formatTS(ts) {
|
|
const milliseconds = ts * 1000;
|
|
const dateObject = new Date(milliseconds);
|
|
return dateObject.toLocaleString("de-DE");
|
|
}
|
|
|
|
function update_table(data) {
|
|
if (!(data.name in name_idx)) {
|
|
createRow(data);
|
|
setup();
|
|
}
|
|
|
|
for (var i = 0; i < data.connections.length; i++) {
|
|
name_idx[data.name].cells[2 + i * 4].innerHTML = data.connections[i].addr;
|
|
name_idx[data.name].cells[5 + i * 4].innerHTML = formatTS(
|
|
data.connections[i].statetime
|
|
);
|
|
if (data.connections[i].state == "up") {
|
|
state = "up";
|
|
latency = Number.parseFloat(data.connections[i].rtts[0]).toFixed(2);
|
|
} else {
|
|
if (data.connections[i].state == "unknown") {
|
|
state = "";
|
|
latency = "";
|
|
name_idx[data.name].cells[2 + i * 4].innerHTML = "";
|
|
name_idx[data.name].cells[5 + i * 4].innerHTML = "";
|
|
} else {
|
|
state = "<b>" + data.connections[i].state + "</b>";
|
|
latency = "-";
|
|
}
|
|
}
|
|
name_idx[data.name].cells[3 + i * 4].innerHTML = state;
|
|
name_idx[data.name].cells[4 + i * 4].innerHTML = latency;
|
|
}
|
|
}
|
|
|
|
function WS_Connect() {
|
|
if ("WebSocket" in window) {
|
|
//N.B: subprotocol field causes chrome to error 1006
|
|
var ws_hbd = new WebSocket("{{heartbeat_ws_url}}", /* "hdb" */ );
|
|
|
|
ws_hbd.onopen = function () {
|
|
// Web Socket is connected, send data using send()
|
|
console.log("ws connect {{heartbeat_ws_url}}");
|
|
// Hide modal window if visible
|
|
var modal = document.getElementById("connectionModal");
|
|
if (modal) {
|
|
modal.classList.remove("show");
|
|
}
|
|
ws_hbd.send("heartbeat_web");
|
|
};
|
|
|
|
ws_hbd.onerror = function (event) {
|
|
console.log(event);
|
|
};
|
|
|
|
ws_hbd.onmessage = function (event) {
|
|
/* console.log(event.data); */
|
|
var state = JSON.parse(event.data);
|
|
/* console.log("State: " + state.type); */
|
|
if (state.type == "host") {
|
|
update_table(state.data);
|
|
} else if (state.type == "message") {
|
|
var msgs = document.getElementById("messages");
|
|
msgs.insertAdjacentHTML("afterbegin", state.data + "<br>");
|
|
}
|
|
cnt++;
|
|
};
|
|
|
|
ws_hbd.onclose = function (event) {
|
|
/* console.log(event); */
|
|
console.log("Connection is closed, reopening");
|
|
// Show modal window
|
|
var modal = document.getElementById("connectionModal");
|
|
if (modal) {
|
|
modal.classList.add("show");
|
|
}
|
|
setTimeout(function () {
|
|
WS_Connect();
|
|
}, 3000);
|
|
};
|
|
} else {
|
|
// The browser doesn't support WebSocket
|
|
console.log("WebSocket NOT supported by your Browser!");
|
|
}
|
|
}
|
|
WS_Connect();
|
|
</script>
|
|
<body>
|
|
<div class="nav">
|
|
<a href="/live" class="active">Live Dashboard</a>
|
|
<a href="/plugins">Plugin Metrics</a>
|
|
<a href="/alerts">Alerts</a>
|
|
</div>
|
|
|
|
{% include 'menu.html' %}
|
|
|
|
<div id="content" class="content" style="overflow: hidden">
|
|
<div id="table" class="table" style="overflow: hidden">
|
|
<!-- <h2>{{title}}</h2> -->
|
|
<table id="ntable" class="sortable">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Ver</th>
|
|
<th>IPv4 Addr</th>
|
|
<th>State</th>
|
|
<th style="text-align: right">Latencey</th>
|
|
<th style="text-align: right">Last State</th>
|
|
<th>IPv6 Addr</th>
|
|
<th>State</th>
|
|
<th style="text-align: right">Latencey</th>
|
|
<th style="text-align: right">Last State</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="ntablebody">
|
|
{% for host in hosts %}
|
|
<tr>
|
|
<td>{{ host.name }}</td>
|
|
<td>{{ host.ver if host.ver else '' }}</td>
|
|
{% for conn in host.connections %}
|
|
<td>{{ conn.addr if conn.addr else '' }}</td>
|
|
<td>{{ conn.state if conn.state else '' }}</td>
|
|
<td style="text-align: right">{{ conn.latency if conn.latency else '' }}</td>
|
|
<td style="text-align: right">{{ conn.last_state_ts if conn.last_state_ts else '' }}</td>
|
|
{% endfor %}
|
|
{% if host.connections|length == 0 %}
|
|
<td></td><td></td><td></td><td></td>
|
|
<td></td><td></td><td></td><td></td>
|
|
{% elif host.connections|length == 1 %}
|
|
<td></td><td></td><td></td><td></td>
|
|
{% endif %}
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div id="log" class="log" style="overflow: auto;">
|
|
<h2>Log of Events</h2>
|
|
<div id="messages">
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% include 'foot.html' %}
|
|
|
|
<!-- Connection status modal -->
|
|
<div id="connectionModal" class="connection-modal">
|
|
<div class="connection-modal-content">
|
|
<p>⚠️ Connection is closed, reopening...</p>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
setup();
|
|
</script>
|
|
</body>
|
|
</html>
|