From 0ee2f94300826e06da03231b84769fcda505ce24 Mon Sep 17 00:00:00 2001 From: Nabil Adouani Date: Fri, 23 Jul 2021 16:29:25 +0200 Subject: [PATCH] #2144 Add action to drop and rebuild data index --- .../admin/platform/PlatformStatusCtrl.js | 208 ++++++++++-------- .../app/scripts/services/api/PlatformSrv.js | 20 +- .../views/partials/admin/platform/status.html | 20 +- .../thp/thehive/controllers/v1/Router.scala | 2 +- 4 files changed, 141 insertions(+), 109 deletions(-) diff --git a/frontend/app/scripts/controllers/admin/platform/PlatformStatusCtrl.js b/frontend/app/scripts/controllers/admin/platform/PlatformStatusCtrl.js index 3718916b33..a0ed8a01b8 100644 --- a/frontend/app/scripts/controllers/admin/platform/PlatformStatusCtrl.js +++ b/frontend/app/scripts/controllers/admin/platform/PlatformStatusCtrl.js @@ -1,107 +1,131 @@ -(function() { +(function () { 'use strict'; - angular.module('theHiveControllers').controller('PlatformStatusCtrl', function(ModalSrv, PlatformSrv, NotificationSrv, appConfig) { - var self = this; + angular.module('theHiveControllers').controller('PlatformStatusCtrl', function (ModalSrv, PlatformSrv, NotificationSrv, appConfig) { + var self = this; - self.appConfig = appConfig; - self.indexStatus = {}; - self.checkStats = {}; - - self.loading = { - index: false, - check: false - } - - this.loadIndexStatus = function() { - self.indexStatus = {}; - self.loading.index = true; - - PlatformSrv.getIndexStatus() - .then(function(response) { - self.indexStatus = response.data; - self.loading.index = false; - }); - } + self.appConfig = appConfig; + self.indexStatus = {}; + self.checkStats = {}; - this.loadCheckStats = function() { - self.loading.check = true; + self.loading = { + index: false, + check: false + } - PlatformSrv.getCheckStats() - .then(function(response) { - self.checkStats = response.data; - self.loading.check = false; - }) - } + this.loadIndexStatus = function () { + self.indexStatus = {}; + self.loading.index = true; - this.$onInit = function() { - self.loadIndexStatus(); - self.loadCheckStats(); + PlatformSrv.getIndexStatus() + .then(function (response) { + self.indexStatus = response.data; + self.loading.index = false; + }); + } + + this.loadCheckStats = function () { + self.loading.check = true; + + PlatformSrv.getCheckStats() + .then(function (response) { + self.checkStats = response.data; + self.loading.check = false; + }) + } + + this.$onInit = function () { + self.loadIndexStatus(); + self.loadCheckStats(); + }; + + this.exportReport = function () { + var date = new moment().format('YYYYMMDD-HH:mmZ'); + var fileName = 'Platform-Status-Report-' + date + '.json'; + + var content = { + indexStatus: self.indexStatus, + checkStatus: self.checkStats, + schemaStatus: self.appConfig.schemaStatus }; - this.exportReport = function() { - var date = new moment().format('YYYYMMDD-HH:mmZ'); - var fileName = 'Platform-Status-Report-'+date+'.json'; - - var content = { - indexStatus: self.indexStatus, - checkStatus: self.checkStats, - schemaStatus: self.appConfig.schemaStatus - }; - - // Create a blob of the data - var fileToSave = new Blob([JSON.stringify(content)], { - type: 'application/json', - name: fileName + // Create a blob of the data + var fileToSave = new Blob([JSON.stringify(content)], { + type: 'application/json', + name: fileName + }); + + // Save the file + saveAs(fileToSave, fileName); + } + + this.reindex = function (indexName) { + var modalInstance = ModalSrv.confirm( + 'Reindex', + 'Are you sure you want to trigger ' + indexName + ' data reindex', { + okText: 'Yes, reindex it' + } + ); + + modalInstance.result + .then(function () { + PlatformSrv.runReindex(indexName); + }) + .then(function (/*response*/) { + NotificationSrv.success('Reindexing of ' + indexName + ' data started sucessfully'); + }) + .catch(function (err) { + if (!_.isString(err)) { + NotificationSrv.error('Platform status', err.data, err.status); + } }); - - // Save the file - saveAs(fileToSave, fileName); + }; + + this.rebuildIndex = function (indexName) { + var modalInstance = ModalSrv.confirm( + 'Drop & Rebuild Index', + 'Are you sure you want to delete and rebuild ' + indexName + ' data reindex. ' + + 'This operation will drop your existing data index and create a new one.', { + okText: 'Yes, rebuild it', + flavor: 'danger' } - - this.reindex = function(indexName) { - var modalInstance = ModalSrv.confirm( - 'Reindex', - 'Are you sure you want to trigger ' + indexName + ' data reindex', { - okText: 'Yes, reindex it' + ); + + modalInstance.result + .then(function () { + PlatformSrv.runRebuildIndex(indexName); + }) + .then(function (/*response*/) { + NotificationSrv.success('Rebuild of ' + indexName + ' data started sucessfully'); + }) + .catch(function (err) { + if (!_.isString(err)) { + NotificationSrv.error('Platform status', err.data, err.status); } - ); - - modalInstance.result - .then(function() { - PlatformSrv.runReindex(indexName); - }) - .then(function(/*response*/) { - NotificationSrv.success('Reindexing of ' + indexName + ' data started sucessfully'); - }) - .catch(function(err) { - if (!_.isString(err)) { - NotificationSrv.error('Platform status', err.data, err.status); - } - }); - }; + }); + }; - this.checkControl = function(checkName) { - var modalInstance = ModalSrv.confirm( - 'Data health check', - 'Are you sure you want to trigger ' + checkName + ' health check', { - okText: 'Yes, trigger it' - } - ); - - modalInstance.result - .then(function() { - PlatformSrv.runCheck(checkName); - }) - .then(function(/*response*/) { - NotificationSrv.success('Data health check of ' + checkName + ' started sucessfully'); - }) - .catch(function(err) { - if (!_.isString(err)) { - NotificationSrv.error('Platform status', err.data, err.status); - } - }); + this.checkControl = function (checkName) { + var modalInstance = ModalSrv.confirm( + 'Data health check', + 'Are you sure you want to trigger ' + checkName + ' health check', { + okText: 'Yes, trigger it' } + ); + + modalInstance.result + .then(function () { + PlatformSrv.runCheck(checkName); + }) + .then(function (/*response*/) { + NotificationSrv.success('Data health check of ' + checkName + ' started sucessfully'); + }) + .catch(function (err) { + if (!_.isString(err)) { + NotificationSrv.error('Platform status', err.data, err.status); + } + }); + } - }); + }); })(); diff --git a/frontend/app/scripts/services/api/PlatformSrv.js b/frontend/app/scripts/services/api/PlatformSrv.js index bd3451ec11..2aa910b1fc 100644 --- a/frontend/app/scripts/services/api/PlatformSrv.js +++ b/frontend/app/scripts/services/api/PlatformSrv.js @@ -1,22 +1,26 @@ -(function() { +(function () { 'use strict'; angular.module('theHiveServices') - .service('PlatformSrv', function($http) { + .service('PlatformSrv', function ($http) { - this.getIndexStatus = function() { + this.getIndexStatus = function () { return $http.get('./api/v1/admin/index/status') } - this.runReindex = function(indexName) { - return $http.get('./api/v1/admin/index/'+indexName+'/reindex'); + this.runReindex = function (indexName) { + return $http.post('./api/v1/admin/index/' + indexName + '/reindex'); } - this.getCheckStats = function() { + this.runRebuildIndex = function (indexName) { + return $http.post('./api/v1/admin/index/' + indexName + '/rebuild'); + } + + this.getCheckStats = function () { return $http.get('./api/v1/admin/check/stats') } - this.runCheck = function(checkName) { - return $http.get('./api/v1/admin/check/'+checkName+'/trigger'); + this.runCheck = function (checkName) { + return $http.get('./api/v1/admin/check/' + checkName + '/trigger'); } }); diff --git a/frontend/app/views/partials/admin/platform/status.html b/frontend/app/views/partials/admin/platform/status.html index 12b4c23851..6a25e82efd 100644 --- a/frontend/app/views/partials/admin/platform/status.html +++ b/frontend/app/views/partials/admin/platform/status.html @@ -55,16 +55,22 @@

