Added Agent Error Log Fetching.

Ylian Saint-Hilaire committed Apr 17, 2021 at 14:44 UTC 8b2835d40a924aedbd6cc609d68ae7ac401aa2c9
7 files changed +40 -2
agents/meshcore.js
+3
@@ -1249,6 +1249,9 @@ function handleServerCommand(data) {
1249 agentFileHttpPendingRequests.push(data);
1250 serverFetchFile();
1251 break;
1252 + case 'errorlog': // Return agent error log
1253 + try { mesh.SendCommand(JSON.stringify({ action: 'errorlog', log: require('util-agentlog').read(data.startTime) })); } catch (ex) { }
1254 + break;
1255 default:
1256 // Unknown action, ignore it.
1257 break;
meshagent.js
+21
@@ -68,6 +68,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
68 db.Remove('nt' + obj.dbNodeKey); // Remove notes
69 db.Remove('lc' + obj.dbNodeKey); // Remove last connect time
70 db.Remove('si' + obj.dbNodeKey); // Remove system information
71 + db.Remove('al' + obj.dbNodeKey); // Remove error log last time
72 if (db.RemoveSMBIOS) { db.RemoveSMBIOS(obj.dbNodeKey); } // Remove SMBios data
73 db.RemoveAllNodeEvents(obj.dbNodeKey); // Remove all events for this node
74 db.removeAllPowerEventsForNode(obj.dbNodeKey); // Remove all power events for this node
@@ -1005,6 +1006,17 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1006 if ((results != null) && (results.length == 1)) { obj.send(JSON.stringify({ action: 'sysinfo', hash: results[0].hash })); } else { obj.send(JSON.stringify({ action: 'sysinfo' })); }
1007 });
1008
1009 + // Agent error log dump
1010 + if (parent.parent.agentErrorLog != null) {
1011 + db.Get('al' + obj.dbNodeKey, function (err, docs) { // Agent Log
1012 + if ((docs != null) && (docs.length == 1) && (typeof docs[0].lastEvent)) {
1013 + obj.send('{"action":"errorlog","startTime":' + docs[0].lastEvent + '}'); // Ask all events after a given time
1014 + } else {
1015 + obj.send('{"action":"errorlog"}'); // Ask all
1016 + }
1017 + });
1018 + }
1019 +
1020 // Set agent core dump
1021 if ((parent.parent.config.settings != null) && ((parent.parent.config.settings.agentcoredump === true) || (parent.parent.config.settings.agentcoredump === false))) {
1022 obj.send(JSON.stringify({ action: 'coredump', value: parent.parent.config.settings.agentcoredump }));
@@ -1516,6 +1528,15 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1528 }
1529 break;
1530 }
1531 + case 'errorlog': { // This is the agent error log
1532 + if ((!Array.isArray(command.log)) || (command.log.length == 0) || (parent.parent.agentErrorLog == null)) break;
1533 + var lastLogEntry = command.log[command.log.length - 1];
1534 + if ((lastLogEntry != null) && (typeof lastLogEntry == 'object') && (typeof lastLogEntry.t == 'number')) {
1535 + parent.fs.write(parent.parent.agentErrorLog, obj.dbNodeKey + ', ' + Date.now() + ', ' + str + '\r\n', function (err) { });
1536 + db.Set({ _id: 'al' + obj.dbNodeKey, lastEvent: lastLogEntry.t });
1537 + }
1538 + break;
1539 + }
1540 case '2faauth': {
1541 // Validate input
1542 if ((typeof command.url != 'string') || (typeof command.approved != 'boolean') || (command.url.startsWith('2fa://') == false)) return;
meshcentral-config-schema.json
+1
@@ -61,6 +61,7 @@
61 "agentAliasPort": { "type": "integer", "minimum": 1, "maximum": 65535, "description": "When set, indicates the actual publically visible agent-only port. If not set, the AgentPort value is used." },
62 "agentAliasDNS": { "type": "string", "format": "hostname", "description": "When set, specified the DNS name used by agents to connect to the agent-only port." },
63 "agentPortTls": { "type": "boolean", "default": true, "description": "Indicates if the agent-only port must perform TLS, this should be set to false if TLS is performed in front of this server." },
64 + "agentLogDump": { "type": "boolean", "default": false, "description": "Automatically downloads all agent error logs into meshcentral-data/agenterrorlogs.txt." },
65 "agentCoreDump": { "type": "boolean", "default": false, "description": "Automatically activates and transfers any agent crash dump files to the server in meshcentral-data/coredumps." },
66 "agentCoreDumpUsers": { "type": "array", "description": "List of non-administrator users that have access to mesh agent crash dumps." },
67 "ignoreAgentHashCheck": { "type": [ "boolean", "string" ], "default": false, "description": "When true, the agent no longer checked the TLS certificate of the server. This should be used for debugging only. You can also set this to a comma seperated list of IP addresses to ignore, for example: \"192.168.2.100,192.168.1.0/24\"." },
meshcentral.js
+5
@@ -1308,6 +1308,11 @@ function CreateMeshCentralServer(config, args) {
1308 return;
1309 }
1310
1311 + // Setup agent error log
1312 + if ((obj.config) && (obj.config.settings) && (obj.config.settings.agentlogdump != null)) {
1313 + obj.fs.open(obj.path.join(obj.datapath, 'agenterrorlogs.txt'), 'a', function (err, fd) { obj.agentErrorLog = fd; })
1314 + }
1315 +
1316 // Perform other database cleanup
1317 obj.db.cleanup();
1318
meshuser.js
+1
@@ -3776,6 +3776,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3776 db.Remove('nt' + node._id); // Remove notes
3777 db.Remove('lc' + node._id); // Remove last connect time
3778 db.Remove('si' + node._id); // Remove system information
3779 + db.Remove('al' + node._id); // Remove error log last time
3780 if (db.RemoveSMBIOS) { db.RemoveSMBIOS(node._id); } // Remove SMBios data
3781 db.RemoveAllNodeEvents(node._id); // Remove all events for this node
3782 db.removeAllPowerEventsForNode(node._id); // Remove all power events for this node
public/styles/style.css
+7
@@ -316,6 +316,13 @@ body {
316 overflow: hidden;
317 }
318
319 +.boxsize {
320 + -ms-box-sizing:border-box;
321 + -moz-box-sizing:border-box;
322 + box-sizing:border-box;
323 + -webkit-box-sizing:border-box;
324 +}
325 +
326 .night #column_l {
327 background-color: #000;
328 }
views/default.handlebars
+2 -2
@@ -10207,8 +10207,8 @@
10207 var y = '', x = "Create a temporary username and password that can be used as alternative login to your account. This is useful for allowing tools or other services to access your account." + '<br /><br />';
10208 var options = { 0 : "Unlimited", 1 : "1 minute", 5 : "5 minutes", 10 : "10 minutes", 15 : "15 minutes", 30 : "30 minutes", 45 : "45 minutes", 60 : "60 minutes", 120 : "2 hours", 240 : "4 hours", 480 : "8 hours", 720 : "12 hours", 960 : "16 hours", 1440 : "24 hours", 2880 : "2 days", 5760 : "4 days" }
10209 for (var i in options) { y += '<option value=' + i + '>' + options[i] + '</option>'; }
10210 - x += addHtmlValue("Token Name", '<input id=d2tokenName style=width:250px maxlength=100 type=text onchange=account_createLoginTokenValidate() onkeyup=account_createLoginTokenValidate() />');
10211 - x += addHtmlValue("Expire Time", '<select id=d2tokenExpire style=width:250px>' + y + '</select>');
10210 + x += addHtmlValue("Token Name", '<input class=boxsize id=d2tokenName style=width:250px maxlength=100 type=text onchange=account_createLoginTokenValidate() onkeyup=account_createLoginTokenValidate() />');
10211 + x += addHtmlValue("Expire Time", '<select class=boxsize id=d2tokenExpire style=width:250px>' + y + '</select>');
10212 setDialogMode(2, "Create Login Token", 3, account_createLoginTokenEx, x);
10213 QE('idx_dlgOkButton', false);
10214 Q('d2tokenName').focus();