Skip to content

Commit 68360b1

Browse files
C50-582
1 parent 670cdeb commit 68360b1

File tree

7 files changed

+119
-17
lines changed

7 files changed

+119
-17
lines changed

client/cat3/src/partials/sections/dashboard/bots/controller/libraryCtrl.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,17 @@
247247
if($scope.failedBotsselected)
248248
var param={
249249
inlineLoader:true,
250-
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&page=' + $scope.botServiceNowLibGridOptions.paginationCurrentPage +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=' + $scope.paginationParams.sortBy +'&sortOrder=' + $scope.paginationParams.sortOrder + '&filterBy=actionStatus:failed'
250+
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&page=' + $scope.botServiceNowLibGridOptions.paginationCurrentPage +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=' + $scope.paginationParams.sortBy +'&sortOrder=' + $scope.paginationParams.sortOrder + '&filterBy=actionStatus:failed' + '&auditForDashboard=true'
251251
};
252252
else if($scope.scheduledBotsSelected)
253253
var param={
254254
inlineLoader:true,
255-
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&filterBy=actionStatus:success&page=' + $scope.paginationParams.page +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=startedOn&sortOrder=' + $scope.paginationParams.sortOrder+'&type=snow'
255+
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&filterBy=actionStatus:success&page=' + $scope.paginationParams.page +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=startedOn&sortOrder=' + $scope.paginationParams.sortOrder+'&type=snow' + '&auditForDashboard=true'
256256
};
257257
else if($scope.runningBotsselected)
258258
var param={
259259
inlineLoader:true,
260-
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&page=' + $scope.botServiceNowLibGridOptions.paginationCurrentPage +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=startedOn&sortOrder=' + $scope.paginationParams.sortOrder
260+
url:'/audit-trail?startdate='+ $scope.ticketsResolveStartsOn+ '&enddate='+ $scope.ticketsResolveEndsOn +'&page=' + $scope.botServiceNowLibGridOptions.paginationCurrentPage +'&pageSize=' + $scope.paginationParams.pageSize +'&sortBy=startedOn&sortOrder=' + $scope.paginationParams.sortOrder + '&auditForDashboard=true'
261261
};
262262

