Added secondary agent id to events.
Ylian Saint-Hilaire committed
Apr 6, 2020 at 21:18 UTC
c8161aedc391fb815320a61162791cd8a6f1ea92
2 files changed
+11
-15
meshagent.js
+10
-14
@@ -709,7 +709,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
709
parent.agentStats.invalidMeshType2Count++;
710
console.log('Agent connected with invalid mesh type, holding connection (' + obj.remoteaddrport + ').');
711
return;
712
- }
712
+ }
713
714
// Mark when this device connected
715
obj.connectTime = Date.now();
@@ -907,10 +907,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
907
//console.log('recoveryAgentCoreIsStable()');
908
909
// Fetch the the real agent nodeid
910
- db.Get('da' + obj.dbNodeKey, function (err, nodes, self)
911
- {
912
- if ((nodes != null) && (nodes.length == 1))
913
- {
910
+ db.Get('da' + obj.dbNodeKey, function (err, nodes, self) {
911
+ if ((nodes != null) && (nodes.length == 1)) {
912
self.realNodeKey = nodes[0].raid;
913
914
// Get agent connection state
@@ -919,8 +917,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
917
if (state) { agentConnected = ((state.connectivity & 1) != 0) }
918
919
self.send(JSON.stringify({ action: 'diagnostic', value: { command: 'query', value: self.realNodeKey, agent: agentConnected } }));
922
- } else
923
- {
920
+ } else {
921
self.send(JSON.stringify({ action: 'diagnostic', value: { command: 'query', value: null } }));
922
}
923
}, obj);
@@ -1051,7 +1048,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1048
// Not a valid signature
1049
parent.agentStats.invalidPkcsSignatureCount++;
1050
return false;
1054
- }
1051
+ }
1052
} catch (ex) { };
1053
}
1054
}
@@ -1243,8 +1240,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1240
switch (command.value.command) {
1241
case 'register': {
1242
// Only main agent can do this
1246
- if (((obj.agentInfo.capabilities & 0x40) == 0) && (typeof command.value.value == 'string') && (command.value.value.length == 64))
1247
- {
1243
+ if (((obj.agentInfo.capabilities & 0x40) == 0) && (typeof command.value.value == 'string') && (command.value.value.length == 64)) {
1244
// Store links to diagnostic agent id
1245
var daNodeKey = 'node/' + domain.id + '/' + db.escapeBase64(command.value.value);
1246
db.Set({ _id: 'da' + daNodeKey, domain: domain.id, time: obj.connectTime, raid: obj.dbNodeKey }); // DiagnosticAgent --> Agent
@@ -1276,7 +1272,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1272
case 'log': {
1273
if (((obj.agentInfo.capabilities & 0x40) != 0) && (typeof command.value.value == 'string') && (command.value.value.length < 256)) {
1274
// If this is a diagnostic agent, log the event in the log of the main agent
1279
- var event = { etype: 'node', action: 'diagnostic', nodeid: obj.realNodeKey, domain: domain.id, msg: command.value.value };
1275
+ var event = { etype: 'node', action: 'diagnostic', nodeid: obj.realNodeKey, snodeid: obj.dbNodeKey, domain: domain.id, msg: command.value.value };
1276
parent.parent.DispatchEvent(parent.CreateMeshDispatchTargets(obj.dbMeshKey, [obj.dbNodeKey]), obj, event);
1277
}
1278
break;
@@ -1308,7 +1304,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1304
}
1305
case 'plugin': {
1306
if ((parent.parent.pluginHandler == null) || (typeof command.plugin != 'string')) break;
1311
- try {
1307
+ try {
1308
parent.parent.pluginHandler.plugins[command.plugin].serveraction(command, obj, parent);
1309
} catch (e) {
1310
console.log('Error loading plugin handler (' + e + ')');
@@ -1316,7 +1312,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1312
break;
1313
}
1314
default: {
1319
- parent.agentStats.unknownAgentActionCount++;
1315
+ parent.agentStats.unknownAgentActionCount++;
1316
console.log('Unknown agent action (' + obj.remoteaddrport + '): ' + command.action + '.');
1317
break;
1318
}
@@ -1453,7 +1449,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1449
if (device.agent.tag != tag) {
1450
// Do some clean up if needed, these values should not be in the database.
1451
if (device.conn != null) { delete device.conn; }
1456
- if (device.pwr != null) { delete device.pwr; }
1452
+ if (device.pwr != null) { delete device.pwr; }
1453
if (device.agct != null) { delete device.agct; }
1454
if (device.cict != null) { delete device.cict; }
1455
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.5.1-g",
3
+ "version": "0.5.1-h",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",