Skip to content

Commit 3f0ea00

Browse files
committed
This is for adding Task ID in logging for demo of elastalert
1 parent 49dc8dd commit 3f0ea00

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

server/app/engine/bots/scriptExecutor.js

Lines changed: 15 additions & 2 deletions
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,8 +221,8 @@ function executeScriptOnLocal(botsScriptDetails,auditTrail,userName,botHostDetai
208221
});
209222
request.post(options, function (err, res, body) {
210223
if (err) {
211-
logger.error("Logging body"+JSON.stringify(body))
212-
logger.error("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 ")
213226
var timestampEnded = new Date().getTime();
214227
logsDao.insertLog({
215228
referenceId: logsReferenceIds,

server/app/services/botService.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -364,34 +364,23 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
364364
var botId = null;
365365
var botRemoteServerDetails = {};
366366
var bots = [];
367-
var taskId = null;
367+
var taskId = 'xxxxxx';
368368
var cryptoConfig = appConfig.cryptoSettings;
369369
var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password);
370370
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+
}
371377
async.waterfall([
372378
function (next) {
373379
botDao.getBotsByBotId(botsId, next);
374380
},
375381
function (botList, next) {
376382
bots = botList;
377383
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-
}
395384
if (schedulerCallCheck)
396385
scheduledBots.getScheduledBotsByBotId(botsId, next);
397386
else next(null, []);
@@ -437,7 +426,8 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
437426
encryptedParam(reqBody, next);
438427
} else {
439428
var error = new Error();
440-
error.message = 'task_id'+taskId+' BOTs Remote Engine is not configured or not in running mode';
429+
logger.error("task_id"+taskId+" BOTs Remote Engine is not configured or not in running mode")
430+
error.message = 'BOTs Remote Engine is not configured or not in running mode';
441431
error.status = 403;
442432
//next(error, null);
443433
encryptedParam(reqBody, next);
@@ -448,7 +438,8 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
448438

449439
} else {
450440
var error = new Error();
451-
error.message = 'task_id'+taskId+' There is no record available in DB against BOT : ' + botsId;
441+
logger.error("task_id"+taskId+" There is no record available in DB against BOT :"+botsId)
442+
error.message = 'There is no record available in DB against BOT : ' + botsId;
452443
error.status = 403;
453444
next(error, null);
454445
}
@@ -507,7 +498,7 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
507498
date: startHour,
508499
}, { $inc: { "runningCount": 1 } }, { upsert: true }, function (err, data) {
509500
if (err) logger.error(JSON.stringify(err))
510-
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")
511502
})
512503
auditTrailService.insertAuditTrail(botDetails[0], auditTrailObj, actionObj, next);
513504
},
@@ -556,6 +547,7 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
556547
botDao.updateBotsDetail(botId, botUpdateObj, callback);
557548
} else {
558549
var err = new Error('Invalid BOT Type');
550+
logger.error("task_id"+taskId+" Invalid BOT Type")
559551
err.status = 400;
560552
err.msg = 'Invalid BOT Type';
561553
callback(err, null);

0 commit comments

Comments
 (0)