Added device group name to reports. #3130

This commit is contained in:
Ylian Saint-Hilaire 2021-09-14 15:19:05 -07:00
parent 0a1b5b8f9c
commit 453eb369ee
2 changed files with 48 additions and 11 deletions

View File

@ -5485,12 +5485,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
// Columns
if (command.groupBy == 1) {
data.groupFormat = 'user';
data.columns = [{ id: 'time', title: "time", format: 'datetime' }, { id: 'nodeid', title: "device", format: 'node' }, { id: 'guestname', title: "guest", align: 'center' }, { id: 'protocol', title: "session", format: 'protocol', align: 'center' }, { id: 'length', title: "length", format: 'seconds', align: 'center', sumBy: 'protocol' } ];
data.columns = [{ id: 'time', title: "time", format: 'datetime' }, { id: 'nodeid', title: "device", format: 'node' }, { id: 'meshid', title: "devgroup", format: 'mesh' }, { id: 'guestname', title: "guest", align: 'center' }, { id: 'protocol', title: "session", format: 'protocol', align: 'center' }, { id: 'length', title: "length", format: 'seconds', align: 'center', sumBy: 'protocol' } ];
} else if (command.groupBy == 2) {
data.groupFormat = 'node';
data.groupFormat = 'nodemesh';
data.columns = [{ id: 'time', title: "time", format: 'datetime' }, { id: 'userid', title: "user", format: 'user' }, { id: 'guestname', title: "guest", align: 'center' }, { id: 'protocol', title: "session", format: 'protocol', align: 'center' }, { id: 'length', title: "length", format: 'seconds', align: 'center', sumBy: 'protocol' } ];
} else if (command.groupBy == 3) {
data.columns = [{ id: 'time', title: "time", format: 'time' }, { id: 'nodeid', title: "device", format: 'node' }, { id: 'guestname', title: "guest", align: 'center' }, { id: 'userid', title: "user", format: 'user' }, { id: 'protocol', title: "session", format: 'protocol', align: 'center' }, { id: 'length', title: "length", format: 'seconds', align: 'center', sumBy: 'protocol' } ];
data.columns = [{ id: 'time', title: "time", format: 'time' }, { id: 'nodeid', title: "device", format: 'node' }, { id: 'meshid', title: "devgroup", format: 'mesh' }, { id: 'guestname', title: "guest", align: 'center' }, { id: 'userid', title: "user", format: 'user' }, { id: 'protocol', title: "session", format: 'protocol', align: 'center' }, { id: 'length', title: "length", format: 'seconds', align: 'center', sumBy: 'protocol' } ];
}
// Add traffic columns
@ -5512,6 +5512,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (command.groupBy != 2) { entry.nodeid = docs[i].nodeid; }
entry.protocol = docs[i].protocol;
// Device Group
if (docs[i].ids != null) { for (var j in docs[i].ids) { if (docs[i].ids[j].startsWith('mesh/')) { entry.meshid = docs[i].ids[j]; } } }
// Add traffic data
if (command.showTraffic) { entry.bytesin = docs[i].bytesin; entry.bytesout = docs[i].bytesout; }
@ -5522,13 +5525,19 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (((docs[i].msgid >= 10) && (docs[i].msgid <= 12)) && (docs[i].msgArgs != null) && (typeof docs[i].msgArgs == 'object') && (typeof docs[i].msgArgs[3] == 'number')) { entry.length = docs[i].msgArgs[3]; }
else if ((docs[i].msgid >= 122) && (docs[i].msgid <= 126) && (docs[i].msgArgs != null) && (typeof docs[i].msgArgs == 'object') && (typeof docs[i].msgArgs[0] == 'number')) { entry.length = docs[i].msgArgs[0]; }
if (command.groupBy == 1) { // Add entry to per user group
if (command.groupBy == 1) { // Add entry to per user
if (data.groups[docs[i].userid] == null) { data.groups[docs[i].userid] = { entries: [] }; }
data.groups[docs[i].userid].entries.push(entry);
} else if (command.groupBy == 2) { // Add entry to per device group
if (data.groups[docs[i].nodeid] == null) { data.groups[docs[i].nodeid] = { entries: [] }; }
data.groups[docs[i].nodeid].entries.push(entry);
} else if (command.groupBy == 3) { // Add entry to per day group
} else if (command.groupBy == 2) { // Add entry to per mesh+device
if (entry.meshid != null) {
var k = docs[i].nodeid + '/' + entry.meshid;
if (data.groups[k] == null) { data.groups[k] = { entries: [] }; }
data.groups[k].entries.push(entry);
} else {
if (data.groups[docs[i].nodeid] == null) { data.groups[docs[i].nodeid] = { entries: [] }; }
data.groups[docs[i].nodeid].entries.push(entry);
}
} else if (command.groupBy == 3) { // Add entry to per day
var day;
if ((typeof command.l == 'string') && (typeof command.tz == 'string')) {
day = new Date(docs[i].time).toLocaleDateString(command.l, { timeZone: command.tz });
@ -5542,7 +5551,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}
// Remove guest column if not needed
if (guestNamePresent == false) { data.columns.splice(2, 1); }
if (guestNamePresent == false) {
if ((command.groupBy == 1) || (command.groupBy == 3)) {
data.columns.splice(3, 1);
} else if (command.groupBy == 2) {
data.columns.splice(2, 1);
}
}
try { ws.send(JSON.stringify({ action: 'report', data: data })); } catch (ex) { }
});

