Skip to content

Commit 31f373b

Browse files
authored
Merge pull request #1700 from yatam-manasa/topic-performance
This is for logging task ID in bot execution for elastalert demo
2 parents 5cf6a95 + 075c79d commit 31f373b

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

server/app/engine/bots/scriptExecutor.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,21 @@ scriptExecutor.execute = function execute(botsDetails,auditTrail,userName,execut
121121

122122

123123
function executeScriptOnLocal(botsScriptDetails,auditTrail,userName,botHostDetails,callback) {
124+
logger.info("Bot script details",JSON.stringify(botsScriptDetails))
124125
var cryptoConfig = appConfig.cryptoSettings;
125126
var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password);
127+
var taskId = 'xxxxxx';
128+
if (botsScriptDetails.params){
129+
if(botsScriptDetails.params.data){
130+
if(botsScriptDetails.params.data.sysid){
131+
sysId = botsScriptDetails.params.data.sysid
132+
var decryptedText = cryptography.decryptText(sysId, cryptoConfig.decryptionEncoding,
133+
cryptoConfig.encryptionEncoding);
134+
taskId = decryptedText
135+
logger.info("Task ID",taskId)
136+
}
137+
}
138+
}
126139
var actionId = uuid.v4();
127140
var logsReferenceIds = [botsScriptDetails.id, actionId];
128141
var replaceTextObj = {
@@ -208,7 +221,8 @@ function executeScriptOnLocal(botsScriptDetails,auditTrail,userName,botHostDetai
208221
});
209222
request.post(options, function (err, res, body) {
210223
if (err) {
211-
logger.error(err);
224+
logger.error("task_id"+taskId+" "+JSON.stringify(err))
225+
logger.error("Error: task_id"+taskId+" Configure appropriate bot executor with proper osType ")
212226
var timestampEnded = new Date().getTime();
213227
logsDao.insertLog({
214228
referenceId: logsReferenceIds,

server/app/services/botService.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,16 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
364364
var botId = null;
365365
var botRemoteServerDetails = {};
366366
var bots = [];
367+
var taskId = 'xxxxxx';
368+
var cryptoConfig = appConfig.cryptoSettings;
369+
var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password);
367370
logger.info("Entering WF");
371+
if (reqBody.data){
372+
if(reqBody.data.sysid){
373+
logger.info("SYS ID",reqBody.data.sysid)
374+
taskId = reqBody.data.sysid
375+
}
376+
}
368377
async.waterfall([
369378
function (next) {
370379
botDao.getBotsByBotId(botsId, next);
@@ -417,6 +426,7 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
417426
encryptedParam(reqBody, next);
418427
} else {
419428
var error = new Error();
429+
logger.error("task_id"+taskId+" BOTs Remote Engine is not configured or not in running mode")
420430
error.message = 'BOTs Remote Engine is not configured or not in running mode';
421431
error.status = 403;
422432
//next(error, null);
@@ -428,6 +438,7 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
428438

429439
} else {
430440
var error = new Error();
441+
logger.error("task_id"+taskId+" There is no record available in DB against BOT :"+botsId)
431442
error.message = 'There is no record available in DB against BOT : ' + botsId;
432443
error.status = 403;
433444
next(error, null);
@@ -487,7 +498,7 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
487498
date: startHour,
488499
}, { $inc: { "runningCount": 1 } }, { upsert: true }, function (err, data) {
489500
if (err) logger.error(JSON.stringify(err))
490-
else logger.info("Running count of bot ", botDetails[0].name, "incremented successfully")
501+
else logger.info("task_id"+taskId+" Running count of bot ", botDetails[0].name, "incremented successfully")
491502
})
492503
auditTrailService.insertAuditTrail(botDetails[0], auditTrailObj, actionObj, next);
493504
},
@@ -536,6 +547,7 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
536547
botDao.updateBotsDetail(botId, botUpdateObj, callback);
537548
} else {
538549
var err = new Error('Invalid BOT Type');
550+
logger.error("task_id"+taskId+" Invalid BOT Type")
539551
err.status = 400;
540552
err.msg = 'Invalid BOT Type';
541553
callback(err, null);

0 commit comments

Comments
 (0)