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