Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Elasticsearch error handling #271

Merged
merged 4 commits into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions public/controllers/blank-screen-controller.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const app = require('ui/modules').get('app/wazuh', []);

import $ from 'jquery';
// Logs controller
app.controller('blankScreenController', function ($scope, $rootScope, errorHandler) {
$scope.error = '';
if($rootScope.blankScreenError) {
$scope.error = errorHandler.handle($rootScope.blankScreenError,'',false,true);
$('#result').html(errorHandler.handle($rootScope.blankScreenError,'',false,true));
delete $rootScope.blankScreenError;
} else {
$('#result').html('Something went wrong')
}
});
6 changes: 6 additions & 0 deletions public/services/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ app.service('errorHandler', function ( Notifier, appState, $location) {

let text;
switch (message) {
case 'kibana_index_pattern_error':
text = `There seem to be a problem with Wazuh app visualizations in Kibana, please reinstall the Wazuh app.`;
break;
case 'elasticsearch_down':
text = `Could not find .kibana index on Elasticsearch or maybe Elasticsearch is down.<br>Please check it and try again.`;
break;
case 'no_elasticsearch':
text = `Could not connect with elasticsearch, maybe it's down.`;
break;
Expand Down
4 changes: 2 additions & 2 deletions public/templates/error-handler/blank-screen.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

<div class="checks-fail">
<div class="health-check-error">
<div class="error-notify">Ups, something went wrong...</div>
{{ error }}<hr>
<div class="error-notify">Ups, something went wrong...</div><hr>
<div id="result"></div><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>

Expand Down
26 changes: 15 additions & 11 deletions server/api/wazuh-elastic.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,22 @@ module.exports = (server, options) => {
type: 'doc',
q: `visualization.title:"Wazuh App Overview General Metric alerts"`
})
.then((data) => {
reply({
'statusCode': 200,
'data': JSON.parse(data.hits.hits[0]._source.visualization.kibanaSavedObjectMeta.searchSourceJSON).index
});
.then(data => {
if(data && data.hits && data.hits.hits && data.hits.hits[0] && data.hits.hits[0]._source){
return reply({
statusCode: 200,
data: JSON.parse(data.hits.hits[0]._source.visualization.kibanaSavedObjectMeta.searchSourceJSON).index
});
} else {
throw Error('no_visualization');
}
})
.catch((error) => {
reply({
'statusCode': 500,
'error': 10000,
'message': (error && error.message) ? error.message : error
}).code(500);
.catch(error => {
if(error && error.message && error.message === 'no_visualization'){
return reply('kibana_index_pattern_error').code(500);
}

return reply('elasticsearch_down').code(500);
});
};

Expand Down