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

View File

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