First approach on blank screen controller

This commit is contained in:
Jesús Ángel González 2018-01-29 17:04:36 +01:00 committed by Javier Castro
parent 844d1988ed
commit d6effc2e6a
5 changed files with 80 additions and 33 deletions

View File

@ -55,6 +55,9 @@ require('plugins/wazuh/controllers/common/factories.js');
require('plugins/wazuh/controllers/common/filters.js'); require('plugins/wazuh/controllers/common/filters.js');
require('plugins/wazuh/controllers/common/directives.js'); require('plugins/wazuh/controllers/common/directives.js');
// Blank Screen
require('plugins/wazuh/controllers/blankScreenController.js');
// Login // Login
require('plugins/wazuh/controllers/login.js'); require('plugins/wazuh/controllers/login.js');

View File

@ -0,0 +1,10 @@
const app = require('ui/modules').get('app/wazuh', []);
// Logs controller
app.controller('blankScreenController', function ($scope, $rootScope, errorHandler) {
$scope.error = '';
if($rootScope.blankScreenError) {
$scope.error = $rootScope.blankScreenError;
delete $rootScope.blankScreenError;
}
});

View File

@ -8,6 +8,7 @@ app.service('errorHandler', function ( Notifier, appState, $location) {
if(error.errorData && error.errorData.message) return error.errorData.message; if(error.errorData && error.errorData.message) return error.errorData.message;
if(error.data && typeof error.data === 'string') return error.data; if(error.data && typeof error.data === 'string') return error.data;
if(error.data && error.data.message) return error.data.message; if(error.data && error.data.message) return error.data.message;
if(error.data && error.data.data && typeof error.data.data === 'string') return error.data.data;
if(error.message) return error.message; if(error.message) return error.message;
if(typeof error === 'string') return error; if(typeof error === 'string') return error;
if(typeof error === 'object') return JSON.stringify(error); if(typeof error === 'object') return JSON.stringify(error);
@ -38,7 +39,7 @@ app.service('errorHandler', function ( Notifier, appState, $location) {
let text; let text;
switch (message) { switch (message) {
case 'no_elasticsearch': case 'no_elasticsearch':
text = 'Could not connect with elasticsearch in order to retrieve the credentials.'; text = `Could not connect with elasticsearch, maybe it's down.`;
break; break;
case 'no_credentials': case 'no_credentials':
text = 'Valid credentials not found in elasticsearch. It seems the credentials ' + text = 'Valid credentials not found in elasticsearch. It seems the credentials ' +

View File

@ -24,18 +24,26 @@ const settingsWizard = ($rootScope, $location, $q, $window, testAPI, appState, g
} }
const checkResponse = data => { const checkResponse = data => {
let fromElastic = false;
if (parseInt(data.data.error) === 2){ if (parseInt(data.data.error) === 2){
errorHandler.handle('Wazuh App: Please set up Wazuh API credentials.','Routes',true); errorHandler.handle('Wazuh App: Please set up Wazuh API credentials.','Routes',true);
} else if(data.data.data && data.data.data.apiIsDown){ } else if(data.data.data && data.data.data.apiIsDown){
$rootScope.apiIsDown = "down"; $rootScope.apiIsDown = "down";
errorHandler.handle('Wazuh RESTful API seems to be down.','Routes'); errorHandler.handle('Wazuh RESTful API seems to be down.','Routes');
} else { } else {
errorHandler.handle('Could not connect with Wazuh RESTful API.','Routes'); fromElastic = true;
$rootScope.blankScreenError = errorHandler.handle(data,'Routes');
appState.removeCurrentAPI(); appState.removeCurrentAPI();
} }
$rootScope.comeFromWizard = true;
if(!$rootScope.$$phase) $rootScope.$digest(); if(!fromElastic){
if(!$location.path().includes("/settings")) $location.path('/settings'); $rootScope.comeFromWizard = true;
if(!$rootScope.$$phase) $rootScope.$digest();
if(!$location.path().includes("/settings")) $location.path('/settings');
} else {
$location.path('/blank-screen');
}
deferred.reject(); deferred.reject();
} }
@ -120,30 +128,25 @@ const goToKibana = ($location, $window) => {
}; };
const getIp = (Promise, courier, config, $q, $rootScope, $window, $location, Private, appState, genericReq) => { const getIp = (Promise, courier, config, $q, $rootScope, $window, $location, Private, appState, genericReq) => {
let deferred = $q.defer();
if (healthCheck($window, $rootScope)) { if (healthCheck($window, $rootScope)) {
let deferred = $q.defer();
$location.path('/health-check');
deferred.reject(); deferred.reject();
return deferred.promise; $location.path('/health-check');
} else { } else {
const State = Private(StateProvider); const State = Private(StateProvider);
const savedObjectsClient = Private(SavedObjectsClientProvider); const savedObjectsClient = Private(SavedObjectsClientProvider);
return savedObjectsClient.find({ savedObjectsClient.find({
type: 'index-pattern', type : 'index-pattern',
fields: ['title'], fields : ['title'],
perPage: 10000 perPage: 10000
}) })
.then(({ savedObjects }) => { .then(({ savedObjects }) => {
let onlyWazuhAlerts = [];
let currentPattern = ''; let currentPattern = '';
let deferred = $q.defer();
genericReq.request('GET', '/api/wazuh-elastic/current-pattern') genericReq.request('GET', '/api/wazuh-elastic/current-pattern')
.then((data) => { .then(data => {
if (appState.getCurrentPattern()) { // There's cookie for the pattern if (appState.getCurrentPattern()) { // There's cookie for the pattern
currentPattern = appState.getCurrentPattern(); currentPattern = appState.getCurrentPattern();
@ -152,32 +155,43 @@ const getIp = (Promise, courier, config, $q, $rootScope, $window, $location, Pri
appState.setCurrentPattern(data.data.data); appState.setCurrentPattern(data.data.data);
} }
for (var i = 0; i < savedObjects.length; i++) { const onlyWazuhAlerts = savedObjects.filter(element => element.id === currentPattern);
if (savedObjects[i].id === currentPattern) {
onlyWazuhAlerts.push(savedObjects[i]);
}
}
if (onlyWazuhAlerts.length == 0) { // There's now selected ip if (onlyWazuhAlerts.length === 0) { // There's now selected ip
deferred.resolve("No ip"); deferred.resolve('No ip');
return deferred.promise; return;
} }
courier.indexPatterns.get(currentPattern) courier.indexPatterns.get(currentPattern)
.then((data) => { .then(data => {
deferred.resolve({ deferred.resolve({
list: onlyWazuhAlerts, list : onlyWazuhAlerts,
loaded: data, loaded : data,
stateVal: null, stateVal : null,
stateValFound: false stateValFound: false
}); });
})
.catch(error => {
deferred.reject(error);
$rootScope.blankScreenError = errorHandler.handle(error,'Elasticsearch');
$location.path('/blank-screen');
}); });
}); })
.catch(error => {
return deferred.promise; deferred.reject(error);
$rootScope.blankScreenError = errorHandler.handle(error,'Elasticsearch');
$location.path('/blank-screen');
});
})
.catch(error => {
deferred.reject(error);
$rootScope.blankScreenError = errorHandler.handle(error,'Elasticsearch');
$location.path('/blank-screen');
}); });
} }
return deferred.promise;
}; };
const getAllIp = (Promise, $q, $window, $rootScope, courier, config, $location, Private) => { const getAllIp = (Promise, $q, $window, $rootScope, courier, config, $location, Private) => {
@ -310,6 +324,9 @@ routes
.when('/login', { .when('/login', {
template: require('plugins/wazuh/templates/auth/login.html') template: require('plugins/wazuh/templates/auth/login.html')
}) })
.when('/blank-screen', {
template: require('plugins/wazuh/templates/error-handler/blank-screen.html')
})
.when('/', { .when('/', {
redirectTo: '/overview/' redirectTo: '/overview/'
}) })

View File

@ -0,0 +1,16 @@
<div flex layout="column" ng-controller="blankScreenController" layout-align="center center">
<div class="present-logo">
<img class="loading-logo-fail" aria-hidden="true" kbn-src="/plugins/wazuh/img/icon_fail.png"></img>
</div>
<div class="checks-fail">
<div class="health-check-error">
<div class="error-notify">Ups, something went wrong...</div>
{{ error }}<hr>
<a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html</a><hr>
<a href="https://documentation.wazuh.com/current/installation-guide/">https://documentation.wazuh.com/current/installation-guide/</a>
</div>
</div>
</div>