Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@
cellTemplate:'<div class="text-center"><i class="fa fa-info-circle cursor" title="More Info" ng-click="grid.appScope.historyLogs(row.entity)"></i></div>'},
{ name:'Start Time',field:'startedOn',cellTemplate:'<span title="{{row.entity.startedOn | timestampToLocaleTime}}">{{row.entity.startedOn | timestampToLocaleTime}}</span>', sort:{ direction: 'desc'}, cellTooltip: true},
{ name:'End Time',field:'endedOn',cellTemplate:'<span title="{{row.entity.endedOn | timestampToLocaleTime}}">{{row.entity.endedOn | timestampToLocaleTime}}</span>', cellTooltip: true},
{ name:'Execution Time',cellTemplate:'<span ng-if="row.entity.endedOn">{{grid.appScope.getExecutionTime(row.entity.endedOn,row.entity.startedOn)}} mins</span>'},
{ name:'Manual Time',cellTemplate: '<span>{{row.entity.auditTrailConfig.manualExecutionTime}} mins</span>', cellTooltip: true},
{ name:'Saved Time',cellTemplate:'<span ng-if="row.entity.status == \'success\'">{{grid.appScope.getSavedTime(row.entity.endedOn,row.entity.startedOn)}} mins</span>' +
{ name:'Execution Time (Mins)',cellTemplate:'<span ng-if="row.entity.endedOn">{{grid.appScope.getExecutionTime(row.entity.endedOn,row.entity.startedOn)}} </span>'},
{ name:'Manual Time (Mins)',cellTemplate: '<span>{{row.entity.auditTrailConfig.manualExecutionTime}} </span>', cellTooltip: true},
{ name:'Saved Time (Mins)',cellTemplate:'<span ng-if="row.entity.status == \'success\'">{{grid.appScope.getSavedTime(row.entity.endedOn,row.entity.startedOn)}} </span>' +
'<span ng-if="row.entity.status !== \'success\'" title="NA">NA</span>', cellTooltip: true}
];
bpcolumnDefs = chefGrid;
Expand All @@ -101,9 +101,9 @@
{ name:'Status',field:'status',cellTemplate:'<div class="{{row.entity.status.toUpperCase()}}">{{row.entity.status.toUpperCase()}}</div>'},
{ name:'Start Time',field:'startedOn',cellTemplate:'<span title="{{row.entity.startedOn | timestampToLocaleTime}}">{{row.entity.startedOn | timestampToLocaleTime}}</span>',cellTooltip: true},
{ name:'End Time',field:'endedOn',cellTemplate:'<span title="{{row.entity.endedOn | timestampToLocaleTime}}">{{row.entity.endedOn | timestampToLocaleTime}}</span>',cellTooltip: true},
{ name:'Execution Time',cellTemplate:'<span ng-if="row.entity.endedOn">{{grid.appScope.getExecutionTime(row.entity.endedOn,row.entity.startedOn)}} mins</span>'},
{ name:'Manual Time',cellTemplate: '<span>{{row.entity.auditTrailConfig.manualExecutionTime}} mins</span>', cellTooltip: true},
{ name:'Saved Time',cellTemplate:'<span ng-if="row.entity.status === \'success\'">{{grid.appScope.getSavedTime(row.entity.endedOn,row.entity.startedOn)}} mins</span>' +
{ name:'Execution Time (Mins)',cellTemplate:'<span ng-if="row.entity.endedOn">{{grid.appScope.getExecutionTime(row.entity.endedOn,row.entity.startedOn)}} </span>'},
{ name:'Manual Time (Mins)',cellTemplate: '<span>{{row.entity.auditTrailConfig.manualExecutionTime}} </span>', cellTooltip: true},
{ name:'Saved Time (Mins)',cellTemplate:'<span ng-if="row.entity.status === \'success\'">{{grid.appScope.getSavedTime(row.entity.endedOn,row.entity.startedOn)}} </span>' +
'<span ng-if="row.entity.status !== \'success\'" title="NA">NA</span>', cellTooltip: true}
];
bpcolumnDefs = jenkinsGrid;
Expand All @@ -115,9 +115,9 @@
cellTemplate:'<div class="text-center"><i class="fa fa-info-circle cursor" title="More Info" ng-click="grid.appScope.historyLogs(row.entity)"></i></div>'},
{ name:'Start Time',field:'startedOn',cellTemplate:'<span title="{{row.entity.startedOn | timestampToLocaleTime}}">{{row.entity.startedOn | timestampToLocaleTime}}</span>', sort:{ direction: 'desc'}, cellTooltip: true},
{ name:'End Time',field:'endedOn',cellTemplate:'<span title="{{row.entity.endedOn | timestampToLocaleTime}}">{{row.entity.endedOn | timestampToLocaleTime}}</span>', cellTooltip: true},
{ name:'Execution Time',cellTemplate:'<span ng-if="row.entity.endedOn">{{grid.appScope.getExecutionTime(row.entity.endedOn,row.entity.startedOn)}} mins</span>'},
{ name:'Manual Time',cellTemplate: '<span>{{row.entity.auditTrailConfig.manualExecutionTime}} mins</span>', cellTooltip: true},
{ name:'Saved Time',cellTemplate:'<span ng-if="row.entity.status === \'success\'">{{grid.appScope.getSavedTime(row.entity.endedOn,row.entity.startedOn)}} mins</span>' +
{ name:'Execution Time (Mins)',cellTemplate:'<span ng-if="row.entity.endedOn">{{grid.appScope.getExecutionTime(row.entity.endedOn,row.entity.startedOn)}} </span>'},
{ name:'Manual Time (Mins)',cellTemplate: '<span>{{row.entity.auditTrailConfig.manualExecutionTime}} </span>', cellTooltip: true},
{ name:'Saved Time (Mins)',cellTemplate:'<span ng-if="row.entity.status === \'success\'">{{grid.appScope.getSavedTime(row.entity.endedOn,row.entity.startedOn)}} </span>' +
'<span ng-if="row.entity.status !== \'success\'" title="NA">NA</span>', cellTooltip: true}
];
bpcolumnDefs = blueprintGrid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
//{ name: 'BOT Created From',displayName: 'BOT Created From',field:'botLinkedCategory',cellTooltip: true},
{ name: 'Organization',field:'masterDetails.orgName',cellTooltip: true},
{ name: 'Last Run',field:'lastRunTime ',cellTemplate:'<span title="{{row.entity.lastRunTime | timestampToLocaleTime}}">{{row.entity.lastRunTime | timestampToLocaleTime}}</span>', cellTooltip: true},
{ name: 'Saved Time(Mins)',field:'savedTime', cellTooltip: true},
{ name: 'Total Runs',field:'executionCount'},
{ name: 'BOT Action',width:200,displayName: 'BOT Action',cellTemplate:
'<a title="History"><i class="fa fa-header font-size-16 cursor" ng-click="grid.appScope.botHistory(row.entity);"></i></a>'+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</div>
<div class="circle-tile-content orange">
<div class="circle-tile-number text-faded ng-binding">
{{botSummary.totalSavedTimeForBots}} mins
{{botSummary.totalSavedTimeForBots.hours}}h {{botSummary.totalSavedTimeForBots.minutes}}m
</div>
<div class="circle-tile-description text-faded">
Time saved
Expand Down
4 changes: 4 additions & 0 deletions server/app/model/bots/1.0/bots.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var BotsSchema = new Schema ({
trim: true,
required: true
},
savedTime: {
type: Number,
default:0
},
botConfig:Schema.Types.Mixed,
runTimeParams:Schema.Types.Mixed,
masterDetails: {
Expand Down
17 changes: 10 additions & 7 deletions server/app/services/auditTrailService.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,18 @@ auditTrailService.getBOTsSummary = function getBOTsSummary(queryParam,BOTSchema,
} else if(botAuditTrail.length > 0){
var totalTimeInSeconds = 0;
for(var j = 0; j < botAuditTrail.length; j++){
(function(auditTrail){
if(auditTrail.endedOn && auditTrail.endedOn !== null
&& auditTrail.auditTrailConfig.manualExecutionTime && auditTrail.auditTrailConfig.manualExecutionTime !== null) {
var executionTime = getExecutionTime(auditTrail.endedOn, auditTrail.startedOn);
totalTimeInSeconds = totalTimeInSeconds + ((auditTrail.auditTrailConfig.manualExecutionTime*60) - executionTime);
if(botAuditTrail[j].endedOn && botAuditTrail[j].endedOn !== null
&& botAuditTrail[j].auditTrailConfig.manualExecutionTime && botAuditTrail[j].auditTrailConfig.manualExecutionTime !== null) {
var executionTime = getExecutionTime(botAuditTrail[j].endedOn, botAuditTrail[j].startedOn);
totalTimeInSeconds = totalTimeInSeconds + ((botAuditTrail[j].auditTrailConfig.manualExecutionTime*60) - executionTime);
}
})(botAuditTrail[j]);
}
callback(null,(totalTimeInSeconds/60).toFixed(2));
var totalTimeInMinutes = Math.round(totalTimeInSeconds/60);
var result = {
hours:Math.floor(totalTimeInMinutes / 60),
minutes:totalTimeInMinutes % 60
}
callback(null,result);
} else{
callback(null,botAuditTrail.length);
}
Expand Down
197 changes: 115 additions & 82 deletions server/app/services/botsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,88 +408,6 @@ botsService.executeBots = function executeBots(botId,reqBody,callback){
});
}

function filterScriptBotsData(data,callback){
var botsList = [];
var cryptoConfig = appConfig.cryptoSettings;
var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password);
if(data.docs.length === 0){
callback(null,data);
return;
}else {
for (var i = 0; i < data.docs.length; i++) {
(function (bots) {
if ((bots.botLinkedSubCategory === 'script')
&& ('scriptDetails' in bots.botConfig)
&& (bots.botConfig.scriptDetails.length > 0)) {
var scriptCount = 0;
for (var j = 0; j < bots.botConfig.scriptDetails.length; j++) {
(function (scriptBot) {
if (scriptBot.scriptParameters.length > 0) {
scriptCount++;
for (var k = 0; k < scriptBot.scriptParameters.length; k++) {
if (scriptBot.scriptParameters[k].paramType === '' || scriptBot.scriptParameters[k].paramType === 'Default' || scriptBot.scriptParameters[k].paramType === 'Password') {
scriptBot.scriptParameters[k].paramVal = cryptography.decryptText(scriptBot.scriptParameters[k].paramVal, cryptoConfig.decryptionEncoding,
cryptoConfig.encryptionEncoding);
} else {
scriptBot.scriptParameters[k].paramVal = '';
}
}
} else {
scriptCount++;
}
})(bots.botConfig.scriptDetails[j]);
}
if (scriptCount === bots.botConfig.scriptDetails.length) {
botsList.push(bots);
}
} else {
botsList.push(bots);
}
})(data.docs[i]);
if (botsList.length === data.docs.length) {
data.docs = botsList;
callback(null, data);
return;
}
}
}
}

function encryptedParam(paramDetails, callback) {
var cryptoConfig = appConfig.cryptoSettings;
var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password);
var count = 0;
var encryptedList = [];
for (var i = 0; i < paramDetails.length; i++) {
(function (paramDetail) {
if (paramDetail.scriptParameters.length > 0) {
count++;
for (var j = 0; j < paramDetail.scriptParameters.length; j++) {
(function (scriptParameter) {
var encryptedText = cryptography.encryptText(scriptParameter.paramVal, cryptoConfig.encryptionEncoding,
cryptoConfig.decryptionEncoding);
encryptedList.push({
paramVal: encryptedText,
paramDesc: scriptParameter.paramDesc,
paramType: scriptParameter.paramType
});
if (encryptedList.length === paramDetail.scriptParameters.length) {
paramDetail.scriptParameters = encryptedList;
encryptedList = [];
}
})(paramDetail.scriptParameters[j]);
}
} else {
count++;
}
if (count === paramDetails.length) {
callback(null, paramDetails);
return;
}
})(paramDetails[i]);
}
}

