Added agent trouble detection on the server.
This commit is contained in:
parent
b5fb7ad3de
commit
cd09f64b47
24
meshagent.js
24
meshagent.js
|
@ -326,6 +326,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||||
if (obj.nodeid != null) {
|
if (obj.nodeid != null) {
|
||||||
//console.log('Agent disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ') id=' + obj.agentInfo.agentId);
|
//console.log('Agent disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ') id=' + obj.agentInfo.agentId);
|
||||||
obj.parent.parent.debug(1, 'Agent disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ') id=' + obj.agentInfo.agentId);
|
obj.parent.parent.debug(1, 'Agent disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ') id=' + obj.agentInfo.agentId);
|
||||||
|
|
||||||
|
// Log the agent disconnection
|
||||||
|
if (obj.parent.wsagentsDisconnections[obj.nodeid] == null) {
|
||||||
|
obj.parent.wsagentsDisconnections[obj.nodeid] = 1;
|
||||||
|
} else {
|
||||||
|
obj.parent.wsagentsDisconnections[obj.nodeid] = ++obj.parent.wsagentsDisconnections[obj.nodeid];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
obj.close(0);
|
obj.close(0);
|
||||||
});
|
});
|
||||||
|
@ -411,9 +418,25 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||||
delete obj.pendingCompleteAgentConnection;
|
delete obj.pendingCompleteAgentConnection;
|
||||||
obj.authenticated = 2;
|
obj.authenticated = 2;
|
||||||
|
|
||||||
|
// Check how many times this agent disconnected in the last few minutes.
|
||||||
|
var disconnectCount = obj.parent.wsagentsDisconnections[obj.nodeid];
|
||||||
|
if (disconnectCount > 6) {
|
||||||
|
console.log('Agent in big trouble: NodeId=' + obj.nodeid + ', IP=' + obj.remoteaddrport + ', Agent=' + obj.agentInfo.agentId + '.');
|
||||||
|
// TODO: Log or do something to recover?
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Command 4, inform mesh agent that it's authenticated.
|
// Command 4, inform mesh agent that it's authenticated.
|
||||||
obj.send(obj.common.ShortToStr(4));
|
obj.send(obj.common.ShortToStr(4));
|
||||||
|
|
||||||
|
if (disconnectCount > 4) {
|
||||||
|
// Too many disconnections, this agent has issues. Just clear the core.
|
||||||
|
obj.send(obj.common.ShortToStr(10) + obj.common.ShortToStr(0));
|
||||||
|
console.log('Agent in trouble: NodeId=' + obj.nodeid + ', IP=' + obj.remoteaddrport + ', Agent=' + obj.agentInfo.agentId + '.');
|
||||||
|
// TODO: Log or do something to recover?
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we need to make an native update check
|
// Check if we need to make an native update check
|
||||||
obj.agentExeInfo = obj.parent.parent.meshAgentBinaries[obj.agentInfo.agentId];
|
obj.agentExeInfo = obj.parent.parent.meshAgentBinaries[obj.agentInfo.agentId];
|
||||||
const corename = obj.parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId].core;
|
const corename = obj.parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId].core;
|
||||||
|
@ -468,6 +491,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "meshcentral",
|
"name": "meshcentral",
|
||||||
"version": "0.2.6-t",
|
"version": "0.2.6-v",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Remote Management",
|
"Remote Management",
|
||||||
"Intel AMT",
|
"Intel AMT",
|
||||||
|
|
|
@ -140,6 +140,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
|
||||||
|
|
||||||
// Main lists
|
// Main lists
|
||||||
obj.wsagents = {};
|
obj.wsagents = {};
|
||||||
|
obj.wsagentsDisconnections = {};
|
||||||
|
obj.wsagentsDisconnectionsTimer = null;
|
||||||
obj.wssessions = {}; // UserId --> Array Of Sessions
|
obj.wssessions = {}; // UserId --> Array Of Sessions
|
||||||
obj.wssessions2 = {}; // "UserId + SessionRnd" --> Session (Note that the SessionId is the UserId + / + SessionRnd)
|
obj.wssessions2 = {}; // "UserId + SessionRnd" --> Session (Note that the SessionId is the UserId + / + SessionRnd)
|
||||||
obj.wsPeerSessions = {}; // ServerId --> Array Of "UserId + SessionRnd"
|
obj.wsPeerSessions = {}; // ServerId --> Array Of "UserId + SessionRnd"
|
||||||
|
@ -2004,6 +2006,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
|
||||||
|
|
||||||
// Indicates to ExpressJS that the public folder should be used to serve static files.
|
// Indicates to ExpressJS that the public folder should be used to serve static files.
|
||||||
obj.app.use(url, obj.express.static(obj.path.join(__dirname, 'public')));
|
obj.app.use(url, obj.express.static(obj.path.join(__dirname, 'public')));
|
||||||
|
|
||||||
|
// Start regular disconnection list flush every 2 minutes.
|
||||||
|
obj.wsagentsDisconnectionsTimer = setInterval(function () { obj.wsagentsDisconnections = {}; }, 120000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start server on a free port
|
// Start server on a free port
|
||||||
|
|
Loading…
Reference in New Issue