View File

@ -15019,7 +15019,7 @@
}
function renderReport(r) {
var colTranslation = { time: "Time", device: "Device", session: "Session", user: "User", guest: "Guest", length: "Length", bytesin: "Bytes In", bytesout: "Bytes Out" }
var colTranslation = { time: "Time", device: "Device", session: "Session", user: "User", devgroup: "Device Group", guest: "Guest", length: "Length", bytesin: "Bytes In", bytesout: "Bytes Out" }
var x = '<table style=width:100%>', firstItem;
var sumByCol = null; // Indicate by what colum we sum by
var sumByValues = []; // Indicate by what values we sum by
@ -15142,7 +15142,25 @@
}
if (f == 'node') {
var node = getNodeFromId(v);
if (node != null) { return '<div onclick=\'gotoDevice("' + node._id + '",10);haltEvent(event);\' style=float:left;margin-right:4px class="j' + node.icon + '"></div>' + EscapeHtml(node.name); } else { return '<i>' + "Unknown Device" + '</i>'; }
if (node != null) { return '<div onclick=\'gotoDevice("' + node._id + '",10);haltEvent(event);\' style=float:left;margin-right:4px class="j' + node.icon + '"></div>' + EscapeHtml(node.name); } else { return '<i>' + "Unknown" + '</i>'; }
}
if (f == 'mesh') {
var mesh = meshes[v];
if (mesh != null) { return '<div onclick=\'gotoMesh("' + mesh._id + '",10);haltEvent(event);\' style=float:left;margin-right:4px;cursor:pointer class="m99"></div>' + EscapeHtml(mesh.name); } else { return '<i>' + "Unknown" + '</i>'; }
}
if (f == 'nodemesh') {
var nodeid = null, meshid = null;
var s = v.split('/'), x = '<table><tr>';
if (s.length >= 3) { nodeid = s[0] + '/' + s[1] + '/' + s[2]; }
if (s.length >= 6) { meshid = s[3] + '/' + s[4] + '/' + s[5]; }
if (meshid != null) {
var mesh = meshes[meshid];
if (mesh != null) { x += '<td><div onclick=\'gotoMesh("' + mesh._id + '",10);haltEvent(event);\' style=float:left;margin-right:4px;cursor:pointer class="m99"></div>' + EscapeHtml(mesh.name) + '&nbsp;&nbsp;&nbsp;</td>'; } else { return '<i>' + "Unknown" + '</i>'; }
}
var node = getNodeFromId(nodeid);
if (node != null) { x += '<td><div onclick=\'gotoDevice("' + node._id + '",10);haltEvent(event);\' style=float:left;margin-right:4px class="j' + node.icon + '"></div>' + EscapeHtml(node.name) + '</td>'; } else { return '<i>' + "Unknown" + '</i>'; }
x += '</tr></table>';
return x;
}
if (f == 'user') {
var user = null;
@ -15171,6 +15189,10 @@
var node = getNodeFromId(v);
if (node != null) { return node.name; }
}
if (f == 'mesh') {
var mesh = meshes[v];
if (mesh != null) { return mesh.name }
}
if (f == 'user') {
var user = null;
if (v == userinfo._id) { user = userinfo; } else { if (users != null) { user = users[v]; } }