mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-24 06:05:53 -05:00
Added agent trouble detection on the server.
This commit is contained in:
parent
14f5d092de
commit
5a2d3512ca
24
meshagent.js
24
meshagent.js
@ -326,6 +326,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||
if (obj.nodeid != null) {
|
||||
//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);
|
||||
|
||||
// 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);
|
||||
});
|
||||
@ -411,9 +418,25 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||
delete obj.pendingCompleteAgentConnection;
|
||||
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.
|
||||
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
|
||||
obj.agentExeInfo = obj.parent.parent.meshAgentBinaries[obj.agentInfo.agentId];
|
||||
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",
|
||||
"version": "0.2.6-t",
|
||||
"version": "0.2.6-v",
|
||||
"keywords": [
|
||||
"Remote Management",
|
||||
"Intel AMT",
|
||||
|
@ -140,6 +140,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
|
||||
|
||||
// Main lists
|
||||
obj.wsagents = {};
|
||||
obj.wsagentsDisconnections = {};
|
||||
obj.wsagentsDisconnectionsTimer = null;
|
||||
obj.wssessions = {}; // UserId --> Array Of Sessions
|
||||
obj.wssessions2 = {}; // "UserId + SessionRnd" --> Session (Note that the SessionId is the 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.
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user