-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdevice.js
More file actions
104 lines (69 loc) · 3.23 KB
/
Copy pathdevice.js
File metadata and controls
104 lines (69 loc) · 3.23 KB
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
import { GetSDTable, GetSlowCommands, MakePlotDataFromPSQL, MakePlot, GetPSQLTable} from "/includes/functions.js";
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const name = urlParams.get('name');
const ip = urlParams.get('ip');
const port = urlParams.get('port')
var status_div = document.getElementById('status');
var commands_div = document.getElementById('commands');
var commands_output_div = document.getElementById('commands_output');
var plots_div = document.getElementById('plots');
var logs_div = document.getElementById('logs');
var sqlquery
var replot = false
GetData();
var updateinterval = setInterval(GetData, 5000);
function GetData(){
GetSDTable(name, true).then(function(result){
const titleRow = document.createElement("tr");
// Array of title names
const titles = ["", "IP", "Port", "Name", "Status"];
// Create and append the title cells
for (const title of titles) {
const titleCell = document.createElement("td");
titleCell.textContent = title;
titleRow.appendChild(titleCell);
}
// Add the title row to the table
result.insertBefore(titleRow, result.firstChild);
// Center the table within its container
result.style.margin = "auto";
result.style.border = "1px solid black"; // Add a border of 1px solid black
result.style.borderCollapse = "collapse"; // Optional: Collapses the border into a single border
result.style.backgroundColor = "lightblue"; // Sets the background color of the table
const cells = result.getElementsByTagName("td");
for (const cell of cells) {
cell.style.border = "1px solid black"; // Add a border to each cell
cell.style.padding = "8px"; // Optional: Add some padding to improve readability
}
status_div.innerHTML = "";
status_div.appendChild(result);
// Optional: Add some styles to the table container
status_div.style.width = "80%"; // Set the container width to 80% of its parent element
status_div.style.padding = "20px"; // Add some padding for better presentation
});
GetSlowCommands(ip, port, commands_output_div, true).then(function(result){
commands_div.innerHTML = result;
});
sqlquery = "select * from monitoring where device='" + name + "' order by time asc";
var data = [];
MakePlotDataFromPSQL(sqlquery, "root", "daq", data, true).then(function(result){
MakePlot(plots_div, data, layout_timeseries_slider_selector, replot);
replot=true;
});
sqlquery = "select time, severity, message from logging where device='" + name + "' order by time desc";
GetPSQLTable(sqlquery , "root", "daq", true).then(function(result){
// result.style.margin = "auto";
var table=document.createElement("table");
table.innerHTML=result;
logs.innerHTML="";
for (const row of table.rows) {
// Loop through cells of each row
if(row.rowIndex==0) continue;
logs.innerHTML += "<b>" + row.cells[0].innerText + " [" + row.cells[1].innerText + "]: </b>" +row.cells[2].innerText +"<br>";
}
logs.style.whiteSpace = "normal";
logs.style.width = (window.innerWidth *0.8)+"px"; // Set the container width to 80% of its parent element
logs.style.padding = "20px"; // Add some padding for better presentation
});
}