From 0161d9e7162320b000c28390976acb771347879e Mon Sep 17 00:00:00 2001 From: JuanjiJG Date: Thu, 30 Aug 2018 14:10:35 +0200 Subject: [PATCH] Implemented Refresh function for Settings/Logs tab --- public/controllers/settings/index.js | 33 ++++++++++++++------ public/templates/settings/settings-logs.html | 27 +++++++++++----- public/templates/settings/settings.head | 2 +- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/public/controllers/settings/index.js b/public/controllers/settings/index.js index eb52dd4b2..338bb7fe8 100644 --- a/public/controllers/settings/index.js +++ b/public/controllers/settings/index.js @@ -15,7 +15,7 @@ import TabNames from '../../utils/tab-names'; const app = uiModules.get('app/wazuh', []); -app.controller('settingsController', +app.controller('settingsController', function ($scope, $routeParams, $window, $location, testAPI, appState, genericReq, errorHandler, wzMisc, wazuhConfig) { if (wzMisc.getWizard()) { $window.sessionStorage.removeItem('healthCheck'); @@ -29,6 +29,7 @@ function ($scope, $routeParams, $window, $location, testAPI, appState, genericRe $scope.formData = {}; $scope.tab = 'api'; $scope.load = true; + $scope.loadingLogs = true; $scope.addManagerContainer = false; $scope.showEditForm = {}; $scope.formUpdate = {}; @@ -232,7 +233,7 @@ function ($scope, $routeParams, $window, $location, testAPI, appState, genericRe const config = wazuhConfig.getConfig(); appState.setPatternSelector(config['ip.selector']); - + tmpData.extensions.audit = config['extensions.audit']; tmpData.extensions.pci = config['extensions.pci']; tmpData.extensions.gdpr = config['extensions.gdpr']; @@ -240,7 +241,7 @@ function ($scope, $routeParams, $window, $location, testAPI, appState, genericRe tmpData.extensions.ciscat = config['extensions.ciscat']; tmpData.extensions.aws = config['extensions.aws']; tmpData.extensions.virustotal = config['extensions.virustotal']; - + const checkData = await testAPI.check(tmpData); // API Check correct. Get Cluster info @@ -280,7 +281,7 @@ function ($scope, $routeParams, $window, $location, testAPI, appState, genericRe } try { - await genericReq.request('GET', '/api/wazuh-api/fetchAgents'); + await genericReq.request('GET', '/api/wazuh-api/fetchAgents'); } catch (error) { if(error && error.status && error.status === -1) { @@ -288,7 +289,7 @@ function ($scope, $routeParams, $window, $location, testAPI, appState, genericRe } else { errorHandler.handle(error,'Fetch agents'); } - + } await getSettings(); @@ -434,6 +435,18 @@ function ($scope, $routeParams, $window, $location, testAPI, appState, genericRe else $scope.messageErrorUpdate = text; }; + const getAppLogs = async () => { + try { + $scope.loadingLogs = true; + const logs = await genericReq.request('GET','/api/wazuh-api/logs',{}); + $scope.logs = logs.data.lastLogs.map(item => JSON.parse(item)); + $scope.loadingLogs = false; + if(!$scope.$$phase) $scope.$digest(); + } catch (error) { + $scope.logs = [{date: new Date(), level:'error', message: 'Error when loading Wazuh app logs'}]; + } + }; + const getAppInfo = async () => { try { const data = await genericReq.request('GET', '/api/wazuh-elastic/setup'); @@ -463,12 +476,10 @@ function ($scope, $routeParams, $window, $location, testAPI, appState, genericRe $scope.extensions = appState.getExtensions(JSON.parse(appState.getCurrentAPI()).id); } - try { - const logs = await genericReq.request('GET','/api/wazuh-api/logs',{}); - $scope.logs = logs.data.lastLogs.map(item => JSON.parse(item)); - } catch(error) { - $scope.logs = [{date: new Date(), level:'error', message: 'Error when loading Wazuh app logs'}]; + if ($scope.tab === 'logs') { + getAppLogs(); } + if(!$scope.$$phase) $scope.$digest(); return; } catch (error) { @@ -479,4 +490,6 @@ function ($scope, $routeParams, $window, $location, testAPI, appState, genericRe // Loading data getSettings().then(getAppInfo); + + $scope.refreshLogs = () => getAppLogs(); }); diff --git a/public/templates/settings/settings-logs.html b/public/templates/settings/settings-logs.html index af7a2c9c1..e5ce131be 100644 --- a/public/templates/settings/settings-logs.html +++ b/public/templates/settings/settings-logs.html @@ -5,7 +5,18 @@ Logs located at /usr/share/kibana/optimize/wazuh-logs/wazuhapp.log -
+ + +
+
+
+ + +
+ Refresh +
+ +
@@ -15,17 +26,17 @@ - - + +
Date
- {{ item.date }} + {{ item.date }} - {{ item.level.toUpperCase() }} - - {{ item.message }} + {{ item.level.toUpperCase() }} + {{ item.message }} +
-
\ No newline at end of file + diff --git a/public/templates/settings/settings.head b/public/templates/settings/settings.head index 34a899480..2ce1edb82 100644 --- a/public/templates/settings/settings.head +++ b/public/templates/settings/settings.head @@ -35,7 +35,7 @@ Extensions Pattern Configuration - Logs + Logs About