Data index status Loading index status...
-
Index: {{index.name | uppercase}}
-
# Entities
-
- Reindex +
+ Index: {{index.name | uppercase}} + + + Reindex the data + + + Drop and rebuild the index + +
+
# Entities
-
+

{{item.name}}

@@ -75,8 +81,6 @@

{{item.count}}

- -
diff --git a/thehive/app/org/thp/thehive/controllers/v1/Router.scala b/thehive/app/org/thp/thehive/controllers/v1/Router.scala index acfec720e2..0b98838365 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/Router.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/Router.scala @@ -46,7 +46,7 @@ class Router @Inject() ( case GET(p"/admin/check/stats") => adminCtrl.checkStats case GET(p"/admin/check/$name/trigger") => adminCtrl.triggerCheck(name) case GET(p"/admin/index/status") => adminCtrl.indexStatus - case GET(p"/admin/index/$name/reindex") => adminCtrl.reindex(name) + case POST(p"/admin/index/$name/reindex") => adminCtrl.reindex(name) case POST(p"/admin/index/$name/rebuild") => adminCtrl.rebuild(name) case GET(p"/admin/log/set/$packageName/$level") => adminCtrl.setLogLevel(packageName, level) case POST(p"/admin/schema/repair/$schemaName" ? q_o"select=$select" ? q_o"filter=$filter") => adminCtrl.schemaRepair(schemaName, select, filter)