From 88245f58ac5eb5a4f2b1075581237133213a5792 Mon Sep 17 00:00:00 2001 From: Nabil Adouani Date: Fri, 9 Jun 2017 17:11:26 +0200 Subject: [PATCH] #175 #232 Update alert similarity dialog and allow updating alert case template during import --- .../controllers/alert/AlertEventCtrl.js | 57 +++++++++++++++- .../controllers/alert/AlertListCtrl.js | 7 +- ui/app/scripts/services/AlertingSrv.js | 4 +- ui/app/views/partials/alert/event.dialog.html | 65 ++++++++++++++----- .../partials/alert/event.similarity.html | 14 +++- 5 files changed, 124 insertions(+), 23 deletions(-) diff --git a/ui/app/scripts/controllers/alert/AlertEventCtrl.js b/ui/app/scripts/controllers/alert/AlertEventCtrl.js index 38761571eb..a97e50ea75 100644 --- a/ui/app/scripts/controllers/alert/AlertEventCtrl.js +++ b/ui/app/scripts/controllers/alert/AlertEventCtrl.js @@ -1,10 +1,11 @@ (function() { 'use strict'; angular.module('theHiveControllers') - .controller('AlertEventCtrl', function($scope, $rootScope, $state, $uibModalInstance, CaseResolutionStatus, AlertingSrv, NotificationSrv, event) { + .controller('AlertEventCtrl', function($scope, $rootScope, $state, $uibModalInstance, CaseResolutionStatus, AlertingSrv, NotificationSrv, event, templates) { var self = this; var eventId = event.id; + self.templates = _.pluck(templates, 'name'); self.CaseResolutionStatus = CaseResolutionStatus; self.event = event; @@ -18,6 +19,11 @@ }; self.filteredArtifacts = []; + self.similarityFilters = {}; + self.similaritySorts = ['-startDate', '-similarArtifactCount', '-similarIocCount', '-iocCount']; + self.currentSimilarFilter = ''; + self.similarCasesStats = []; + this.filterArtifacts = function(value) { self.pagination.currentPage = 1; this.pagination.filter= value; @@ -44,6 +50,7 @@ AlertingSrv.get(eventId).then(function(response) { self.event = response.data; self.loading = false; + self.initSimilarCasesFilter(self.event.similarCases); self.dataTypes = _.countBy(self.event.artifacts, function(attr) { return attr.dataType; @@ -59,7 +66,9 @@ self.import = function() { self.loading = true; - AlertingSrv.create(self.event.id).then(function(response) { + AlertingSrv.create(self.event.id, { + caseTemplate: self.event.caseTemplate + }).then(function(response) { $uibModalInstance.dismiss(); $rootScope.$broadcast('alert:event-imported'); @@ -112,6 +121,50 @@ $uibModalInstance.dismiss(); }; + self.initSimilarCasesFilter = function(data) { + var stats = { + 'Open': 0 + }; + + // Init the stats object + _.each(_.without(_.keys(CaseResolutionStatus), 'Duplicated'), function(key) { + stats[key] = 0 + }); + + _.each(data, function(item) { + if(item.status === 'Open') { + stats[item.status] = stats[item.status] + 1; + } else { + stats[item.resolutionStatus] = stats[item.resolutionStatus] + 1; + } + }); + + var result = []; + _.each(_.keys(stats), function(key) { + result.push({ + key: key, + value: stats[key] + }) + }); + + self.similarCasesStats = result; + }; + + self.filterSimilarCases = function(filter) { + self.currentSimilarFilter = filter; + if(filter === '') { + self.similarityFilters = {}; + } else if(filter === 'Open') { + self.similarityFilters = { + status: filter + }; + } else { + self.similarityFilters = { + resolutionStatus: filter + }; + } + }; + self.load(); }); })(); diff --git a/ui/app/scripts/controllers/alert/AlertListCtrl.js b/ui/app/scripts/controllers/alert/AlertListCtrl.js index fa8f448a2a..bb047aa2fa 100644 --- a/ui/app/scripts/controllers/alert/AlertListCtrl.js +++ b/ui/app/scripts/controllers/alert/AlertListCtrl.js @@ -1,7 +1,7 @@ (function() { 'use strict'; angular.module('theHiveControllers') - .controller('AlertListCtrl', function($scope, $q, $state, $uibModal, AlertingSrv, NotificationSrv, FilteringSrv, Severity) { + .controller('AlertListCtrl', function($scope, $q, $state, $uibModal, TemplateSrv, AlertingSrv, NotificationSrv, FilteringSrv, Severity) { var self = this; self.list = []; @@ -190,7 +190,10 @@ controllerAs: 'dialog', size: 'max', resolve: { - event: event + event: event, + templates: function() { + return TemplateSrv.query().$promise; + } } }); }; diff --git a/ui/app/scripts/services/AlertingSrv.js b/ui/app/scripts/services/AlertingSrv.js index 23f0d27dae..828956f0db 100644 --- a/ui/app/scripts/services/AlertingSrv.js +++ b/ui/app/scripts/services/AlertingSrv.js @@ -26,8 +26,8 @@ }); }, - create: function(alertId) { - return $http.post(baseUrl + '/' + alertId + '/createCase', {}); + create: function(alertId, data) { + return $http.post(baseUrl + '/' + alertId + '/createCase', data || {}); }, canMarkAsRead: function(event) { diff --git a/ui/app/views/partials/alert/event.dialog.html b/ui/app/views/partials/alert/event.dialog.html index 1e2910b71b..8df26bde79 100644 --- a/ui/app/views/partials/alert/event.dialog.html +++ b/ui/app/views/partials/alert/event.dialog.html @@ -49,18 +49,6 @@

-
-
-

- Similar cases ({{dialog.event.similarCases.length}}) -

- -
-
-
-

Observables ({{dialog.event.artifacts.length || 0}}) @@ -102,29 +90,74 @@

ng-model="dialog.pagination.currentPage">

+ +
+
+

+ Similar cases ({{dialog.event.similarCases.length}}) +

+ +
+
+
diff --git a/ui/app/views/partials/alert/event.similarity.html b/ui/app/views/partials/alert/event.similarity.html index 1729daddb4..23810272a1 100644 --- a/ui/app/views/partials/alert/event.similarity.html +++ b/ui/app/views/partials/alert/event.similarity.html @@ -1,3 +1,15 @@ +
+ All ({{dialog.event.similarCases.length || 0}}) + + {{dialog.CaseResolutionStatus[statsItem.key] || statsItem.key}} ({{statsItem.value}}) +
+
Title
Date
@@ -5,7 +17,7 @@
IOCs
-
+