263263
$scope.dataTransform(param);
@@ -333,6 +333,23 @@
333333
$scope.errorMessage = "No Records found";
334334
});
335335
$scope.isBotDetailsLoading = false;
336+
var param = {
337+
inlineLoader: true,
338+
url: '/git-hub'
339+
};
340+
genSevs.promiseGet(param).then(function (result) {
341+
$scope.pageLoadBot=false;
342+
for(var i=0;i<result.data.length;i++){
343+
if(result && result.data[i].isDefault == true){
344+
$scope.gitHubRepoName = result.data[i].repositoryName;
345+
}
346+
}
347+
}, function (error) {
348+
$scope.pageLoadBot=false;
349+
toastr.error(error);
350+
$scope.errorMessage = "No Records found";
351+
});
352+
$scope.isBotDetailsLoading = false;
336353
}
337354
$scope.botLibraryGridView = function () {
338355
$rootScope.onBodyLoading = false;

client/cat3/src/partials/sections/dashboard/bots/view/library.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<loading size="large" name="pageLoadBot" type="block" align="center"></loading>
33
<div id="botLibraryPage" ng-show="!pageLoadBot">
44
<div class="page-name">
5-
BOTs Library&nbsp;
5+
BOTs Library : {{gitHubRepoName}} &nbsp;
66
<!--<span class="label label-warning"><small>Time Saved: </small>{{botSummary.totalSavedTimeForBots.days ? botSummary.totalSavedTimeForBots.days:0}}d {{botSummary.totalSavedTimeForBots.hours ? botSummary.totalSavedTimeForBots.hours : 0}}h {{botSummary.totalSavedTimeForBots.minutes ? botSummary.totalSavedTimeForBots.minutes : 0}}m</span>-->
77
<span class="pull-right">
88
<button type="button" title="Refresh" class="btn btn-xs cat-btn-update pull-right refresh-btn" ng-click="RefreshBotsLibrary();">
@@ -316,7 +316,7 @@ <h4 class="margintop-2"><small>{{statusBar}}</small></h4>
316316
ng-show="noShowForServiceNow">
317317
<div class="alert alert-info text-center no-data"
318318
ng-if="!botLibGridOptions.data.length > 0 && !isBotLibraryPageLoading">
319-
No data Available
319+
No BOTs available. Check if your BOT repository is synchronised
320320
</div>
321321
<div id="grid1"
322322
ng-show="!isCardViewActive"

server/app/engine/bots/scriptExecutor.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ scriptExecutor.execute = function execute(botsDetails,auditTrail,userName,execut
8383
botID: botDetails.id,
8484
user: userName,
8585
date: startHour,
86+
gitHubId: botDetails.gitHubId
8687
}, { $inc: { "failedCount": 1, "runningCount": -1} }, function (err, data) {
8788
if(err) logger.error(JSON.stringify(err))
8889
else logger.info("Running count of bot ", botDetails[0].name, "incremented successfully")
@@ -245,6 +246,7 @@ function executeScriptOnLocal(botsScriptDetails,auditTrail,userName,botHostDetai
245246
botID: botsScriptDetails.id,
246247
user: userName,
247248
date: startHour,
249+
gitHubId: botsScriptDetails.gitHubId
248250
}, { $inc: { "failedCount": 1, "runningCount": -1} }, function (err, data) {
249251
if(err) logger.error(JSON.stringify(err))
250252
else logger.info("Running count of bot ", botDetails[0].name, "incremented successfully")
@@ -307,6 +309,7 @@ function executeScriptOnLocal(botsScriptDetails,auditTrail,userName,botHostDetai
307309
botID: botsScriptDetails.id,
308310
user: userName,
309311
date: startHour,
312+
gitHubId: botsScriptDetails.gitHubId
310313
}, { $inc: { "failedCount": 1, "runningCount": -1} }, function (err, data) {
311314
if(err) logger.error(JSON.stringify(err))
312315
else logger.info("Running count of bot ", botsScriptDetails[0].name, "incremented successfully")
@@ -459,6 +462,7 @@ function executeScriptOnRemote(instance,botDetails,actionLogId,auditTrailId,user
459462
botID: botDetails.id,
460463
user: userName,
461464
date: startHour,
465+
gitHubId: botDetails.gitHubId
462466
}, { $inc: { "failedCount": 1, "runningCount": -1} }, function (err, data) {
463467
if(err) logger.error(JSON.stringify(err))
464468
else logger.info("Running count of bot ", botDetails[0].name, "incremented successfully")
@@ -534,6 +538,7 @@ function executeScriptOnRemote(instance,botDetails,actionLogId,auditTrailId,user
534538
botID: botDetails.id,
535539
user: userName,
536540
date: startHour,
541+
gitHubId: botDetails.gitHubId
537542
}, { $inc: { "failedCount": 1, "runningCount": -1} }, function (err, data) {
538543
if(err) logger.error(JSON.stringify(err))
539544
else logger.info("Running count of bot ", botDetails[0].name, "incremented successfully")

server/app/model/audit-trail/base-audit-trail.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ var AuditTrailSchema = function AuditTrail() {
125125
isDeleted: {
126126
type: Boolean,
127127
default:false
128+
},
129+
gitHubId: {
130+
type: String,
131+
required:true
128132
}
129133
});
130134
};

server/app/model/audit-trail/bot-audit-trail-summary.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ var BotAuditTrailSummarySchema= new Schema ({
5050
type: Number,
5151
default: 0
5252
},
53+
gitHubId: {
54+
type: String,
55+
required: true
56+
}
5357
})
5458

5559
BotAuditTrailSummarySchema.index({ user: 1, botID: 1, date:1}, { unique: true });

server/app/services/auditTrailService.js

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ auditTrailService.insertAuditTrail = function insertAuditTrail(auditDetails,audi
5656
user: actionObj.catUser,
5757
startedOn: new Date().getTime(),
5858
providerType: auditDetails.providerType,
59-
action: actionObj.action
59+
action: actionObj.action,
60+
gitHubId: auditDetails.gitHubId
6061
};
6162
if(actionObj.auditType === 'BOTOLD' || actionObj.auditType === 'BOT'){
6263
auditTrailObj.auditTrailConfig = auditTrailConfig;
@@ -663,8 +664,40 @@ auditTrailService.getAuditTrail = function getAuditTrail(query, callback) {
663664
if(query.type && query.type=='snow'){
664665
queryObj.queryObj['$and'].push({auditId:{$in:snowbotsids}})
665666
}
666-
667-
auditTrail.getAuditTrailList(queryObj, next);
667+
if(query.auditForDashboard=="true" && query.type=='snow'){
668+
var gitHubQuery = {
669+
"isDefault": 'true'
670+
};
671+
gitHubModel.getGitRepository(gitHubQuery, '', (err, res) => {
672+
if (!err && res.length>0) {
673+
queryObj.queryObj['$and'].push({gitHubId: res[0]._id.toString()})
674+
auditTrail.getAuditTrailList(queryObj, next);
675+
}
676+
else {
677+
logger.error("Default Github account not found for bot summary");
678+
queryObj.queryObj['$and'].push({gitHubId: ''})
679+
auditTrail.getAuditTrailList(queryObj, next);
680+
}
681+
});
682+
}
683+
if(query.auditForDashboard=="true"){
684+
var gitHubQuery = {
685+
"isDefault": 'true'
686+
};
687+
gitHubModel.getGitRepository(gitHubQuery, '', (err, res) => {
688+
if (!err && res.length>0) {
689+
queryObj.queryObj['$and'].push({gitHubId: res[0]._id.toString()})
690+
auditTrail.getAuditTrailList(queryObj, next);
691+
}
692+
else {
693+
logger.error("Default Github account not found for bot summary");
694+
queryObj.queryObj['$and'].push({gitHubId: ''})
695+
auditTrail.getAuditTrailList(queryObj, next);
696+
}
697+
});
698+
}else{
699+
auditTrail.getAuditTrailList(queryObj, next);
700+
}
668701
},
669702
function(auditTrailList, next) {
670703
apiUtil.paginationResponse(auditTrailList, reqData, next);
@@ -1143,7 +1176,23 @@ auditTrailService.getBotSummary = function getBotSummary(queryParam, BOTSchema,
11431176
})
11441177
}
11451178
},
1146-
function(botsList, next) {
1179+
function(botsList, next){
1180+
var gitHubquery = {
1181+
"isDefault": 'true'
1182+
};
1183+
var gitHubIdData;
1184+
gitHubModel.getGitRepository(gitHubquery, '', (err, res) => {
1185+
if (!err && res.length>0) {
1186+
gitHubIdData = res[0]._id.toString();
1187+
next(null, botsList, gitHubIdData);
1188+
}
1189+
else {
1190+
logger.error("Default Github account not found for bot summary");
1191+
next(null, botsList, '');
1192+
}
1193+
});
1194+
},
1195+
function(botsList, gitHubIdData, next) {
11471196
var totalBots = botsList.length;
11481197
var botIdList = [];
11491198
var snowBotId = [];
@@ -1174,9 +1223,10 @@ auditTrailService.getBotSummary = function getBotSummary(queryParam, BOTSchema,
11741223
querymatch['date']={$gte:sdt,$lte:edt}
11751224
snowQueryMatch['date']={$gte:sdt,$lte:edt}
11761225
}
1177-
querymatch["botID"]={"$in":botIdList};
1226+
querymatch["botID"]={"$in":botIdList};
11781227
snowQueryMatch["botID"]={"$in":snowBotId};
1179-
1228+
snowQueryMatch["gitHubId"]=gitHubIdData;
1229+
querymatch["gitHubId"] = gitHubIdData;
11801230
query.push({$match:querymatch})
11811231
snowQuery.push({$match:snowQueryMatch})
11821232
query.push({
@@ -1377,3 +1427,24 @@ function convertMS( milliseconds ) {
13771427
seconds: seconds
13781428
};
13791429
}
1430+
1431+
function getDefaultGithub(callback){
1432+
var gitHubquery = {
1433+
"isDefault": 'true'
1434+
};
1435+
var gitHubIdData;
1436+
gitHubModel.getGitRepository(gitHubquery, '', (err, res) => {
1437+
if (!err && res.length>0) {
1438+
gitHubIdData = res[0]._id.toString();
1439+
logger.info("GITHUBIDD", gitHubIdData.toString());
1440+
//querymatch["gitHubId"] = gitHubIdData.toString();
1441+
//callback(null, gitHubIdData);
1442+
//return gitHubIdData.toString()
1443+
//query["gitHubId"] = gitHubIdData.toString();
1444+
//filterQuery['gitHubId'] = res[0]._id;
1445+
}
1446+
else {
1447+
logger.error("Default Github account not found for bot summary");
1448+
}
1449+
});
1450+
}

server/app/services/botService.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ botService.executeBots = function executeBots(botsId, reqBody, userName, executi
500500
botID: botDetails[0].id,
501501
user: userName,
502502
date: startHour,
503+
gitHubId: botDetails[0].gitHubId
503504
}, { $inc: { "runningCount": 1 } }, { upsert: true }, function (err, data) {
504505
if (err) logger.error(JSON.stringify(err))
505506
else logger.info("Running count of bot ", botDetails[0].name, "incremented successfully")
@@ -822,7 +823,7 @@ botService.syncBotsWithGitHub = function syncBotsWithGitHub(gitHubId, callback)
822823
logger.error("Error in removing YAML File. ", err);
823824
}
824825
if (runbookObjList.length === runbookFiles.length) {
825-
next(null, runbookObjList);
826+
//next(null, runbookObjList);
826827
return;
827828
}
828829
});
@@ -838,7 +839,7 @@ botService.syncBotsWithGitHub = function syncBotsWithGitHub(gitHubId, callback)
838839
logger.error(err);
839840
runbookObjList.push(err);
840841
if (runbookObjList.length === runbookFiles.length) {
841-
next(null, runbookObjList);
842+
//next(null, runbookObjList);
842843
return;
843844
}
844845
} else if (runbookList.length > 0) {
@@ -848,7 +849,7 @@ botService.syncBotsWithGitHub = function syncBotsWithGitHub(gitHubId, callback)
848849
}
849850
runbookObjList.push(runbookObj);
850851
if (runbookObjList.length === runbookFiles.length) {
851-
next(null, runbookObjList);
852+
//next(null, runbookObjList);
852853
return;
853854
}
854855
})
@@ -859,7 +860,7 @@ botService.syncBotsWithGitHub = function syncBotsWithGitHub(gitHubId, callback)
859860
}
860861
runbookObjList.push(runbookObj);
861862
if (runbookObjList.length === runbookFiles.length) {
862-
next(null, runbookObjList);
863+
//next(null, runbookObjList);
863864
return;
864865
}
865866
});
@@ -870,7 +871,7 @@ botService.syncBotsWithGitHub = function syncBotsWithGitHub(gitHubId, callback)
870871
} else {
871872
runbookObjList.push(result);
872873
if (runbookObjList.length === runbookFiles.length) {
873-
next(null, runbookObjList);
874+
//next(null, runbookObjList);
874875
return;
875876
}
876877
}
@@ -1027,7 +1028,7 @@ botService.syncBotsWithGitHub = function syncBotsWithGitHub(gitHubId, callback)
10271028
})
10281029
}
10291030
})
1030-
1031+
10311032
})(botsList[i]);
10321033
}
10331034
} else {

0 commit comments

Comments
 (0)