Skip to content

Commit

Permalink
#1410 Use StreamQuerySrv for alert stats (unread alerts and filtered …
Browse files Browse the repository at this point in the history
…alerts)
  • Loading branch information
nadouani committed Jul 23, 2020
1 parent b58d783 commit 52cb919
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
37 changes: 28 additions & 9 deletions frontend/app/scripts/controllers/RootCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ angular.module('theHiveControllers').controller('RootCtrl',
name: 'my-tasks.stats'
}
},
onUpdate: function(updates) {
$scope.myCurrentTasksCount = updates;
onUpdate: function(data) {
$scope.myCurrentTasksCount = data;
}
});

Expand All @@ -85,13 +85,28 @@ angular.module('theHiveControllers').controller('RootCtrl',
name: 'waiting-tasks.stats'
}
},
onUpdate: function(updates) {
$scope.waitingTasksCount = updates;
onUpdate: function(data) {
$scope.waitingTasksCount = data;
}
});

// Get Alert counts
$scope.alertEvents = AlertingSrv.stats($scope);
StreamQuerySrv('v1', [
{_name: 'listAlert'},
{_name: 'filter', _field: 'read', _value: false},
{_name: 'count'}
], {
scope: $scope,
rootId: 'any',
objectType: 'alert',
query: {
params: {
name: 'unread-alert-count'
}
},
onUpdate: function(data) {
$scope.unreadAlertCount = data;
}
});

$scope.$on('templates:refresh', function(){
CaseTemplateSrv.list().then(function(templates) {
Expand All @@ -104,9 +119,13 @@ angular.module('theHiveControllers').controller('RootCtrl',
$scope.initCustomFieldsCache();
});

$scope.$on('alert:event-imported', function() {
$scope.alertEvents = AlertingSrv.stats($scope);
});

// Get Alert counts
//$scope.alertEvents = AlertingSrv.stats($scope);

// $scope.$on('alert:event-imported', function() {
// $scope.alertEvents = AlertingSrv.stats($scope);
// });

// FIXME
// $scope.$on('misp:status-updated', function(event, enabled) {
Expand Down
19 changes: 18 additions & 1 deletion frontend/app/scripts/controllers/alert/AlertListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(function() {
'use strict';
angular.module('theHiveControllers')
.controller('AlertListCtrl', function($rootScope, $scope, $q, $state, $uibModal, TagSrv, CaseTemplateSrv, ModalUtilsSrv, AlertingSrv, NotificationSrv, FilteringSrv, CortexSrv, Severity, VersionSrv) {
.controller('AlertListCtrl', function($rootScope, $scope, $q, $state, $uibModal, TagSrv, StreamQuerySrv, CaseTemplateSrv, ModalUtilsSrv, AlertingSrv, NotificationSrv, FilteringSrv, CortexSrv, Severity, VersionSrv) {
var self = this;

self.urls = VersionSrv.mispUrls();
Expand Down Expand Up @@ -44,6 +44,23 @@
self.filtering.setPageSize(newValue);
});
});

StreamQuerySrv('v1', [
{_name: 'listAlert'},
{_name: 'count'}
], {
scope: $scope,
rootId: 'any',
objectType: 'alert',
query: {
params: {
name: 'alert-count'
}
},
onUpdate: function(data) {
self.alertListCount = data;
}
});
};

self.load = function() {
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/views/components/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
</li>
<li ui-sref-active="active">
<a ui-sref="app.main({viewId: 'mytasks'})">My tasks
<span class="badge alert-danger">{{myCurrentTasksCount}}</span>
<span class="badge alert-danger">{{myCurrentTasksCount || 0}}</span>
</a>
</li>
<li ui-sref-active="active">
<a ui-sref="app.main({viewId: 'waitingtasks'})">Waiting tasks
<span class="badge alert-danger">{{waitingTasksCount}}</span>
<span class="badge alert-danger">{{waitingTasksCount || 0}}</span>
</a>
</li>
<li ui-sref-active="active">
<a href ui-sref="app.alert-list">
Alerts
<span class="badge alert-danger">{{(alertEvents.New.count || 0) + (alertEvents.Updated.count || 0)}}</span>
<span class="badge alert-danger">{{unreadAlertCount || 0}}</span>
</a>
</li>
<li class="hdivider hidden-xs"></li>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/views/partials/alert/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="col-md-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">List of alerts ({{$vm.list.total || 0}} of {{alertEvents.count}})</h3>
<h3 class="box-title">List of alerts ({{$vm.list.total || 0}} of {{$vm.alertListCount}})</h3>
</div>
<div class="box-body">
<div ng-include="'views/partials/alert/list/toolbar.html'"></div>
Expand Down
7 changes: 0 additions & 7 deletions frontend/app/views/partials/alert/list/toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@
<span class="caret"></span>
</button>
<ul class="dropdown-menu" uib-dropdown-menu>
<!-- TODO nadouani: fix this filter -->
<!-- <li>
<a class="clickable" ng-click="$vm.filterByNewAndUpdated()">New & Updated events ({{(alertEvents.Updated.count || 0) + (alertEvents.New.count || 0)}})</a>
</li> -->
<!-- <li>
<a class="clickable" ng-click="$vm.filterByStatus(false)">New events ({{alertEvents.New.count || 0}})</a>
</li> -->
<li>
<a class="clickable" ng-click="$vm.filterBy('read', true)"><i class="fa fa-envelope-open-o"></i> Read events</a>
</li>
Expand Down

0 comments on commit 52cb919

Please sign in to comment.