2017-11-27 10:57:47 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////// WAZUH //////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2018-06-25 10:16:49 +00:00
|
|
|
import { uiModules } from 'ui/modules';
|
|
|
|
import discoverTemplate from '../templates/kibana-template/kibana-discover-template.html';
|
2017-11-27 10:57:47 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
uiModules.get('app/wazuh', ['kibana/courier']).directive('kbnDis', [
|
|
|
|
function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
return {
|
2018-09-10 08:32:49 +00:00
|
|
|
restrict: 'E',
|
|
|
|
scope: {},
|
|
|
|
template: discoverTemplate
|
2018-06-25 10:16:49 +00:00
|
|
|
};
|
2018-09-10 08:32:49 +00:00
|
|
|
}
|
|
|
|
]);
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2017-11-27 10:57:47 +00:00
|
|
|
// Added dependencies (from Kibana module)
|
|
|
|
import 'ui/pager';
|
2018-11-06 15:26:34 +00:00
|
|
|
//import 'ui/typeahead';
|
2017-11-27 10:57:47 +00:00
|
|
|
import 'ui/doc_viewer';
|
|
|
|
import 'ui/render_directive';
|
|
|
|
|
|
|
|
// Added from its index.js
|
|
|
|
import 'plugins/kibana/discover/saved_searches/saved_searches';
|
|
|
|
import 'plugins/kibana/discover/directives/no_results';
|
|
|
|
import 'plugins/kibana/discover/directives/timechart';
|
|
|
|
import 'ui/collapsible_sidebar';
|
|
|
|
import 'plugins/kibana/discover/components/field_chooser/field_chooser';
|
|
|
|
import 'plugins/kibana/discover/controllers/discover';
|
|
|
|
import 'ui/doc_table/components/table_row';
|
|
|
|
|
|
|
|
// Research added (further checks needed)
|
2018-06-25 10:16:49 +00:00
|
|
|
import 'ui/doc_table/doc_table';
|
2018-04-21 11:44:46 +00:00
|
|
|
import 'ui/styles/sidebar.less';
|
|
|
|
import 'ui/styles/table.less';
|
2018-06-25 10:16:49 +00:00
|
|
|
import 'ui/doc_viewer/doc_viewer';
|
|
|
|
import 'ui/doc_title/doc_title';
|
|
|
|
import 'ui/style_compile/style_compile';
|
|
|
|
import 'ui/registry/doc_views';
|
|
|
|
import 'plugins/kbn_doc_views/kbn_doc_views';
|
|
|
|
import 'ui/tooltip/tooltip';
|
2017-11-27 10:57:47 +00:00
|
|
|
import 'ui/pager_control';
|
|
|
|
import 'ui/pager';
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-11-25 15:36:39 +00:00
|
|
|
import _ from 'lodash';
|
2019-01-28 19:53:05 +00:00
|
|
|
import React from 'react';
|
2017-11-25 15:36:39 +00:00
|
|
|
import angular from 'angular';
|
2019-01-28 19:53:05 +00:00
|
|
|
import chrome from 'ui/chrome';
|
2017-11-25 15:36:39 +00:00
|
|
|
import { getSort } from 'ui/doc_table/lib/get_sort';
|
|
|
|
import * as columnActions from 'ui/doc_table/actions/columns';
|
2017-12-14 12:28:31 +00:00
|
|
|
import * as filterActions from 'ui/doc_table/actions/filter';
|
2019-01-28 19:53:05 +00:00
|
|
|
import dateMath from '@elastic/datemath';
|
2017-11-25 15:36:39 +00:00
|
|
|
import 'ui/doc_table';
|
|
|
|
import 'ui/visualize';
|
|
|
|
import 'ui/fixed_scroll';
|
|
|
|
import 'ui/directives/validate_json';
|
|
|
|
import 'ui/filters/moment';
|
|
|
|
import 'ui/index_patterns';
|
|
|
|
import 'ui/state_management/app_state';
|
2018-08-21 15:24:57 +00:00
|
|
|
import { timefilter } from 'ui/timefilter';
|
2017-11-25 15:36:39 +00:00
|
|
|
import 'ui/query_bar';
|
2018-09-10 08:32:49 +00:00
|
|
|
import {
|
|
|
|
hasSearchStategyForIndexPattern,
|
|
|
|
isDefaultTypeIndexPattern
|
|
|
|
} from 'ui/courier';
|
2018-08-21 15:24:57 +00:00
|
|
|
import { toastNotifications, getPainlessError } from 'ui/notify';
|
2017-11-25 15:36:39 +00:00
|
|
|
import { VisProvider } from 'ui/vis';
|
2018-11-06 15:26:34 +00:00
|
|
|
import { VislibSeriesResponseHandlerProvider } from 'ui/vis/response_handlers/vislib';
|
2017-11-25 15:36:39 +00:00
|
|
|
import { DocTitleProvider } from 'ui/doc_title';
|
|
|
|
import PluginsKibanaDiscoverHitSortFnProvider from 'plugins/kibana/discover/_hit_sort_fn';
|
|
|
|
import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter';
|
2019-01-28 19:53:05 +00:00
|
|
|
// No need for this since we are using custom interval options
|
|
|
|
//import { intervalOptions } from 'ui/agg_types/buckets/_interval_options';
|
2017-11-25 15:36:39 +00:00
|
|
|
import { stateMonitorFactory } from 'ui/state_management/state_monitor_factory';
|
2019-01-28 19:53:05 +00:00
|
|
|
import { migrateLegacyQuery } from 'ui/utils/migrate_legacy_query';
|
2017-12-14 12:28:31 +00:00
|
|
|
import { FilterManagerProvider } from 'ui/filter_manager';
|
2018-08-21 15:24:57 +00:00
|
|
|
import { getDocLink } from 'ui/documentation_links';
|
2019-01-28 19:53:05 +00:00
|
|
|
import { VisualizeLoaderProvider } from 'ui/visualize/loader/visualize_loader';
|
2018-11-06 15:26:34 +00:00
|
|
|
import { ShareContextMenuExtensionsRegistryProvider } from 'ui/share';
|
|
|
|
import { getUnhashableStatesProvider } from 'ui/state_management/state_hashing';
|
2019-01-28 19:53:05 +00:00
|
|
|
import { Inspector } from 'ui/inspector';
|
2018-11-06 15:26:34 +00:00
|
|
|
import { RequestAdapter } from 'ui/inspector/adapters';
|
2018-12-13 10:02:53 +00:00
|
|
|
import {
|
|
|
|
getRequestInspectorStats,
|
|
|
|
getResponseInspectorStats
|
|
|
|
} from 'ui/courier/utils/courier_inspector_utils';
|
2018-11-06 15:26:34 +00:00
|
|
|
import { tabifyAggResponse } from 'ui/agg_response/tabify';
|
|
|
|
|
2018-09-03 09:46:55 +00:00
|
|
|
import 'ui/courier/search_strategy/default_search_strategy';
|
2017-11-25 15:36:39 +00:00
|
|
|
|
|
|
|
const app = uiModules.get('apps/discover', [
|
|
|
|
'kibana/notify',
|
|
|
|
'kibana/courier',
|
2018-08-21 15:24:57 +00:00
|
|
|
'kibana/url',
|
2017-11-25 15:36:39 +00:00
|
|
|
'kibana/index_patterns',
|
|
|
|
'app/wazuh'
|
|
|
|
]);
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
app.directive('discoverAppW', function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
controllerAs: 'discoverApp',
|
|
|
|
controller: discoverController
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
function discoverController(
|
|
|
|
$element,
|
|
|
|
$route,
|
|
|
|
$scope,
|
|
|
|
$timeout,
|
|
|
|
$window,
|
|
|
|
AppState,
|
|
|
|
Notifier,
|
|
|
|
Private,
|
|
|
|
Promise,
|
|
|
|
config,
|
|
|
|
courier,
|
2018-11-06 15:26:34 +00:00
|
|
|
kbnUrl,
|
|
|
|
localStorage,
|
2019-01-28 19:53:05 +00:00
|
|
|
i18n,
|
|
|
|
// Wazuh requirements from here
|
|
|
|
$rootScope,
|
|
|
|
$location,
|
2018-05-14 15:12:10 +00:00
|
|
|
getAppState,
|
2018-05-15 12:01:26 +00:00
|
|
|
globalState,
|
2018-05-15 14:11:35 +00:00
|
|
|
loadedVisualizations,
|
|
|
|
discoverPendingUpdates
|
2017-11-25 15:36:39 +00:00
|
|
|
) {
|
2019-01-28 19:53:05 +00:00
|
|
|
const visualizeLoader = Private(VisualizeLoaderProvider);
|
|
|
|
let visualizeHandler;
|
2017-11-25 15:36:39 +00:00
|
|
|
const Vis = Private(VisProvider);
|
|
|
|
const docTitle = Private(DocTitleProvider);
|
|
|
|
const HitSortFn = Private(PluginsKibanaDiscoverHitSortFnProvider);
|
|
|
|
const queryFilter = Private(FilterBarQueryFilterProvider);
|
2018-11-06 15:26:34 +00:00
|
|
|
const responseHandler = Private(VislibSeriesResponseHandlerProvider).handler;
|
2017-12-14 12:28:31 +00:00
|
|
|
const filterManager = Private(FilterManagerProvider);
|
2017-11-25 15:36:39 +00:00
|
|
|
const notify = new Notifier({
|
|
|
|
location: 'Discover'
|
|
|
|
});
|
2018-11-06 15:26:34 +00:00
|
|
|
const getUnhashableStates = Private(getUnhashableStatesProvider);
|
2019-01-28 19:53:05 +00:00
|
|
|
const shareContextMenuExtensions = Private(ShareContextMenuExtensionsRegistryProvider);
|
2018-11-06 15:26:34 +00:00
|
|
|
const inspectorAdapters = {
|
|
|
|
requests: new RequestAdapter()
|
|
|
|
};
|
|
|
|
|
2018-06-15 14:57:59 +00:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
//////////////////// WAZUH ///////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
const calcWzInterval = () => {
|
|
|
|
let wzInterval = false;
|
|
|
|
try {
|
2018-08-22 08:37:54 +00:00
|
|
|
const from = dateMath.parse(timefilter.getTime().from);
|
2018-09-10 08:32:49 +00:00
|
|
|
const to = dateMath.parse(timefilter.getTime().to);
|
2018-06-15 14:57:59 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
const totalSeconds = (to - from) / 1000;
|
|
|
|
if (totalSeconds <= 3600) wzInterval = 'm';
|
|
|
|
else if (totalSeconds > 3600 && totalSeconds <= 86400) wzInterval = 'h';
|
|
|
|
else if (totalSeconds > 86400 && totalSeconds <= 604800) wzInterval = 'd';
|
|
|
|
else if (totalSeconds > 604800 && totalSeconds <= 2419200)
|
|
|
|
wzInterval = 'w';
|
|
|
|
else wzInterval = 'M';
|
2018-07-31 14:47:20 +00:00
|
|
|
} catch (error) {} // eslint-disable-line
|
2018-06-15 14:57:59 +00:00
|
|
|
|
2018-06-25 10:16:49 +00:00
|
|
|
return wzInterval;
|
|
|
|
};
|
2018-06-15 14:57:59 +00:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
$scope.getDocLink = getDocLink;
|
2018-06-15 14:57:59 +00:00
|
|
|
|
2018-06-15 13:40:31 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////// WAZUH ////////////////////////////////////////////////////////////
|
|
|
|
// Old code: //
|
2018-08-21 15:24:57 +00:00
|
|
|
// $scope.intervalOptions = intervalOptions; //
|
2018-06-15 13:40:31 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
$scope.intervalOptions = [
|
|
|
|
{
|
|
|
|
display: 'Minute',
|
|
|
|
val: 'm'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: 'Hourly',
|
|
|
|
val: 'h'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: 'Daily',
|
|
|
|
val: 'd'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: 'Weekly',
|
|
|
|
val: 'w'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: 'Monthly',
|
|
|
|
val: 'M'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: 'Yearly',
|
|
|
|
val: 'y'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: 'Custom',
|
|
|
|
val: 'custom'
|
|
|
|
}
|
2018-06-25 10:16:49 +00:00
|
|
|
];
|
2018-06-15 13:40:31 +00:00
|
|
|
//////////////////////////////////////
|
|
|
|
//////////////////////////////////////
|
|
|
|
//////////////////////////////////////
|
2017-11-25 15:36:39 +00:00
|
|
|
$scope.showInterval = false;
|
|
|
|
$scope.minimumVisibleRows = 50;
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.intervalEnabled = function(interval) {
|
2017-11-25 15:36:39 +00:00
|
|
|
return interval.val !== 'custom';
|
|
|
|
};
|
2018-04-21 11:44:46 +00:00
|
|
|
|
2018-11-06 15:26:34 +00:00
|
|
|
// the saved savedSearch
|
|
|
|
const savedSearch = $route.current.locals.savedSearch;
|
|
|
|
$scope.$on('$destroy', savedSearch.destroy);
|
|
|
|
|
|
|
|
const $appStatus = ($scope.appStatus = this.appStatus = {
|
|
|
|
dirty: !savedSearch.id
|
|
|
|
});
|
|
|
|
|
|
|
|
// WAZUH MODIFIED
|
2018-08-21 15:24:57 +00:00
|
|
|
$scope.topNavMenu = [];
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////// WAZUH //////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2018-03-01 12:19:24 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.toggleRefresh = () => {
|
|
|
|
$scope.timefilter.refreshInterval.pause = !$scope.timefilter.refreshInterval
|
|
|
|
.pause;
|
|
|
|
};
|
2018-03-01 12:19:24 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2018-02-06 23:32:17 +00:00
|
|
|
|
2017-11-25 15:36:39 +00:00
|
|
|
// the actual courier.SearchSource
|
|
|
|
$scope.searchSource = savedSearch.searchSource;
|
|
|
|
$scope.indexPattern = resolveIndexPatternLoading();
|
2018-08-21 15:24:57 +00:00
|
|
|
|
2017-11-25 15:36:39 +00:00
|
|
|
$scope.searchSource
|
2018-08-21 15:24:57 +00:00
|
|
|
.setField('index', $scope.indexPattern)
|
|
|
|
.setField('highlightAll', true)
|
|
|
|
.setField('version', true);
|
|
|
|
|
2018-11-06 15:26:34 +00:00
|
|
|
// Even when searching rollups, we want to use the default strategy so that we get back a
|
|
|
|
// document-like response.
|
|
|
|
$scope.searchSource.setPreferredSearchStrategyId('default');
|
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
// searchSource which applies time range
|
|
|
|
const timeRangeSearchSource = savedSearch.searchSource.create();
|
2018-12-13 10:02:53 +00:00
|
|
|
if (isDefaultTypeIndexPattern($scope.indexPattern)) {
|
2018-11-06 15:26:34 +00:00
|
|
|
timeRangeSearchSource.setField('filter', () => {
|
|
|
|
return timefilter.createFilter($scope.indexPattern);
|
|
|
|
});
|
|
|
|
}
|
2018-08-21 15:24:57 +00:00
|
|
|
|
|
|
|
$scope.searchSource.setParent(timeRangeSearchSource);
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-12-13 10:02:53 +00:00
|
|
|
const pageTitleSuffix =
|
|
|
|
savedSearch.id && savedSearch.title ? `: ${savedSearch.title}` : '';
|
2017-12-14 12:28:31 +00:00
|
|
|
docTitle.change(`Discover${pageTitleSuffix}`);
|
2019-01-28 19:53:05 +00:00
|
|
|
const discoverBreadcrumbsTitle = i18n('kbn.discover.discoverBreadcrumbTitle', {
|
|
|
|
defaultMessage: 'Discover',
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-11-06 15:26:34 +00:00
|
|
|
if (savedSearch.id && savedSearch.title) {
|
2019-01-28 19:53:05 +00:00
|
|
|
chrome.breadcrumbs.set([{
|
|
|
|
text: discoverBreadcrumbsTitle,
|
|
|
|
href: '#/discover'
|
|
|
|
}, { text: savedSearch.title }]);
|
2018-11-06 15:26:34 +00:00
|
|
|
} else {
|
2019-01-28 19:53:05 +00:00
|
|
|
chrome.breadcrumbs.set([{
|
|
|
|
text: discoverBreadcrumbsTitle,
|
|
|
|
}]);
|
2018-11-06 15:26:34 +00:00
|
|
|
}
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-11-06 15:26:34 +00:00
|
|
|
let stateMonitor;
|
2018-12-13 10:02:53 +00:00
|
|
|
|
|
|
|
const $state = ($scope.state = new AppState(getStateDefaults()));
|
2017-11-25 15:36:39 +00:00
|
|
|
|
|
|
|
const getFieldCounts = async () => {
|
|
|
|
// the field counts aren't set until we have the data back,
|
|
|
|
// so we wait for the fetch to be done before proceeding
|
|
|
|
if (!$scope.fetchStatus) {
|
|
|
|
return $scope.fieldCounts;
|
|
|
|
}
|
|
|
|
|
|
|
|
return await new Promise(resolve => {
|
2018-09-10 08:32:49 +00:00
|
|
|
const unwatch = $scope.$watch('fetchStatus', newValue => {
|
2017-11-25 15:36:39 +00:00
|
|
|
if (newValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unwatch();
|
|
|
|
resolve($scope.fieldCounts);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const getSharingDataFields = async () => {
|
|
|
|
const selectedFields = $state.columns;
|
2018-12-13 10:02:53 +00:00
|
|
|
if (selectedFields.length === 1 && selectedFields[0] === '_source') {
|
2017-11-25 15:36:39 +00:00
|
|
|
const fieldCounts = await getFieldCounts();
|
|
|
|
return {
|
|
|
|
searchFields: null,
|
|
|
|
selectFields: _.keys(fieldCounts).sort()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const timeFieldName = $scope.indexPattern.timeFieldName;
|
2018-12-13 10:02:53 +00:00
|
|
|
const fields = timeFieldName
|
|
|
|
? [timeFieldName, ...selectedFields]
|
|
|
|
: selectedFields;
|
2017-11-25 15:36:39 +00:00
|
|
|
return {
|
|
|
|
searchFields: fields,
|
|
|
|
selectFields: fields
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getSharingData = async () => {
|
2018-08-21 15:24:57 +00:00
|
|
|
const searchSource = $scope.searchSource.createCopy();
|
2017-11-25 15:36:39 +00:00
|
|
|
|
|
|
|
const { searchFields, selectFields } = await getSharingDataFields();
|
2018-08-21 15:24:57 +00:00
|
|
|
searchSource.setField('fields', searchFields);
|
|
|
|
searchSource.setField('sort', getSort($state.sort, $scope.indexPattern));
|
|
|
|
searchSource.setField('highlight', null);
|
|
|
|
searchSource.setField('highlightAll', null);
|
|
|
|
searchSource.setField('aggs', null);
|
|
|
|
searchSource.setField('size', null);
|
2017-11-25 15:36:39 +00:00
|
|
|
|
|
|
|
const body = await searchSource.getSearchRequestBody();
|
|
|
|
return {
|
|
|
|
searchRequest: {
|
2018-08-21 15:24:57 +00:00
|
|
|
index: searchSource.getField('index').title,
|
2017-11-25 15:36:39 +00:00
|
|
|
body
|
|
|
|
},
|
|
|
|
fields: selectFields,
|
|
|
|
metaFields: $scope.indexPattern.metaFields,
|
2018-12-13 10:02:53 +00:00
|
|
|
conflictedTypesFields: $scope.indexPattern.fields
|
|
|
|
.filter(f => f.type === 'conflict')
|
|
|
|
.map(f => f.name),
|
2018-08-21 15:24:57 +00:00
|
|
|
indexPatternId: searchSource.getField('index').id
|
2017-11-25 15:36:39 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.uiState = $state.makeStateful('uiState');
|
|
|
|
|
|
|
|
function getStateDefaults() {
|
2018-06-15 13:40:31 +00:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
//////////////////// WAZUH ///////////////////////////////
|
2018-06-15 14:57:59 +00:00
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
let wzInterval = calcWzInterval();
|
2018-06-15 13:40:31 +00:00
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////
|
2017-11-25 15:36:39 +00:00
|
|
|
return {
|
2018-09-10 08:32:49 +00:00
|
|
|
query: $scope.searchSource.getField('query') || {
|
|
|
|
query: '',
|
2018-12-13 10:02:53 +00:00
|
|
|
language:
|
|
|
|
localStorage.get('kibana.userQueryLanguage') ||
|
|
|
|
config.get('search:queryLanguage')
|
2018-09-10 08:32:49 +00:00
|
|
|
},
|
2018-12-13 10:02:53 +00:00
|
|
|
sort: getSort.array(
|
|
|
|
savedSearch.sort,
|
|
|
|
$scope.indexPattern,
|
|
|
|
config.get('discover:sort:defaultOrder')
|
|
|
|
),
|
|
|
|
columns:
|
|
|
|
savedSearch.columns.length > 0
|
|
|
|
? savedSearch.columns
|
|
|
|
: config.get('defaultColumns').slice(),
|
2017-11-25 15:36:39 +00:00
|
|
|
index: $scope.indexPattern.id,
|
2018-09-10 08:32:49 +00:00
|
|
|
interval: wzInterval || 'h', //// WAZUH /////
|
2018-08-21 15:24:57 +00:00
|
|
|
filters: _.cloneDeep($scope.searchSource.getOwnField('filter'))
|
2017-11-25 15:36:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
$state.index = $scope.indexPattern.id;
|
|
|
|
$state.sort = getSort.array($state.sort, $scope.indexPattern);
|
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
$scope.getBucketIntervalToolTipText = () => {
|
2019-01-28 19:53:05 +00:00
|
|
|
return (
|
|
|
|
i18n('kbn.discover.bucketIntervalTooltip', {
|
|
|
|
// eslint-disable-next-line max-len
|
|
|
|
defaultMessage: 'This interval creates {bucketsDescription} to show in the selected time range, so it has been scaled to {bucketIntervalDescription}',
|
|
|
|
values: {
|
|
|
|
bucketsDescription: $scope.bucketInterval.scale > 1
|
|
|
|
? i18n('kbn.discover.bucketIntervalTooltip.tooLargeBucketsText', {
|
|
|
|
defaultMessage: 'buckets that are too large',
|
|
|
|
})
|
|
|
|
: i18n('kbn.discover.bucketIntervalTooltip.tooManyBucketsText', {
|
|
|
|
defaultMessage: 'too many buckets',
|
|
|
|
}),
|
|
|
|
bucketIntervalDescription: $scope.bucketInterval.description,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
2018-08-21 15:24:57 +00:00
|
|
|
};
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.$watchCollection('state.columns', function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
$state.save();
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.opts = {
|
|
|
|
// number of records to fetch, then paginate through
|
|
|
|
sampleSize: config.get('discover:sampleSize'),
|
2018-12-13 10:02:53 +00:00
|
|
|
timefield:
|
|
|
|
isDefaultTypeIndexPattern($scope.indexPattern) &&
|
|
|
|
$scope.indexPattern.timeFieldName,
|
2017-11-25 15:36:39 +00:00
|
|
|
savedSearch: savedSearch,
|
2018-12-13 10:02:53 +00:00
|
|
|
indexPatternList: $route.current.locals.ip.list
|
2017-11-25 15:36:39 +00:00
|
|
|
};
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
const init = _.once(function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
stateMonitor = stateMonitorFactory.create($state, getStateDefaults());
|
2018-09-10 08:32:49 +00:00
|
|
|
stateMonitor.onChange(status => {
|
2017-11-25 15:36:39 +00:00
|
|
|
$appStatus.dirty = status.dirty || !savedSearch.id;
|
|
|
|
});
|
|
|
|
$scope.$on('$destroy', () => stateMonitor.destroy());
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.updateDataSource().then(function() {
|
|
|
|
$scope.$listen(timefilter, 'fetch', function() {
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
// WAZUH //
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
$state.interval = calcWzInterval() || 'd';
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////
|
|
|
|
|
|
|
|
$scope.fetch();
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-12-13 10:02:53 +00:00
|
|
|
$scope.$watchCollection('state.sort', function(sort) {
|
2018-09-10 08:32:49 +00:00
|
|
|
if (!sort) return;
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
// get the current sort from {key: val} to ["key", "val"];
|
2018-12-13 10:02:53 +00:00
|
|
|
const currentSort = Object.entries(
|
|
|
|
$scope.searchSource.getField('sort')
|
|
|
|
).pop();
|
2018-09-10 08:32:49 +00:00
|
|
|
|
|
|
|
// if the searchSource doesn't know, tell it so
|
|
|
|
if (!angular.equals(sort, currentSort)) $scope.fetch();
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
// update data source when filters update
|
|
|
|
$scope.$listen(queryFilter, 'update', function() {
|
|
|
|
return $scope
|
|
|
|
.updateDataSource()
|
|
|
|
.then(function() {
|
2017-12-14 12:28:31 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////// WAZUH ///////////////////////////////////
|
2018-09-10 08:32:49 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2018-06-25 10:16:49 +00:00
|
|
|
discoverPendingUpdates.removeAll();
|
2018-09-10 08:32:49 +00:00
|
|
|
discoverPendingUpdates.addItem(
|
|
|
|
$state.query,
|
|
|
|
queryFilter.getFilters()
|
|
|
|
);
|
2018-05-15 07:40:20 +00:00
|
|
|
$rootScope.$broadcast('updateVis');
|
2017-12-14 12:28:31 +00:00
|
|
|
$rootScope.$broadcast('fetch');
|
2018-09-10 08:32:49 +00:00
|
|
|
if ($location.search().tab != 'configuration') {
|
2018-05-15 12:01:26 +00:00
|
|
|
loadedVisualizations.removeAll();
|
2018-01-14 13:08:38 +00:00
|
|
|
$rootScope.rendered = false;
|
2018-09-10 08:32:49 +00:00
|
|
|
$rootScope.loadingStatus = 'Fetching data...';
|
2018-01-14 13:08:38 +00:00
|
|
|
}
|
2017-12-14 12:28:31 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
$state.save();
|
2018-09-10 08:32:49 +00:00
|
|
|
})
|
|
|
|
.catch(console.error); // eslint-disable-line
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
// update data source when hitting forward/back and the query changes
|
|
|
|
$scope.$listen($state, 'fetch_with_changes', function(diff) {
|
|
|
|
if (diff.indexOf('query') >= 0) $scope.fetch();
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
// fetch data when filters fire fetch event
|
|
|
|
$scope.$listen(queryFilter, 'fetch', $scope.fetch);
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
timefilter.enableAutoRefreshSelector();
|
|
|
|
$scope.$watch('opts.timefield', function(timefield) {
|
|
|
|
if (!!timefield) {
|
|
|
|
timefilter.enableTimeRangeSelector();
|
|
|
|
} else {
|
|
|
|
timefilter.disableTimeRangeSelector();
|
|
|
|
}
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.$watch('state.interval', function() {
|
|
|
|
$scope.fetch();
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.$watch('vis.aggs', function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
// no timefield, no vis, nothing to update
|
2018-09-10 08:32:49 +00:00
|
|
|
if (!$scope.opts.timefield) return;
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
const buckets = $scope.vis.getAggConfig().bySchemaGroup.buckets;
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
if (buckets && buckets.length === 1) {
|
|
|
|
$scope.bucketInterval = buckets[0].buckets.getInterval();
|
|
|
|
}
|
|
|
|
});
|
2017-12-14 12:28:31 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.$watch('state.query', $scope.updateQueryAndFetch);
|
|
|
|
|
|
|
|
$scope.$watchMulti(
|
|
|
|
['rows', 'fetchStatus'],
|
|
|
|
(function updateResultState() {
|
|
|
|
let prev = {};
|
|
|
|
const status = {
|
|
|
|
LOADING: 'loading', // initial data load
|
|
|
|
READY: 'ready', // results came back
|
|
|
|
NO_RESULTS: 'none' // no results came back
|
|
|
|
};
|
|
|
|
|
|
|
|
function pick(rows, oldRows, fetchStatus) {
|
|
|
|
// initial state, pretend we are loading
|
|
|
|
if (rows == null && oldRows == null) return status.LOADING;
|
|
|
|
|
|
|
|
const rowsEmpty = _.isEmpty(rows);
|
|
|
|
// An undefined fetchStatus means the requests are still being
|
|
|
|
// prepared to be sent. When all requests are completed,
|
|
|
|
// fetchStatus is set to null, so it's important that we
|
|
|
|
// specifically check for undefined to determine a loading status.
|
|
|
|
const preparingForFetch = _.isUndefined(fetchStatus);
|
|
|
|
if (preparingForFetch) return status.LOADING;
|
|
|
|
else if (rowsEmpty && fetchStatus) return status.LOADING;
|
|
|
|
else if (!rowsEmpty) return status.READY;
|
|
|
|
else return status.NO_RESULTS;
|
|
|
|
}
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
return function() {
|
|
|
|
const current = {
|
|
|
|
rows: $scope.rows,
|
|
|
|
fetchStatus: $scope.fetchStatus
|
2017-12-14 12:28:31 +00:00
|
|
|
};
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.resultState = pick(
|
|
|
|
current.rows,
|
|
|
|
prev.rows,
|
|
|
|
current.fetchStatus,
|
|
|
|
prev.fetchStatus
|
|
|
|
);
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
// Copying it to the rootScope to access it from the Wazuh App //
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
$rootScope.resultState = $scope.resultState;
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
prev = current;
|
|
|
|
};
|
2019-01-28 19:53:05 +00:00
|
|
|
}()));
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
if ($scope.opts.timefield) {
|
|
|
|
setupVisualization();
|
|
|
|
$scope.updateTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
init.complete = true;
|
|
|
|
$state.replace();
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
});
|
|
|
|
|
2019-01-28 19:53:05 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Wazuh - Removed saveDataSource, it's not needed by our integration //
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2019-01-28 19:53:05 +00:00
|
|
|
/**
|
|
|
|
* Wazuh - aux function for checking filters status
|
|
|
|
*/
|
2018-10-18 08:15:37 +00:00
|
|
|
const filtersAreReady = () => {
|
|
|
|
const currentUrlPath = $location.path();
|
|
|
|
if (currentUrlPath && !currentUrlPath.includes('wazuh-discover')) {
|
|
|
|
let filters = queryFilter.getFilters();
|
|
|
|
filters = Array.isArray(filters)
|
|
|
|
? filters.filter(
|
2019-01-28 19:53:05 +00:00
|
|
|
item => (((item || {}).$state || {}).store || '') === 'appState'
|
2018-10-18 08:15:37 +00:00
|
|
|
)
|
|
|
|
: [];
|
|
|
|
if (!filters || !filters.length) return false;
|
|
|
|
}
|
|
|
|
return true;
|
2018-11-02 17:23:00 +00:00
|
|
|
};
|
2018-10-18 08:15:37 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.opts.fetch = $scope.fetch = function() {
|
2018-10-18 08:15:37 +00:00
|
|
|
// Wazuh filters are not ready yet
|
2018-11-02 17:23:00 +00:00
|
|
|
if (!filtersAreReady()) return;
|
2018-10-18 08:15:37 +00:00
|
|
|
|
2017-11-25 15:36:39 +00:00
|
|
|
// ignore requests to fetch before the app inits
|
|
|
|
if (!init.complete) return;
|
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
$scope.fetchError = undefined;
|
|
|
|
|
2017-11-25 15:36:39 +00:00
|
|
|
$scope.updateTime();
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope
|
|
|
|
.updateDataSource()
|
2017-12-14 12:28:31 +00:00
|
|
|
.then(setupVisualization)
|
2018-09-10 08:32:49 +00:00
|
|
|
.then(function() {
|
2017-12-14 12:28:31 +00:00
|
|
|
$state.save();
|
|
|
|
return courier.fetch();
|
|
|
|
})
|
|
|
|
.catch(notify.error);
|
2017-11-25 15:36:39 +00:00
|
|
|
};
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.updateQueryAndFetch = function(query) {
|
2017-11-25 15:36:39 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////// WAZUH ///////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2018-10-18 08:15:37 +00:00
|
|
|
// Wazuh filters are not ready yet
|
2018-11-02 17:23:00 +00:00
|
|
|
if (!filtersAreReady()) return;
|
|
|
|
|
2018-06-25 10:16:49 +00:00
|
|
|
discoverPendingUpdates.removeAll();
|
2018-09-10 08:32:49 +00:00
|
|
|
discoverPendingUpdates.addItem($state.query, queryFilter.getFilters());
|
2018-05-15 07:40:20 +00:00
|
|
|
$rootScope.$broadcast('updateVis');
|
2017-11-25 15:36:39 +00:00
|
|
|
$rootScope.$broadcast('fetch');
|
2017-11-28 16:37:31 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2017-11-25 15:36:39 +00:00
|
|
|
|
|
|
|
$state.query = migrateLegacyQuery(query);
|
|
|
|
$scope.fetch();
|
|
|
|
};
|
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
function handleSegmentedFetch(segmented) {
|
2017-11-25 15:36:39 +00:00
|
|
|
function flushResponseData() {
|
2018-08-21 15:24:57 +00:00
|
|
|
$scope.fetchError = undefined;
|
2017-11-25 15:36:39 +00:00
|
|
|
$scope.hits = 0;
|
2018-08-21 15:24:57 +00:00
|
|
|
$scope.failures = [];
|
2017-11-25 15:36:39 +00:00
|
|
|
$scope.rows = [];
|
|
|
|
$scope.fieldCounts = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$scope.rows) flushResponseData();
|
|
|
|
|
|
|
|
const sort = $state.sort;
|
|
|
|
const timeField = $scope.indexPattern.timeFieldName;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Basically an emum.
|
|
|
|
*
|
|
|
|
* opts:
|
|
|
|
* "time" - sorted by the timefield
|
|
|
|
* "non-time" - explicitly sorted by a non-time field, NOT THE SAME AS `sortBy !== "time"`
|
|
|
|
* "implicit" - no sorting set, NOT THE SAME AS "non-time"
|
|
|
|
*
|
|
|
|
* @type {String}
|
|
|
|
*/
|
2018-09-10 08:32:49 +00:00
|
|
|
const sortBy = (function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
if (!Array.isArray(sort)) return 'implicit';
|
|
|
|
else if (sort[0] === '_score') return 'implicit';
|
|
|
|
else if (sort[0] === timeField) return 'time';
|
|
|
|
else return 'non-time';
|
2018-09-10 08:32:49 +00:00
|
|
|
})();
|
2017-11-25 15:36:39 +00:00
|
|
|
|
|
|
|
let sortFn = null;
|
|
|
|
if (sortBy !== 'implicit') {
|
|
|
|
sortFn = new HitSortFn(sort[1]);
|
|
|
|
}
|
|
|
|
|
2019-01-28 19:53:05 +00:00
|
|
|
$scope.updateTime();
|
|
|
|
|
2018-11-06 15:26:34 +00:00
|
|
|
if (sort[0] === '_score') {
|
|
|
|
segmented.setMaxSegments(1);
|
|
|
|
}
|
|
|
|
|
2018-12-13 10:02:53 +00:00
|
|
|
segmented.setDirection(sortBy === 'time' ? sort[1] || 'desc' : 'desc');
|
2017-11-25 15:36:39 +00:00
|
|
|
segmented.setSortFn(sortFn);
|
|
|
|
segmented.setSize($scope.opts.sampleSize);
|
|
|
|
|
2018-11-06 15:26:34 +00:00
|
|
|
let inspectorRequests = [];
|
|
|
|
function logResponseInInspector(resp) {
|
|
|
|
if (inspectorRequests.length > 0) {
|
|
|
|
const inspectorRequest = inspectorRequests.shift();
|
|
|
|
inspectorRequest
|
|
|
|
.stats(getResponseInspectorStats($scope.searchSource, resp))
|
|
|
|
.ok({ json: resp });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-25 15:36:39 +00:00
|
|
|
// triggered when the status updated
|
2018-12-13 10:02:53 +00:00
|
|
|
segmented.on('status', function(status) {
|
2017-11-25 15:36:39 +00:00
|
|
|
$scope.fetchStatus = status;
|
2018-11-06 15:26:34 +00:00
|
|
|
if (status.complete === 0) {
|
|
|
|
// starting new segmented search request
|
|
|
|
inspectorAdapters.requests.reset();
|
|
|
|
inspectorRequests = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status.remaining > 0) {
|
|
|
|
const inspectorRequest = inspectorAdapters.requests.start(
|
2019-01-28 19:53:05 +00:00
|
|
|
i18n('kbn.discover.inspectorRequest.segmentFetchCompleteStatusTitle', {
|
|
|
|
defaultMessage: 'Segment {fetchCompleteStatus}',
|
|
|
|
values: {
|
|
|
|
fetchCompleteStatus: $scope.fetchStatus.complete,
|
|
|
|
}
|
|
|
|
}),
|
2018-11-06 15:26:34 +00:00
|
|
|
{
|
2019-01-28 19:53:05 +00:00
|
|
|
description: i18n('kbn.discover.inspectorRequest.segmentFetchCompleteStatusDescription', {
|
|
|
|
defaultMessage: 'This request queries Elasticsearch to fetch the data for the search.',
|
|
|
|
}),
|
|
|
|
});
|
2018-11-06 15:26:34 +00:00
|
|
|
inspectorRequest.stats(getRequestInspectorStats($scope.searchSource));
|
|
|
|
$scope.searchSource.getSearchRequestBody().then(body => {
|
|
|
|
inspectorRequest.json(body);
|
|
|
|
});
|
|
|
|
inspectorRequests.push(inspectorRequest);
|
|
|
|
}
|
2017-11-25 15:36:39 +00:00
|
|
|
});
|
|
|
|
|
2018-12-13 10:02:53 +00:00
|
|
|
segmented.on('first', function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
flushResponseData();
|
|
|
|
});
|
|
|
|
|
2018-12-13 10:02:53 +00:00
|
|
|
segmented.on('segment', resp => {
|
2018-11-06 15:26:34 +00:00
|
|
|
logResponseInInspector(resp);
|
2017-11-25 15:36:39 +00:00
|
|
|
if (resp._shards.failed > 0) {
|
|
|
|
$scope.failures = _.union($scope.failures, resp._shards.failures);
|
2018-12-13 10:02:53 +00:00
|
|
|
$scope.failures = _.uniq($scope.failures, false, function(failure) {
|
2017-11-25 15:36:39 +00:00
|
|
|
return failure.index + failure.shard + failure.reason;
|
|
|
|
});
|
|
|
|
}
|
2018-08-21 15:24:57 +00:00
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-12-13 10:02:53 +00:00
|
|
|
segmented.on('emptySegment', function(resp) {
|
2018-11-06 15:26:34 +00:00
|
|
|
logResponseInInspector(resp);
|
|
|
|
});
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
segmented.on('mergedSegment', function(merged) {
|
2017-11-25 15:36:39 +00:00
|
|
|
$scope.mergedEsResp = merged;
|
|
|
|
|
|
|
|
if ($scope.opts.timefield) {
|
2018-11-06 15:26:34 +00:00
|
|
|
const tabifiedData = tabifyAggResponse($scope.vis.aggs, merged);
|
2017-11-25 15:36:39 +00:00
|
|
|
$scope.searchSource.rawResponse = merged;
|
2019-01-28 19:53:05 +00:00
|
|
|
Promise
|
|
|
|
.resolve(responseHandler(tabifiedData))
|
|
|
|
.then(resp => {
|
2018-12-13 10:02:53 +00:00
|
|
|
if (
|
|
|
|
($scope.tabView !== 'panels' ||
|
|
|
|
$location.path().includes('wazuh-discover')) &&
|
|
|
|
$scope.tabView !== 'cluster-monitoring'
|
|
|
|
) {
|
2019-01-28 19:53:05 +00:00
|
|
|
visualizeHandler.render(resp);
|
2018-12-13 10:02:53 +00:00
|
|
|
}
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.hits = merged.hits.total;
|
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
const indexPattern = $scope.searchSource.getField('index');
|
2017-11-25 15:36:39 +00:00
|
|
|
|
|
|
|
// the merge rows, use a new array to help watchers
|
|
|
|
$scope.rows = merged.hits.hits.slice();
|
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
let counts = $scope.fieldCounts;
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
// if we haven't counted yet, or need a fresh count because we are sorting, reset the counts
|
|
|
|
if (!counts || sortFn) counts = $scope.fieldCounts = {};
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.rows.forEach(function(hit) {
|
2018-08-21 15:24:57 +00:00
|
|
|
// skip this work if we have already done it
|
|
|
|
if (hit.$$_counted) return;
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
// when we are sorting results, we need to redo the counts each time because the
|
|
|
|
// "top 500" may change with each response, so don't mark this as counted
|
|
|
|
if (!sortFn) hit.$$_counted = true;
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
const fields = _.keys(indexPattern.flattenHit(hit));
|
|
|
|
let n = fields.length;
|
|
|
|
let field;
|
2018-12-13 10:02:53 +00:00
|
|
|
while ((field = fields[--n])) {
|
2018-09-10 08:32:49 +00:00
|
|
|
// eslint-disable-line
|
2018-08-21 15:24:57 +00:00
|
|
|
if (counts[field]) counts[field] += 1;
|
|
|
|
else counts[field] = 1;
|
|
|
|
}
|
2017-11-25 15:36:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
segmented.on('complete', function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
if ($scope.fetchStatus.hitCount === 0) {
|
|
|
|
flushResponseData();
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.fetchStatus = null;
|
|
|
|
});
|
2017-12-14 12:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function beginSegmentedFetch() {
|
2018-12-13 10:02:53 +00:00
|
|
|
$scope.searchSource
|
|
|
|
.onBeginSegmentedFetch(handleSegmentedFetch)
|
2018-09-10 08:32:49 +00:00
|
|
|
.catch(error => {
|
2018-08-21 15:24:57 +00:00
|
|
|
const fetchError = getPainlessError(error);
|
|
|
|
|
|
|
|
if (fetchError) {
|
|
|
|
$scope.fetchError = fetchError;
|
|
|
|
} else {
|
|
|
|
notify.error(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restart. This enables auto-refresh functionality.
|
2017-12-14 12:28:31 +00:00
|
|
|
beginSegmentedFetch();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
beginSegmentedFetch();
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.updateTime = function() {
|
2018-01-09 18:53:42 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
/////////////////////////////// WAZUH ///////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2018-09-10 08:32:49 +00:00
|
|
|
if ($location.search().tab != 'configuration') {
|
2018-05-15 12:01:26 +00:00
|
|
|
loadedVisualizations.removeAll();
|
2018-01-14 13:08:38 +00:00
|
|
|
$rootScope.rendered = false;
|
2018-09-10 08:32:49 +00:00
|
|
|
$rootScope.loadingStatus = 'Fetching data...';
|
2018-01-14 13:08:38 +00:00
|
|
|
}
|
2018-01-09 18:53:42 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
2018-05-15 11:32:57 +00:00
|
|
|
|
2017-11-25 15:36:39 +00:00
|
|
|
$scope.timeRange = {
|
2018-08-21 15:24:57 +00:00
|
|
|
from: dateMath.parse(timefilter.getTime().from),
|
|
|
|
to: dateMath.parse(timefilter.getTime().to, { roundUp: true })
|
2017-11-25 15:36:39 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.resetQuery = function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
kbnUrl.change('/discover/{{id}}', { id: $route.current.params.id });
|
|
|
|
};
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.newQuery = function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
kbnUrl.change('/discover');
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.updateDataSource = Promise.method(function updateDataSource() {
|
|
|
|
$scope.searchSource
|
2018-08-21 15:24:57 +00:00
|
|
|
.setField('size', $scope.opts.sampleSize)
|
|
|
|
.setField('sort', getSort($state.sort, $scope.indexPattern))
|
|
|
|
.setField('query', !$state.query ? null : $state.query)
|
|
|
|
.setField('filter', queryFilter.getFilters());
|
2017-11-25 15:36:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$scope.setSortOrder = function setSortOrder(columnName, direction) {
|
|
|
|
$scope.state.sort = [columnName, direction];
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: On array fields, negating does not negate the combination, rather all terms
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.filterQuery = function(field, values, operation) {
|
2018-12-12 15:38:38 +00:00
|
|
|
// Commented due to https://github.com/elastic/kibana/issues/22426
|
|
|
|
//$scope.indexPattern.popularizeField(field, 1);
|
2018-09-10 08:32:49 +00:00
|
|
|
filterActions.addFilter(
|
|
|
|
field,
|
|
|
|
values,
|
|
|
|
operation,
|
|
|
|
$scope.indexPattern.id,
|
|
|
|
$scope.state,
|
|
|
|
filterManager
|
|
|
|
);
|
2017-11-25 15:36:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addColumn = function addColumn(columnName) {
|
2018-12-12 15:38:38 +00:00
|
|
|
// Commented due to https://github.com/elastic/kibana/issues/22426
|
|
|
|
//$scope.indexPattern.popularizeField(columnName, 1);
|
2017-11-25 15:36:39 +00:00
|
|
|
columnActions.addColumn($scope.state.columns, columnName);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeColumn = function removeColumn(columnName) {
|
2018-12-12 15:38:38 +00:00
|
|
|
// Commented due to https://github.com/elastic/kibana/issues/22426
|
|
|
|
//$scope.indexPattern.popularizeField(columnName, 1);
|
2017-11-25 15:36:39 +00:00
|
|
|
columnActions.removeColumn($scope.state.columns, columnName);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.moveColumn = function moveColumn(columnName, newIndex) {
|
|
|
|
columnActions.moveColumn($scope.state.columns, columnName, newIndex);
|
|
|
|
};
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.scrollToTop = function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
$window.scrollTo(0, 0);
|
|
|
|
};
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.scrollToBottom = function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
// delay scrolling to after the rows have been rendered
|
|
|
|
$timeout(() => {
|
|
|
|
$element.find('#discoverBottomMarker').focus();
|
|
|
|
}, 0);
|
|
|
|
};
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
$scope.showAllRows = function() {
|
2017-11-25 15:36:39 +00:00
|
|
|
$scope.minimumVisibleRows = $scope.hits;
|
|
|
|
};
|
|
|
|
|
|
|
|
function setupVisualization() {
|
2017-12-14 12:28:31 +00:00
|
|
|
// If no timefield has been specified we don't create a histogram of messages
|
|
|
|
if (!$scope.opts.timefield) return;
|
2017-11-25 15:36:39 +00:00
|
|
|
|
|
|
|
const visStateAggs = [
|
|
|
|
{
|
|
|
|
type: 'count',
|
|
|
|
schema: 'metric'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'date_histogram',
|
|
|
|
schema: 'segment',
|
|
|
|
params: {
|
|
|
|
field: $scope.opts.timefield,
|
2018-11-06 15:26:34 +00:00
|
|
|
interval: $state.interval,
|
|
|
|
timeRange: timefilter.getTime()
|
2017-11-25 15:36:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2019-01-28 19:53:05 +00:00
|
|
|
console.log('DEBUG SCOPE.VIS',$scope.vis)
|
2017-11-25 15:36:39 +00:00
|
|
|
// we have a vis, just modify the aggs
|
|
|
|
if ($scope.vis) {
|
|
|
|
const visState = $scope.vis.getEnabledState();
|
|
|
|
visState.aggs = visStateAggs;
|
|
|
|
|
|
|
|
$scope.vis.setState(visState);
|
2019-01-28 19:53:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const visSavedObject = {
|
|
|
|
indexPattern: $scope.indexPattern.id,
|
|
|
|
visState: {
|
2017-12-14 12:28:31 +00:00
|
|
|
type: 'histogram',
|
2019-01-28 19:53:05 +00:00
|
|
|
title: savedSearch.title,
|
2017-12-14 12:28:31 +00:00
|
|
|
params: {
|
|
|
|
addLegend: false,
|
|
|
|
addTimeMarker: true
|
|
|
|
},
|
|
|
|
aggs: visStateAggs
|
2019-01-28 19:53:05 +00:00
|
|
|
}
|
|
|
|
};
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2019-01-28 19:53:05 +00:00
|
|
|
console.log($scope.searchSource.getField('index'))
|
|
|
|
$scope.vis = new Vis(
|
|
|
|
$scope.searchSource.getField('index'),
|
|
|
|
visSavedObject.visState
|
|
|
|
);
|
|
|
|
visSavedObject.vis = $scope.vis;
|
|
|
|
console.log(visSavedObject)
|
|
|
|
$scope.searchSource.onRequestStart((searchSource, searchRequest) => {
|
|
|
|
return $scope.vis
|
|
|
|
.getAggConfig()
|
|
|
|
.onSearchRequestStart(searchSource, searchRequest);
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2019-01-28 19:53:05 +00:00
|
|
|
$scope.searchSource.setField('aggs', function() {
|
|
|
|
//////////////////// WAZUH ////////////////////////////////
|
|
|
|
// Old code: //
|
|
|
|
// return $scope.vis.getAggConfig().toDsl(); //
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
const result = $scope.vis.getAggConfig().toDsl();
|
|
|
|
if (
|
|
|
|
result[2] &&
|
|
|
|
result[2].date_histogram &&
|
|
|
|
result[2].date_histogram.interval === '0ms'
|
|
|
|
) {
|
|
|
|
result[2].date_histogram.interval = '1d';
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
});
|
|
|
|
|
|
|
|
$timeout(async () => {
|
|
|
|
try {
|
|
|
|
console.log('ENTERING HERE',$scope.vis)
|
|
|
|
const visEl = $element.find('#discoverHistogram')[0];
|
|
|
|
visualizeHandler = await visualizeLoader.embedVisualizationWithSavedObject(visEl, visSavedObject, {
|
|
|
|
autoFetch: false,
|
2017-12-14 12:28:31 +00:00
|
|
|
});
|
2019-01-28 19:53:05 +00:00
|
|
|
}catch(error) {
|
|
|
|
console.log(error.message)
|
|
|
|
}
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function resolveIndexPatternLoading() {
|
2018-08-21 15:24:57 +00:00
|
|
|
const {
|
|
|
|
loaded: loadedIndexPattern,
|
|
|
|
stateVal,
|
2018-09-10 08:32:49 +00:00
|
|
|
stateValFound
|
2018-08-21 15:24:57 +00:00
|
|
|
} = $route.current.locals.ip;
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
const ownIndexPattern = $scope.searchSource.getOwnField('index');
|
|
|
|
|
|
|
|
if (ownIndexPattern && !stateVal) {
|
|
|
|
return ownIndexPattern;
|
|
|
|
}
|
2017-11-25 15:36:39 +00:00
|
|
|
|
|
|
|
if (stateVal && !stateValFound) {
|
2019-01-28 19:53:05 +00:00
|
|
|
const warningTitle = i18n('kbn.discover.valueIsNotConfiguredIndexPatternIDWarningTitle', {
|
|
|
|
defaultMessage: '{stateVal} is not a configured index pattern ID',
|
|
|
|
values: {
|
|
|
|
stateVal: `"${stateVal}"`,
|
|
|
|
},
|
|
|
|
});
|
2018-08-21 15:24:57 +00:00
|
|
|
|
|
|
|
if (ownIndexPattern) {
|
|
|
|
toastNotifications.addWarning({
|
|
|
|
title: warningTitle,
|
2019-01-28 19:53:05 +00:00
|
|
|
text: i18n('kbn.discover.showingSavedIndexPatternWarningDescription', {
|
|
|
|
defaultMessage: 'Showing the saved index pattern: "{ownIndexPatternTitle}" ({ownIndexPatternId})',
|
|
|
|
values: {
|
|
|
|
ownIndexPatternTitle: ownIndexPattern.title,
|
|
|
|
ownIndexPatternId: ownIndexPattern.id,
|
|
|
|
},
|
|
|
|
}),
|
2018-08-21 15:24:57 +00:00
|
|
|
});
|
|
|
|
return ownIndexPattern;
|
2017-11-25 15:36:39 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
toastNotifications.addWarning({
|
|
|
|
title: warningTitle,
|
2019-01-28 19:53:05 +00:00
|
|
|
text: i18n('kbn.discover.showingDefaultIndexPatternWarningDescription', {
|
|
|
|
defaultMessage: 'Showing the default index pattern: "{loadedIndexPatternTitle}" ({loadedIndexPatternId})',
|
|
|
|
values: {
|
|
|
|
loadedIndexPatternTitle: loadedIndexPattern.title,
|
|
|
|
loadedIndexPatternId: loadedIndexPattern.id,
|
|
|
|
},
|
|
|
|
}),
|
2018-08-21 15:24:57 +00:00
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
}
|
2018-08-21 15:24:57 +00:00
|
|
|
|
|
|
|
return loadedIndexPattern;
|
2017-11-25 15:36:39 +00:00
|
|
|
}
|
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
// Block the UI from loading if the user has loaded a rollup index pattern but it isn't
|
|
|
|
// supported.
|
2019-01-28 19:53:05 +00:00
|
|
|
$scope.isUnsupportedIndexPattern = (
|
|
|
|
!isDefaultTypeIndexPattern($route.current.locals.ip.loaded)
|
|
|
|
&& !hasSearchStategyForIndexPattern($route.current.locals.ip.loaded)
|
|
|
|
);
|
2018-08-21 15:24:57 +00:00
|
|
|
|
|
|
|
if ($scope.isUnsupportedIndexPattern) {
|
|
|
|
$scope.unsupportedIndexPatternType = $route.current.locals.ip.loaded.type;
|
|
|
|
return;
|
|
|
|
}
|
2018-09-10 08:32:49 +00:00
|
|
|
|
2018-08-21 15:24:57 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
2017-11-29 10:02:34 +00:00
|
|
|
////////////////////////////////////////////////////// WAZUH //////////////////////////////////////////////////////////
|
2017-11-25 15:36:39 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-16 11:38:55 +00:00
|
|
|
const loadFilters = (wzCurrentFilters, localChange) => {
|
2018-05-14 15:12:10 +00:00
|
|
|
const appState = getAppState();
|
2018-09-10 08:32:49 +00:00
|
|
|
if (!appState || !globalState) {
|
|
|
|
$timeout(100).then(() => {
|
2018-06-25 10:16:49 +00:00
|
|
|
return loadFilters(wzCurrentFilters);
|
|
|
|
});
|
2018-05-14 15:12:10 +00:00
|
|
|
} else {
|
2018-05-16 11:38:55 +00:00
|
|
|
$state.filters = localChange ? $state.filters : [];
|
2018-04-12 10:41:13 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
queryFilter
|
|
|
|
.addFilters(wzCurrentFilters)
|
|
|
|
.then(() => {})
|
|
|
|
.catch(error => console.log(error.message || error)); // eslint-disable-line
|
2017-11-28 16:37:31 +00:00
|
|
|
}
|
2018-06-25 10:16:49 +00:00
|
|
|
};
|
2017-11-25 15:36:39 +00:00
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
const wzEventFiltersListener = $rootScope.$on(
|
|
|
|
'wzEventFilters',
|
|
|
|
(evt, parameters) => {
|
|
|
|
loadFilters(parameters.filters, parameters.localChange);
|
|
|
|
}
|
|
|
|
);
|
2018-05-15 15:32:29 +00:00
|
|
|
|
2018-06-25 10:16:49 +00:00
|
|
|
$scope.tabView = $location.search().tabView || 'panels';
|
2018-09-10 08:32:49 +00:00
|
|
|
const changeTabViewListener = $rootScope.$on(
|
|
|
|
'changeTabView',
|
|
|
|
(evt, parameters) => {
|
|
|
|
$scope.tabView = parameters.tabView || 'panels';
|
|
|
|
$scope.updateQueryAndFetch($state.query);
|
|
|
|
}
|
|
|
|
);
|
2018-05-18 08:21:53 +00:00
|
|
|
|
|
|
|
$scope.$on('$destroy', () => {
|
2018-06-25 10:16:49 +00:00
|
|
|
wzEventFiltersListener();
|
|
|
|
changeTabViewListener();
|
|
|
|
});
|
2017-11-25 15:36:39 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
init();
|
2017-12-14 12:28:31 +00:00
|
|
|
}
|