MeshAgent update debug improvements.
Ylian Saint-Hilaire committed
Oct 28, 2019 at 10:35 UTC
b06763ab30e0e1c24a93fcfb57914ffdbca19524
6 files changed
+31
-15
meshagent.js
+14
-6
@@ -126,6 +126,9 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
126
if (msg.length == 4) { ChangeAgentCoreInfo({ "caps": 0 }); } // If the agent indicated that no core is running, clear the core information string.
127
// Mesh core hash, sent by agent with the hash of the current mesh core.
128
129
+ // If we are performing an agent update, don't update the core.
130
+ if (obj.agentUpdate != null) { return; }
131
+
132
// If we are using a custom core, don't try to update it.
133
if (obj.agentCoreCheck == 1000) {
134
obj.sendBinary(common.ShortToStr(16) + common.ShortToStr(0)); // MeshCommand_CoreOk. Indicates to the agent that the core is ok. Start it if it's not already started.
@@ -236,7 +239,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
239
// Read the agent from disk
240
parent.fs.open(obj.agentExeInfo.path, 'r', function (err, fd) {
241
if (obj.agentExeInfo == null) return; // Agent disconnected during this call.
239
- if (err) { return console.error(err); }
242
+ if (err) { parent.parent.debug('agentupdate', "ERROR: " + err); return console.error(err); }
243
obj.agentUpdate = { ptr: 0, buf: Buffer.alloc(agentUpdateBlockSize + 4), fd: fd, taskid: taskid };
244
245
// MeshCommand_CoreModule, ask mesh agent to clear the core.
@@ -257,12 +260,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
260
// Error reading the agent file, stop here.
261
try { parent.fs.close(obj.agentUpdate.fd); } catch (ex) { }
262
parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete
263
+ parent.parent.debug('agentupdate', "ERROR: Unable to read first block of agent binary from disk.");
264
delete obj.agentUpdate.buf;
265
delete obj.agentUpdate;
266
} else {
267
// Send the first block to the agent
268
obj.agentUpdate.ptr += bytesRead;
265
- //console.log("Agent update send first block: " + bytesRead);
269
+ parent.parent.debug('agentupdate', "Sent first block of " + bytesRead + " bytes from disk.");
270
obj.sendBinary(obj.agentUpdate.buf); // Command 14, mesh agent first data block
271
}
272
});
@@ -290,8 +294,10 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
294
obj.agentExeInfo.data.copy(obj.agentUpdate.buf, 4, obj.agentUpdate.ptr, obj.agentUpdate.ptr + len);
295
obj.agentUpdate.ptr += len;
296
obj.sendBinary(obj.agentUpdate.buf); // Command 14, mesh agent first data block
297
+ parent.parent.debug('agentupdate', "Sent first block of " + len + " bytes from RAM.");
298
} else {
299
// Error
300
+ parent.parent.debug('agentupdate', "ERROR: Len of " + len + " is invalid.");
301
parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete
302
delete obj.agentUpdate.buf;
303
delete obj.agentUpdate;
@@ -317,17 +323,18 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
323
if ((obj.agentExeInfo == null) || (obj.agentUpdate == null)) return; // Agent disconnected during this async call.
324
if ((err != null) || (bytesRead < 0)) {
325
// Error reading the agent file, stop here.
326
+ parent.parent.debug('agentupdate', "ERROR: Unable to read agent #" + obj.agentExeInfo.id + " binary from disk.");
327
try { parent.fs.close(obj.agentUpdate.fd); } catch (ex) { }
328
parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete
329
delete obj.agentUpdate.buf;
330
delete obj.agentUpdate;
331
} else {
332
// Send the next block to the agent
333
+ parent.parent.debug('agentupdate', "Sending disk agent #" + obj.agentExeInfo.id + " block, ptr=" + obj.agentUpdate.ptr + ", len=" + bytesRead + ".");
334
obj.agentUpdate.ptr += bytesRead;
327
- //console.log("Agent update send next block", obj.agentUpdate.ptr, bytesRead);
335
if (bytesRead == agentUpdateBlockSize) { obj.sendBinary(obj.agentUpdate.buf); } else { obj.sendBinary(obj.agentUpdate.buf.slice(0, bytesRead + 4)); } // Command 14, mesh agent next data block
329
- if (bytesRead < agentUpdateBlockSize) {
330
- //console.log("Agent update sent from disk.");
336
+ if ((bytesRead < agentUpdateBlockSize) || (obj.agentUpdate.ptr == obj.agentExeInfo.size)) {
337
+ parent.parent.debug('agentupdate', "Completed agent #" + obj.agentExeInfo.id + " update from disk, ptr=" + obj.agentUpdate.ptr + ".");
338
obj.sendBinary(common.ShortToStr(13) + common.ShortToStr(0) + obj.agentExeInfo.hash); // Command 13, end mesh agent download, send agent SHA384 hash
339
try { parent.fs.close(obj.agentUpdate.fd); } catch (ex) { }
340
parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete
@@ -342,11 +349,12 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
349
if (len > 0) {
350
obj.agentExeInfo.data.copy(obj.agentUpdate.buf, 4, obj.agentUpdate.ptr, obj.agentUpdate.ptr + len);
351
if (len == agentUpdateBlockSize) { obj.sendBinary(obj.agentUpdate.buf); } else { obj.sendBinary(obj.agentUpdate.buf.slice(0, len + 4)); } // Command 14, mesh agent next data block
352
+ parent.parent.debug('agentupdate', "Sending RAM agent #" + obj.agentExeInfo.id + " block, ptr=" + obj.agentUpdate.ptr + ", len=" + len + ".");
353
obj.agentUpdate.ptr += len;
354
}
355
356
if (obj.agentUpdate.ptr == obj.agentExeInfo.data.length) {
349
- //console.log("Agent update sent from RAM.");
357
+ parent.parent.debug('agentupdate', "Completed agent #" + obj.agentExeInfo.id + " update from RAM, ptr=" + obj.agentUpdate.ptr + ".");
358
obj.sendBinary(common.ShortToStr(13) + common.ShortToStr(0) + obj.agentExeInfo.hash); // Command 13, end mesh agent download, send agent SHA384 hash
359
parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete
360
delete obj.agentUpdate.buf;
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.4.3-h",
3
+ "version": "0.4.3-i",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",
views/default-min.handlebars
+4
-2
@@ -8154,6 +8154,8 @@
8154
x += '<div><label><input type=checkbox id=p41c2 ' + ((serverTraceSources.indexOf('dispatch') >= 0) ? 'checked' : '') + '>' + "Message Dispatcher" + '</label></div>';
8155
x += '<div><label><input type=checkbox id=p41c3 ' + ((serverTraceSources.indexOf('main') >= 0) ? 'checked' : '') + '>' + "Main Server Messages" + '</label></div>';
8156
x += '<div><label><input type=checkbox id=p41c4 ' + ((serverTraceSources.indexOf('peer') >= 0) ? 'checked' : '') + '>' + "MeshCentral Server Peering" + '</label></div>';
8157
+ x += '<div><label><input type=checkbox id=p41c15 ' + ((serverTraceSources.indexOf('agent') >= 0) ? 'checked' : '') + '>' + "MeshAgent traffic" + '</label></div>';
8158
+ x += '<div><label><input type=checkbox id=p41c14 ' + ((serverTraceSources.indexOf('agentupdate') >= 0) ? 'checked' : '') + '>' + "MeshAgent update" + '</label></div>';
8159
x += '<div style="width:100%;border-bottom:1px solid gray;margin-bottom:5px;margin-top:5px"><b>' + "Web Server" + '</b></div>';
8160
x += '<div><label><input type=checkbox id=p41c5 ' + ((serverTraceSources.indexOf('web') >= 0) ? 'checked' : '') + '>' + "Web Server" + '</label></div>';
8161
x += '<div><label><input type=checkbox id=p41c6 ' + ((serverTraceSources.indexOf('webrequest') >= 0) ? 'checked' : '') + '>' + "Web Server Requests" + '</label></div>';
@@ -8170,8 +8172,8 @@
8172
}
8173
8174
function setServerTracingEx(b) {
8173
- var sources = [], allsources = ['cookie', 'dispatch', 'main', 'peer', 'web', 'webrequest', 'relay', 'webrelaydata', 'webrelay', 'mps', 'mpscmd', 'swarm', 'swarmcmd'];
8174
- if (b == 1) { for (var i = 1; i < 13; i++) { try { if (Q('p41c' + i).checked) { sources.push(allsources[i - 1]); } } catch (ex) { } } }
8175
+ var sources = [], allsources = ['cookie', 'dispatch', 'main', 'peer', 'web', 'webrequest', 'relay', 'webrelaydata', 'webrelay', 'mps', 'mpscmd', 'swarm', 'swarmcmd', 'agentupdate', 'agent'];
8176
+ if (b == 1) { for (var i = 1; i < 16; i++) { try { if (Q('p41c' + i).checked) { sources.push(allsources[i - 1]); } } catch (ex) { } } }
8177
meshserver.send({ action: 'traceinfo', traceSources: sources });
8178
}
8179
views/default.handlebars
+4
-2
@@ -9136,6 +9136,8 @@
9136
x += '<div><label><input type=checkbox id=p41c2 ' + ((serverTraceSources.indexOf('dispatch') >= 0) ? 'checked' : '') + '>' + "Message Dispatcher" + '</label></div>';
9137
x += '<div><label><input type=checkbox id=p41c3 ' + ((serverTraceSources.indexOf('main') >= 0) ? 'checked' : '') + '>' + "Main Server Messages" + '</label></div>';
9138
x += '<div><label><input type=checkbox id=p41c4 ' + ((serverTraceSources.indexOf('peer') >= 0) ? 'checked' : '') + '>' + "MeshCentral Server Peering" + '</label></div>';
9139
+ x += '<div><label><input type=checkbox id=p41c15 ' + ((serverTraceSources.indexOf('agent') >= 0) ? 'checked' : '') + '>' + "MeshAgent traffic" + '</label></div>';
9140
+ x += '<div><label><input type=checkbox id=p41c14 ' + ((serverTraceSources.indexOf('agentupdate') >= 0) ? 'checked' : '') + '>' + "MeshAgent update" + '</label></div>';
9141
x += '<div style="width:100%;border-bottom:1px solid gray;margin-bottom:5px;margin-top:5px"><b>' + "Web Server" + '</b></div>';
9142
x += '<div><label><input type=checkbox id=p41c5 ' + ((serverTraceSources.indexOf('web') >= 0) ? 'checked' : '') + '>' + "Web Server" + '</label></div>';
9143
x += '<div><label><input type=checkbox id=p41c6 ' + ((serverTraceSources.indexOf('webrequest') >= 0) ? 'checked' : '') + '>' + "Web Server Requests" + '</label></div>';
@@ -9152,8 +9154,8 @@
9154
}
9155
9156
function setServerTracingEx(b) {
9155
- var sources = [], allsources = ['cookie', 'dispatch', 'main', 'peer', 'web', 'webrequest', 'relay', 'webrelaydata', 'webrelay', 'mps', 'mpscmd', 'swarm', 'swarmcmd'];
9156
- if (b == 1) { for (var i = 1; i < 13; i++) { try { if (Q('p41c' + i).checked) { sources.push(allsources[i - 1]); } } catch (ex) { } } }
9157
+ var sources = [], allsources = ['cookie', 'dispatch', 'main', 'peer', 'web', 'webrequest', 'relay', 'webrelaydata', 'webrelay', 'mps', 'mpscmd', 'swarm', 'swarmcmd', 'agentupdate', 'agent'];
9158
+ if (b == 1) { for (var i = 1; i < 16; i++) { try { if (Q('p41c' + i).checked) { sources.push(allsources[i - 1]); } } catch (ex) { } } }
9159
meshserver.send({ action: 'traceinfo', traceSources: sources });
9160
}
9161
views/translations/default-min_fr.handlebars
+4
-2
@@ -8154,6 +8154,8 @@
8154
x += '<div><label><input type=checkbox id=p41c2 ' + ((serverTraceSources.indexOf('dispatch') >= 0) ? 'checked' : '') + '>' + "Message Dispatcher" + '</label></div>';
8155
x += '<div><label><input type=checkbox id=p41c3 ' + ((serverTraceSources.indexOf('main') >= 0) ? 'checked' : '') + '>' + "Main Server Messages" + '</label></div>';
8156
x += '<div><label><input type=checkbox id=p41c4 ' + ((serverTraceSources.indexOf('peer') >= 0) ? 'checked' : '') + '>' + "MeshCentral Server Peering" + '</label></div>';
8157
+ x += '<div><label><input type=checkbox id=p41c15 ' + ((serverTraceSources.indexOf('agent') >= 0) ? 'checked' : '') + '>' + "MeshAgent traffic" + '</label></div>';
8158
+ x += '<div><label><input type=checkbox id=p41c14 ' + ((serverTraceSources.indexOf('agentupdate') >= 0) ? 'checked' : '') + '>' + "MeshAgent update" + '</label></div>';
8159
x += '<div style="width:100%;border-bottom:1px solid gray;margin-bottom:5px;margin-top:5px"><b>' + "Serveur Web" + '</b></div>';
8160
x += '<div><label><input type=checkbox id=p41c5 ' + ((serverTraceSources.indexOf('web') >= 0) ? 'checked' : '') + '>' + "Serveur Web" + '</label></div>';
8161
x += '<div><label><input type=checkbox id=p41c6 ' + ((serverTraceSources.indexOf('webrequest') >= 0) ? 'checked' : '') + '>' + "Demandes de serveur Web" + '</label></div>';
@@ -8170,8 +8172,8 @@
8172
}
8173
8174
function setServerTracingEx(b) {
8173
- var sources = [], allsources = ['cookie', 'dispatch', 'main', 'peer', 'web', 'webrequest', 'relay', 'webrelaydata', 'webrelay', 'mps', 'mpscmd', 'swarm', 'swarmcmd'];
8174
- if (b == 1) { for (var i = 1; i < 13; i++) { try { if (Q('p41c' + i).checked) { sources.push(allsources[i - 1]); } } catch (ex) { } } }
8175
+ var sources = [], allsources = ['cookie', 'dispatch', 'main', 'peer', 'web', 'webrequest', 'relay', 'webrelaydata', 'webrelay', 'mps', 'mpscmd', 'swarm', 'swarmcmd', 'agentupdate', 'agent'];
8176
+ if (b == 1) { for (var i = 1; i < 16; i++) { try { if (Q('p41c' + i).checked) { sources.push(allsources[i - 1]); } } catch (ex) { } } }
8177
meshserver.send({ action: 'traceinfo', traceSources: sources });
8178
}
8179
views/translations/default_fr.handlebars
+4
-2
@@ -9134,6 +9134,8 @@
9134
x += '<div><label><input type=checkbox id=p41c2 ' + ((serverTraceSources.indexOf('dispatch') >= 0) ? 'checked' : '') + '>' + "Message Dispatcher" + '</label></div>';
9135
x += '<div><label><input type=checkbox id=p41c3 ' + ((serverTraceSources.indexOf('main') >= 0) ? 'checked' : '') + '>' + "Main Server Messages" + '</label></div>';
9136
x += '<div><label><input type=checkbox id=p41c4 ' + ((serverTraceSources.indexOf('peer') >= 0) ? 'checked' : '') + '>' + "MeshCentral Server Peering" + '</label></div>';
9137
+ x += '<div><label><input type=checkbox id=p41c15 ' + ((serverTraceSources.indexOf('agent') >= 0) ? 'checked' : '') + '>' + "MeshAgent traffic" + '</label></div>';
9138
+ x += '<div><label><input type=checkbox id=p41c14 ' + ((serverTraceSources.indexOf('agentupdate') >= 0) ? 'checked' : '') + '>' + "MeshAgent update" + '</label></div>';
9139
x += '<div style="width:100%;border-bottom:1px solid gray;margin-bottom:5px;margin-top:5px"><b>' + "Serveur Web" + '</b></div>';
9140
x += '<div><label><input type=checkbox id=p41c5 ' + ((serverTraceSources.indexOf('web') >= 0) ? 'checked' : '') + '>' + "Serveur Web" + '</label></div>';
9141
x += '<div><label><input type=checkbox id=p41c6 ' + ((serverTraceSources.indexOf('webrequest') >= 0) ? 'checked' : '') + '>' + "Demandes de serveur Web" + '</label></div>';
@@ -9150,8 +9152,8 @@
9152
}
9153
9154
function setServerTracingEx(b) {
9153
- var sources = [], allsources = ['cookie', 'dispatch', 'main', 'peer', 'web', 'webrequest', 'relay', 'webrelaydata', 'webrelay', 'mps', 'mpscmd', 'swarm', 'swarmcmd'];
9154
- if (b == 1) { for (var i = 1; i < 13; i++) { try { if (Q('p41c' + i).checked) { sources.push(allsources[i - 1]); } } catch (ex) { } } }
9155
+ var sources = [], allsources = ['cookie', 'dispatch', 'main', 'peer', 'web', 'webrequest', 'relay', 'webrelaydata', 'webrelay', 'mps', 'mpscmd', 'swarm', 'swarmcmd', 'agentupdate', 'agent'];
9156
+ if (b == 1) { for (var i = 1; i < 16; i++) { try { if (Q('p41c' + i).checked) { sources.push(allsources[i - 1]); } } catch (ex) { } } }
9157
meshserver.send({ action: 'traceinfo', traceSources: sources });
9158
}
9159