Added total memory to device CSV export, #3616

Ylian Saint-Hilaire committed Feb 8, 2022 at 11:51 UTC 6f3a0e67dd24b6a31872965abfed53145b53a4b7
1 file changed +15 -2
meshuser.js
+15 -2
@@ -4583,7 +4583,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4583 if (type == 'csv') {
4584 try {
4585 // Create the CSV file
4586 - output = 'id,name,rname,host,icon,ip,osdesc,groupname,av,update,firewall,avdetails,cpu,osbuild,biosDate,biosVendor,biosVersion,boardName,boardVendor,boardVersion,productUuid,agentOpenSSL,agentCommitDate,agentCommitHash,agentCompileTime,netIfCount,macs,addresses,lastConnectTime,lastConnectAddr\r\n';
4586 + output = 'id,name,rname,host,icon,ip,osdesc,groupname,av,update,firewall,avdetails,cpu,osbuild,biosDate,biosVendor,biosVersion,boardName,boardVendor,boardVersion,productUuid,totalMemory,agentOpenSSL,agentCommitDate,agentCommitHash,agentCompileTime,netIfCount,macs,addresses,lastConnectTime,lastConnectAddr\r\n';
4587 for (var i = 0; i < results.length; i++) {
4588 const nodeinfo = results[i];
4589
@@ -4625,6 +4625,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4625 if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.board_version)) { output += csvClean(nodeinfo.sys.hardware.identifiers.board_version); }
4626 output += ',';
4627 if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.product_uuid)) { output += csvClean(nodeinfo.sys.hardware.identifiers.product_uuid); }
4628 + output += ',';
4629 + if (nodeinfo.sys.hardware.windows.memory) {
4630 + var totalMemory = 0;
4631 + for (var j in nodeinfo.sys.hardware.windows.memory) {
4632 + if (nodeinfo.sys.hardware.windows.memory[j].Capacity) {
4633 + if (typeof nodeinfo.sys.hardware.windows.memory[j].Capacity == 'number') { totalMemory += nodeinfo.sys.hardware.windows.memory[j].Capacity; }
4634 + if (typeof nodeinfo.sys.hardware.windows.memory[j].Capacity == 'string') { totalMemory += parseInt(nodeinfo.sys.hardware.windows.memory[j].Capacity); }
4635 + }
4636 + }
4637 + output += csvClean('' + totalMemory);
4638 + }
4639 } else if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.mobile)) {
4640 // Mobile
4641 output += ',';
@@ -4640,6 +4651,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4651 output += ',';
4652 output += ',';
4653 if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.id)) { output += csvClean(nodeinfo.sys.hardware.mobile.id); }
4654 + output += ',';
4655 } else if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.windows) && (nodeinfo.sys.hardware.linux)) {
4656 // Linux
4657 output += ',';
@@ -4658,8 +4670,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4670 if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.board_version)) { output += csvClean(nodeinfo.sys.hardware.linux.board_version); }
4671 output += ',';
4672 if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.product_uuid)) { output += csvClean(nodeinfo.sys.hardware.linux.product_uuid); }
4673 + output += ',';
4674 } else {
4662 - output += ',,,,,,,,,';
4675 + output += ',,,,,,,,,,';
4676 }
4677
4678 // Agent information