botsService.syncBotsWithGitHub = function syncBotsWithGitHub(gitHubId,callback){
async.waterfall([
function(next) {
Expand Down Expand Up @@ -561,5 +479,120 @@ botsService.syncBotsWithGitHub = function syncBotsWithGitHub(gitHubId,callback){
});
}

function filterScriptBotsData(data,callback){
var botsList = [];
var cryptoConfig = appConfig.cryptoSettings;
var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password);
if(data.docs.length === 0){
callback(null,data);
return;
}else {
for (var i = 0; i < data.docs.length; i++) {
(function (bots) {
if ((bots.botLinkedSubCategory === 'script')
&& ('scriptDetails' in bots.botConfig)
&& (bots.botConfig.scriptDetails.length > 0)) {
var scriptCount = 0;
for (var j = 0; j < bots.botConfig.scriptDetails.length; j++) {
(function (scriptBot) {
if (scriptBot.scriptParameters.length > 0) {
scriptCount++;
for (var k = 0; k < scriptBot.scriptParameters.length; k++) {
if (scriptBot.scriptParameters[k].paramType === '' || scriptBot.scriptParameters[k].paramType === 'Default' || scriptBot.scriptParameters[k].paramType === 'Password') {
scriptBot.scriptParameters[k].paramVal = cryptography.decryptText(scriptBot.scriptParameters[k].paramVal, cryptoConfig.decryptionEncoding,
cryptoConfig.encryptionEncoding);
} else {
scriptBot.scriptParameters[k].paramVal = '';
}
}
} else {
scriptCount++;
}
})(bots.botConfig.scriptDetails[j]);
}
if (scriptCount === bots.botConfig.scriptDetails.length) {
addSavedTimePerBots(bots.botId,function(err,savedTime) {
if (err) {
logger.error("Error in fetching Saved Time per bots ", err);
}
bots.savedTime = savedTime;
botsList.push(bots);
if (botsList.length === data.docs.length) {
data.docs = botsList;
callback(null, data);
return;
}
});
}
} else {
addSavedTimePerBots(bots.botId,function(err,savedTime) {
if (err) {
logger.error("Error in fetching Saved Time per bots ", err);
}
bots.savedTime = savedTime;
botsList.push(bots);
if (botsList.length === data.docs.length) {
data.docs = botsList;
callback(null, data);
return;
}
});
}
})(data.docs[i]);
}
}
}

function encryptedParam(paramDetails, callback) {
var cryptoConfig = appConfig.cryptoSettings;
var cryptography = new Cryptography(cryptoConfig.algorithm, cryptoConfig.password);
for (var i = 0; i < paramDetails.length; i++) {
if (paramDetails[i].scriptParameters.length > 0) {
for (var j = 0; j < paramDetails[i].scriptParameters.length; j++) {
var encryptedText = cryptography.encryptText(paramDetails[i].scriptParameters[j].paramVal, cryptoConfig.encryptionEncoding,
cryptoConfig.decryptionEncoding);
paramDetails[i].scriptParameters[j].paramVal = encryptedText;
}
}
}
callback(null, paramDetails)
return;
}

function getExecutionTime(endTime, startTime) {
var executionTimeInMS = endTime - startTime;
var totalSeconds = Math.floor(executionTimeInMS / 1000);
return totalSeconds;
}

function addSavedTimePerBots(botId, callback) {
var query = {
auditType: 'BOTs',
actionStatus: 'success',
isDeleted: false,
auditId: botId
};
auditTrail.getAuditTrails(query, function (err, botAuditTrail) {
if (err) {
logger.error("Error in Fetching Audit Trail.", err);
callback(err, null);
}
if (botAuditTrail.length > 0) {
var totalTimeInSeconds = 0;
for (var m = 0; m < botAuditTrail.length; m++) {
if (botAuditTrail[m].endedOn && botAuditTrail[m].endedOn !== null
&& botAuditTrail[m].auditTrailConfig.manualExecutionTime && botAuditTrail[m].auditTrailConfig.manualExecutionTime !== null) {
var executionTime = getExecutionTime(botAuditTrail[m].endedOn, botAuditTrail[m].startedOn);
totalTimeInSeconds = totalTimeInSeconds + ((botAuditTrail[m].auditTrailConfig.manualExecutionTime * 60) - executionTime);
}
}
callback(null, (totalTimeInSeconds / 60).toFixed(2));
} else {
callback(null, 0);
}
});
}