Enable hideManagerAlerts

This commit is contained in:
JuanCarlos 2020-03-12 15:16:54 +01:00
parent 8e9dff0737
commit 15e216e2da
No known key found for this signature in database
GPG Key ID: B1C4FB733616273A
2 changed files with 68 additions and 44 deletions

View File

@ -5,7 +5,7 @@ import { uiModules } from 'ui/modules';
import discoverTemplate from '../templates/kibana-template/kibana-discover-template.html'; import discoverTemplate from '../templates/kibana-template/kibana-discover-template.html';
uiModules.get('app/wazuh', ['kibana/courier']).directive('kbnDis', [ uiModules.get('app/wazuh', ['kibana/courier']).directive('kbnDis', [
function() { function () {
return { return {
restrict: 'E', restrict: 'E',
scope: {}, scope: {},
@ -97,7 +97,7 @@ const app = uiModules.get('apps/discover', [
'app/wazuh' 'app/wazuh'
]); ]);
app.directive('discoverAppW', function() { app.directive('discoverAppW', function () {
return { return {
restrict: 'E', restrict: 'E',
controllerAs: 'discoverApp', controllerAs: 'discoverApp',
@ -126,7 +126,8 @@ function discoverController(
getAppState, getAppState,
globalState, globalState,
loadedVisualizations, loadedVisualizations,
discoverPendingUpdates discoverPendingUpdates,
wazuhConfig
) { ) {
const visualizeLoader = Private(VisualizeLoaderProvider); const visualizeLoader = Private(VisualizeLoaderProvider);
let visualizeHandler; let visualizeHandler;
@ -154,7 +155,7 @@ function discoverController(
$scope.showInterval = false; $scope.showInterval = false;
$scope.minimumVisibleRows = 50; $scope.minimumVisibleRows = 50;
$scope.intervalEnabled = function(interval) { $scope.intervalEnabled = function (interval) {
return interval.val !== 'custom'; return interval.val !== 'custom';
}; };
@ -339,17 +340,17 @@ function discoverController(
bucketsDescription: bucketsDescription:
$scope.bucketInterval.scale > 1 $scope.bucketInterval.scale > 1
? i18n('kbn.discover.bucketIntervalTooltip.tooLargeBucketsText', { ? i18n('kbn.discover.bucketIntervalTooltip.tooLargeBucketsText', {
defaultMessage: 'buckets that are too large' defaultMessage: 'buckets that are too large'
}) })
: i18n('kbn.discover.bucketIntervalTooltip.tooManyBucketsText', { : i18n('kbn.discover.bucketIntervalTooltip.tooManyBucketsText', {
defaultMessage: 'too many buckets' defaultMessage: 'too many buckets'
}), }),
bucketIntervalDescription: $scope.bucketInterval.description bucketIntervalDescription: $scope.bucketInterval.description
} }
}); });
}; };
$scope.$watchCollection('state.columns', function() { $scope.$watchCollection('state.columns', function () {
$state.save(); $state.save();
}); });
@ -363,21 +364,21 @@ function discoverController(
indexPatternList: $route.current.locals.ip.list indexPatternList: $route.current.locals.ip.list
}; };
const init = _.once(function() { const init = _.once(function () {
stateMonitor = stateMonitorFactory.create($state, getStateDefaults()); stateMonitor = stateMonitorFactory.create($state, getStateDefaults());
stateMonitor.onChange(status => { stateMonitor.onChange(status => {
$appStatus.dirty = status.dirty || !savedSearch.id; $appStatus.dirty = status.dirty || !savedSearch.id;
}); });
$scope.$on('$destroy', () => stateMonitor.destroy()); $scope.$on('$destroy', () => stateMonitor.destroy());
$scope.updateDataSource().then(function() { $scope.updateDataSource().then(function () {
$scope.$listen(timefilter, 'fetch', function() { $scope.$listen(timefilter, 'fetch', function () {
$scope.fetch(); $scope.fetch();
// WAZUH // WAZUH
$rootScope.$broadcast('updateVis'); $rootScope.$broadcast('updateVis');
}); });
$scope.$watchCollection('state.sort', function(sort) { $scope.$watchCollection('state.sort', function (sort) {
if (!sort) return; if (!sort) return;
// get the current sort from {key: val} to ["key", "val"]; // get the current sort from {key: val} to ["key", "val"];
@ -390,17 +391,39 @@ function discoverController(
}); });
// update data source when filters update // update data source when filters update
$scope.$listen(queryFilter, 'update', function() { $scope.$listen(queryFilter, 'update', function () {
const buildFilters = () => {
const { hideManagerAlerts } = wazuhConfig.getConfig();
if (hideManagerAlerts) {
return [{
"meta": {
"alias": null,
"disabled": false,
"key": "agent.id",
"negate": true,
"params": { "query": "000" },
"type": "phrase",
"index": "wazuh-alerts-3.x-*"
},
"query": { "match_phrase": { "agent.id": "000" } },
"$state": { "store": "appState" }
}];
}
return [];
}
return $scope return $scope
.updateDataSource() .updateDataSource()
.then(function() { .then(function () {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
/////////////////////////////// WAZUH /////////////////////////////////// /////////////////////////////// WAZUH ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
discoverPendingUpdates.removeAll(); discoverPendingUpdates.removeAll();
discoverPendingUpdates.addItem( discoverPendingUpdates.addItem(
$state.query, $state.query,
queryFilter.getFilters() [
...queryFilter.getFilters(),
...buildFilters() // Hide '000' agent
]
); );
$rootScope.$broadcast('updateVis'); $rootScope.$broadcast('updateVis');
$rootScope.$broadcast('fetch'); $rootScope.$broadcast('fetch');
@ -421,7 +444,7 @@ function discoverController(
}); });
// update data source when hitting forward/back and the query changes // update data source when hitting forward/back and the query changes
$scope.$listen($state, 'fetch_with_changes', function(diff) { $scope.$listen($state, 'fetch_with_changes', function (diff) {
if (diff.indexOf('query') >= 0) $scope.fetch(); if (diff.indexOf('query') >= 0) $scope.fetch();
}); });
@ -429,7 +452,7 @@ function discoverController(
$scope.$listen(queryFilter, 'fetch', $scope.fetch); $scope.$listen(queryFilter, 'fetch', $scope.fetch);
timefilter.enableAutoRefreshSelector(); timefilter.enableAutoRefreshSelector();
$scope.$watch('opts.timefield', function(timefield) { $scope.$watch('opts.timefield', function (timefield) {
if (!!timefield) { if (!!timefield) {
timefilter.enableTimeRangeSelector(); timefilter.enableTimeRangeSelector();
} else { } else {
@ -437,11 +460,11 @@ function discoverController(
} }
}); });
$scope.$watch('state.interval', function() { $scope.$watch('state.interval', function () {
$scope.fetch(); $scope.fetch();
}); });
$scope.$watch('vis.aggs', function() { $scope.$watch('vis.aggs', function () {
// no timefield, no vis, nothing to update // no timefield, no vis, nothing to update
if (!$scope.opts.timefield) return; if (!$scope.opts.timefield) return;
@ -483,7 +506,7 @@ function discoverController(
else return status.NO_RESULTS; else return status.NO_RESULTS;
} }
return function() { return function () {
const current = { const current = {
rows: $scope.rows, rows: $scope.rows,
fetchStatus: $scope.fetchStatus fetchStatus: $scope.fetchStatus
@ -531,15 +554,15 @@ function discoverController(
let filters = queryFilter.getFilters(); let filters = queryFilter.getFilters();
filters = Array.isArray(filters) filters = Array.isArray(filters)
? filters.filter( ? filters.filter(
item => (((item || {}).$state || {}).store || '') === 'appState' item => (((item || {}).$state || {}).store || '') === 'appState'
) )
: []; : [];
if (!filters || !filters.length) return false; if (!filters || !filters.length) return false;
} }
return true; return true;
}; };
$scope.opts.fetch = $scope.fetch = function() { $scope.opts.fetch = $scope.fetch = function () {
// Wazuh filters are not ready yet // Wazuh filters are not ready yet
if (!filtersAreReady()) return; if (!filtersAreReady()) return;
@ -553,14 +576,14 @@ function discoverController(
$scope $scope
.updateDataSource() .updateDataSource()
.then(setupVisualization) .then(setupVisualization)
.then(function() { .then(function () {
$state.save(); $state.save();
return courier.fetch(); return courier.fetch();
}) })
.catch(notify.error); .catch(notify.error);
}; };
$scope.updateQueryAndFetch = function({ query }) { $scope.updateQueryAndFetch = function ({ query }) {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
/////////////////////////////// WAZUH /////////////////////////////////// /////////////////////////////// WAZUH ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -602,7 +625,7 @@ function discoverController(
* *
* @type {String} * @type {String}
*/ */
const sortBy = (function() { const sortBy = (function () {
if (!Array.isArray(sort)) return 'implicit'; if (!Array.isArray(sort)) return 'implicit';
else if (sort[0] === '_score') return 'implicit'; else if (sort[0] === '_score') return 'implicit';
else if (sort[0] === timeField) return 'time'; else if (sort[0] === timeField) return 'time';
@ -635,7 +658,7 @@ function discoverController(
} }
// triggered when the status updated // triggered when the status updated
segmented.on('status', function(status) { segmented.on('status', function (status) {
$scope.fetchStatus = status; $scope.fetchStatus = status;
if (status.complete === 0) { if (status.complete === 0) {
// starting new segmented search request // starting new segmented search request
@ -672,7 +695,7 @@ function discoverController(
} }
}); });
segmented.on('first', function() { segmented.on('first', function () {
flushResponseData(); flushResponseData();
}); });
@ -680,17 +703,17 @@ function discoverController(
logResponseInInspector(resp); logResponseInInspector(resp);
if (resp._shards.failed > 0) { if (resp._shards.failed > 0) {
$scope.failures = _.union($scope.failures, resp._shards.failures); $scope.failures = _.union($scope.failures, resp._shards.failures);
$scope.failures = _.uniq($scope.failures, false, function(failure) { $scope.failures = _.uniq($scope.failures, false, function (failure) {
return failure.index + failure.shard + failure.reason; return failure.index + failure.shard + failure.reason;
}); });
} }
}); });
segmented.on('emptySegment', function(resp) { segmented.on('emptySegment', function (resp) {
logResponseInInspector(resp); logResponseInInspector(resp);
}); });
segmented.on('mergedSegment', function(merged) { segmented.on('mergedSegment', function (merged) {
$scope.mergedEsResp = merged; $scope.mergedEsResp = merged;
if ($scope.opts.timefield) { if ($scope.opts.timefield) {
@ -715,7 +738,7 @@ function discoverController(
// if we haven't counted yet, or need a fresh count because we are sorting, reset the counts // if we haven't counted yet, or need a fresh count because we are sorting, reset the counts
if (!counts || sortFn) counts = $scope.fieldCounts = {}; if (!counts || sortFn) counts = $scope.fieldCounts = {};
$scope.rows.forEach(function(hit) { $scope.rows.forEach(function (hit) {
// skip this work if we have already done it // skip this work if we have already done it
if (hit.$$_counted) return; if (hit.$$_counted) return;
@ -734,7 +757,7 @@ function discoverController(
}); });
}); });
segmented.on('complete', function() { segmented.on('complete', function () {
if ($scope.fetchStatus.hitCount === 0) { if ($scope.fetchStatus.hitCount === 0) {
flushResponseData(); flushResponseData();
} }
@ -761,7 +784,7 @@ function discoverController(
} }
beginSegmentedFetch(); beginSegmentedFetch();
$scope.updateTime = function() { $scope.updateTime = function () {
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
/////////////////////////////// WAZUH /////////////////////////////////// /////////////////////////////// WAZUH ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -782,11 +805,11 @@ function discoverController(
}; };
}; };
$scope.resetQuery = function() { $scope.resetQuery = function () {
kbnUrl.change('/discover/{{id}}', { id: $route.current.params.id }); kbnUrl.change('/discover/{{id}}', { id: $route.current.params.id });
}; };
$scope.newQuery = function() { $scope.newQuery = function () {
kbnUrl.change('/discover'); kbnUrl.change('/discover');
}; };
@ -803,7 +826,7 @@ function discoverController(
}; };
// TODO: On array fields, negating does not negate the combination, rather all terms // TODO: On array fields, negating does not negate the combination, rather all terms
$scope.filterQuery = function(field, values, operation) { $scope.filterQuery = function (field, values, operation) {
// Commented due to https://github.com/elastic/kibana/issues/22426 // Commented due to https://github.com/elastic/kibana/issues/22426
//$scope.indexPattern.popularizeField(field, 1); //$scope.indexPattern.popularizeField(field, 1);
filterActions.addFilter( filterActions.addFilter(
@ -832,18 +855,18 @@ function discoverController(
columnActions.moveColumn($scope.state.columns, columnName, newIndex); columnActions.moveColumn($scope.state.columns, columnName, newIndex);
}; };
$scope.scrollToTop = function() { $scope.scrollToTop = function () {
$window.scrollTo(0, 0); $window.scrollTo(0, 0);
}; };
$scope.scrollToBottom = function() { $scope.scrollToBottom = function () {
// delay scrolling to after the rows have been rendered // delay scrolling to after the rows have been rendered
$timeout(() => { $timeout(() => {
$element.find('#discoverBottomMarker').focus(); $element.find('#discoverBottomMarker').focus();
}, 0); }, 0);
}; };
$scope.showAllRows = function() { $scope.showAllRows = function () {
$scope.minimumVisibleRows = $scope.hits; $scope.minimumVisibleRows = $scope.hits;
}; };
@ -900,7 +923,7 @@ function discoverController(
.onSearchRequestStart(searchSource, searchRequest); .onSearchRequestStart(searchSource, searchRequest);
}); });
$scope.searchSource.setField('aggs', function() { $scope.searchSource.setField('aggs', function () {
//////////////////// WAZUH //////////////////////////////// //////////////////// WAZUH ////////////////////////////////
// Old code: // // Old code: //
// return $scope.vis.getAggConfig().toDsl(); // // return $scope.vis.getAggConfig().toDsl(); //
@ -1031,7 +1054,7 @@ function discoverController(
queryFilter queryFilter
.addFilters(wzCurrentFilters) .addFilters(wzCurrentFilters)
.then(() => {}) .then(() => { })
.catch(error => console.log(error.message || error)); // eslint-disable-line .catch(error => console.log(error.message || error)); // eslint-disable-line
} }
}; };

View File

@ -24,7 +24,8 @@ const needRestartFields = [
'wazuh.monitoring.replicas', 'wazuh.monitoring.replicas',
'wazuh.monitoring.creation', 'wazuh.monitoring.creation',
'wazuh.monitoring.pattern', 'wazuh.monitoring.pattern',
'logs.level' 'logs.level',
'hideManagerAlerts'
]; ];
export class UpdateConfigurationFile { export class UpdateConfigurationFile {
constructor() { constructor() {