Skip to content

Commit 51af24a

Browse files
authored
Merge pull request #1697 from yatam-manasa/topic-performance
This is for logging the task id for the demo of elastalert
2 parents 6455feb + 49dc8dd commit 51af24a

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

server/app/engine/bots/scriptExecutor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ function executeScriptOnLocal(botsScriptDetails,auditTrail,userName,botHostDetai
208208
});
209209
request.post(options, function (err, res, body) {
210210
if (err) {
211-
logger.error(err);
211+
logger.error("Logging body"+JSON.stringify(body))
212+
logger.error("Error: ",err)
212213
var timestampEnded = new Date().getTime();
213214
logsDao.insertLog({
214215
referenceId: logsReferenceIds,

server/app/services/botService.js

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
364364
var botId = null;
365365
var botRemoteServerDetails = {};
366366
var bots = [];
367+
var taskId = null;
368+
var cryptoConfig = appConfig.cryptoSettings;
369+
var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password);
367370
logger.info("Entering WF");
368371
async.waterfall([
369372
function (next) {
@@ -372,13 +375,30 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
372375
function (botList, next) {
373376
bots = botList;
374377
logger.info("Got Bots " + JSON.stringify(bots));
378+
if(bots.length > 0) {
379+
if(bots[0].params){
380+
if(bot[0].params.data){
381+
if(bot[0].params.data.sysid){
382+
sysId = bot[0].params.data.sysid
383+
logger.info("Task ID",sysId)
384+
var decryptedTaskId = cryptography.decryptText(sysId, cryptoConfig.decryptionEncoding,
385+
cryptoConfig.encryptionEncoding);
386+
logger.info("Decrypted Task ID",decryptedTaskId)
387+
taskId = decryptedTaskId
388+
logger.info(taskId)
389+
}else{
390+
logger.info("Task ID does not exist")
391+
}
392+
}
393+
}
394+
}
375395
if (schedulerCallCheck)
376396
scheduledBots.getScheduledBotsByBotId(botsId, next);
377397
else next(null, []);
378398
},
379399
function (scheduledBots, next) {
380400
if (bots.length > 0) {
381-
logger.info("Got Bots " + JSON.stringify(scheduledBots));
401+
logger.info("task_id"+taskId+" Got Bots " + JSON.stringify(scheduledBots));
382402
botId = bots[0]._id;
383403
if (scheduledBots.length > 0) {
384404
//included check for params if empty.
@@ -393,31 +413,31 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
393413
//logger.info("Executing BOTs Deatails", bots[0].execution[0].os, bots[0].execution[0].type);
394414
masterUtil.getBotRemoteServerDetailByOrgId(bots[0].orgId, function (err, botServerDetails) {
395415
if (err) {
396-
logger.error("Error while fetching BOTs Server Details");
416+
logger.error("task_id"+taskId+" Error while fetching BOTs Server Details");
397417
callback(err, null);
398418
return;
399419

400420
} else if (botServerDetails !== null && botServerDetails.length > 0) {
401-
logger.info("Checking flag status--->", appConfig.enableBotExecuterOsCheck)
421+
logger.info("task_id"+taskId+" Checking flag status--->", appConfig.enableBotExecuterOsCheck)
402422
if (bots[0].type === 'blueprints') {
403423
botRemoteServerDetails.hostIP = botServerDetails[0].hostIP;
404424
botRemoteServerDetails.hostPort = botServerDetails[0].hostPort;
405425
} else {
406426
//As env variable will always be in string changed the check value to string
407427
if (appConfig.enableBotExecuterOsCheck === true || process.env.enableBotExecuterOsCheck === 'true') {
408-
logger.info("Inn OS check condition");
428+
logger.info("task_id"+taskId+" Inn OS check condition");
409429
executorOsTypeConditionCheck(botServerDetails, botRemoteServerDetails, bots);
410430
} else {
411431

412432
botRemoteServerDetails.hostIP = botServerDetails[0].hostIP;
413433
botRemoteServerDetails.hostPort = botServerDetails[0].hostPort;
414-
logger.info("Default Details as working without Multiple executor feature", botRemoteServerDetails.hostIP, botRemoteServerDetails.hostPort);
434+
logger.info("task_id"+taskId+" Default Details as working without Multiple executor feature", botRemoteServerDetails.hostIP, botRemoteServerDetails.hostPort);
415435
}
416436
}
417437
encryptedParam(reqBody, next);
418438
} else {
419439
var error = new Error();
420-
error.message = 'BOTs Remote Engine is not configured or not in running mode';
440+
error.message = 'task_id'+taskId+' BOTs Remote Engine is not configured or not in running mode';
421441
error.status = 403;
422442
//next(error, null);
423443
encryptedParam(reqBody, next);
@@ -428,7 +448,7 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
428448

429449
} else {
430450
var error = new Error();
431-
error.message = 'There is no record available in DB against BOT : ' + botsId;
451+
error.message = 'task_id'+taskId+' There is no record available in DB against BOT : ' + botsId;
432452
error.status = 403;
433453
next(error, null);
434454
}
@@ -440,15 +460,15 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
440460
if (reqBody.nodeIds) {
441461
botObj.params.nodeIds = reqBody.nodeIds;
442462
}
443-
logger.info("Updating bot details" + JSON.stringify(botObj));
463+
logger.info("task_id"+taskId+" Updating bot details" + JSON.stringify(botObj));
444464
botDao.updateBotsDetail(botId, botObj, next);
445465
},
446466
function (updateStatus, next) {
447467
botDao.getBotsById(botId, next);
448468
},
449469
function (botDetails, next) {
450470
if (botDetails.length > 0) {
451-
logger.info("Executor in parallel " + JSON.stringify(botDetails));
471+
logger.info("task_id"+taskId+" Executor in parallel " + JSON.stringify(botDetails));
452472
async.parallel({
453473
executor: function (callback) {
454474
async.waterfall([
@@ -549,17 +569,17 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
549569
}
550570
});
551571
} else {
552-
logger.info("No Botdetails found ");
572+
logger.info("task_id"+taskId+" No Botdetails found ");
553573
next(null, botDetails);
554574
}
555575
}
556576
], function (err, results) {
557577
if (err) {
558-
logger.error(err);
578+
logger.error("task_id"+taskId+" "+ err);
559579
callback(err, null);
560580
return;
561581
} else {
562-
logger.info("Completed Bot execution " + JSON.stringify(results));
582+
logger.info("task_id"+taskId+" Completed Bot execution " + JSON.stringify(results));
563583
callback(null, results);
564584
return;
565585
}

0 commit comments

Comments
 (0)