Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
angorayc committed Sep 10, 2020
1 parent d1638e2 commit 7e183e6
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 720 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ export const hostDetails: SecuritySolutionFactory<HostsQueries.details> = {
response: [inspectStringifyObject(response)],
};
const formattedHostItem = formatHostItem(aggregations);
console.log('-------------');
console.log(JSON.stringify(options));
console.log('------2-------');
console.log(JSON.stringify(response));
console.log('------3-------');
console.log(JSON.stringify({ ...response, inspect, hostDetails: formattedHostItem }));

return { ...response, inspect, hostDetails: formattedHostItem };
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { buildQuery } from './query.dsl';
import { mockOptions, expectedDsl } from '../__mocks__/';
import { buildHostDetailsQuery as buildQuery } from './query.host_details.dsl';
import { mockOptions, expectedDsl } from './__mocks__/';

describe('buildQuery', () => {
test('build query from options correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export const buildHostDetailsQuery = ({
track_total_hits: false,
},
};
console.log('----dsl----');
console.log(JSON.stringify(dslQuery));

return dslQuery;
};

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { MatrixHistogramType } from '../../../../../../../common/search_strategy';

export const mockOptions = {
filterQuery: '{"bool":{"must":[],"filter":[{"match_all":{}}],"should":[],"must_not":[]}}',
timerange: { from: '2020-09-08T13:32:02.875Z', to: '2020-09-09T13:32:02.875Z' },
defaultIndex: [
'apm-*-transaction*',
'auditbeat-*',
Expand All @@ -16,6 +16,10 @@ export const mockOptions = {
'packetbeat-*',
'winlogbeat-*',
],
filterQuery:
'{"bool":{"must":[],"filter":[{"match_all":{}},{"bool":{"filter":[{"bool":{"should":[{"exists":{"field":"host.name"}}],"minimum_should_match":1}}]}}],"should":[],"must_not":[]}}',
histogramType: MatrixHistogramType.alerts,
timerange: { interval: '12h', from: '2020-09-08T14:23:04.482Z', to: '2020-09-09T14:23:04.482Z' },
stackByField: 'event.module',
};

Expand Down Expand Up @@ -46,7 +50,7 @@ export const expectedDsl = {
field: '@timestamp',
fixed_interval: '2700000ms',
min_doc_count: 0,
extended_bounds: { min: 1599571922875, max: 1599658322875 },
extended_bounds: { min: 1599574984482, max: 1599661384482 },
},
},
},
Expand All @@ -55,7 +59,7 @@ export const expectedDsl = {
query: {
bool: {
filter: [
'{"bool":{"must":[],"filter":[{"match_all":{}}],"should":[],"must_not":[]}}',
'{"bool":{"must":[],"filter":[{"match_all":{}},{"bool":{"filter":[{"bool":{"should":[{"exists":{"field":"host.name"}}],"minimum_should_match":1}}]}}],"should":[],"must_not":[]}}',
{
bool: {
filter: [
Expand All @@ -68,8 +72,8 @@ export const expectedDsl = {
{
range: {
'@timestamp': {
gte: '2020-09-08T13:32:02.875Z',
lte: '2020-09-09T13:32:02.875Z',
gte: '2020-09-08T14:23:04.482Z',
lte: '2020-09-09T14:23:04.482Z',
format: 'strict_date_optional_time',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { MatrixHistogramType } from '../../../../../../../common/search_strategy';

export const mockOptions = {
filterQuery:
'{"bool":{"must":[],"filter":[{"match_all":{}},{"bool":{"should":[],"minimum_should_match":1}},{"match_phrase":{"result_type":"record"}},null,{"range":{"record_score":{"gte":50}}}],"should":[],"must_not":[]}}',
timerange: { from: '2020-09-08T13:51:04.932Z', to: '2020-09-09T13:51:04.933Z' },
defaultIndex: [
'apm-*-transaction*',
'auditbeat-*',
Expand All @@ -17,6 +16,10 @@ export const mockOptions = {
'packetbeat-*',
'winlogbeat-*',
],
filterQuery:
'{"bool":{"must":[],"filter":[{"match_all":{}},{"bool":{"should":[],"minimum_should_match":1}},{"match_phrase":{"result_type":"record"}},null,{"range":{"record_score":{"gte":50}}}],"should":[{"exists":{"field":"source.ip"}},{"exists":{"field":"destination.ip"}}],"must_not":[],"minimum_should_match":1}}',
histogramType: MatrixHistogramType.anomalies,
timerange: { interval: '12h', from: '2020-09-08T15:14:35.566Z', to: '2020-09-09T15:14:35.566Z' },
stackByField: 'job_id',
};

Expand All @@ -42,7 +45,7 @@ export const expectedDsl = {
field: 'timestamp',
fixed_interval: '2700000ms',
min_doc_count: 0,
extended_bounds: { min: 1599573064932, max: 1599659464933 },
extended_bounds: { min: 1599578075566, max: 1599664475566 },
},
},
},
Expand All @@ -51,12 +54,12 @@ export const expectedDsl = {
query: {
bool: {
filter: [
'{"bool":{"must":[],"filter":[{"match_all":{}},{"bool":{"should":[],"minimum_should_match":1}},{"match_phrase":{"result_type":"record"}},null,{"range":{"record_score":{"gte":50}}}],"should":[],"must_not":[]}}',
'{"bool":{"must":[],"filter":[{"match_all":{}},{"bool":{"should":[],"minimum_should_match":1}},{"match_phrase":{"result_type":"record"}},null,{"range":{"record_score":{"gte":50}}}],"should":[{"exists":{"field":"source.ip"}},{"exists":{"field":"destination.ip"}}],"must_not":[],"minimum_should_match":1}}',
{
range: {
timestamp: {
gte: '2020-09-08T13:51:04.932Z',
lte: '2020-09-09T13:51:04.933Z',
gte: '2020-09-08T15:14:35.566Z',
lte: '2020-09-09T15:14:35.566Z',
format: 'strict_date_optional_time',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { MatrixHistogramType } from '../../../../../../../common/search_strategy';

export const mockOptions = {
filterQuery: '{"bool":{"must":[],"filter":[{"match_all":{}}],"should":[],"must_not":[]}}',
timerange: { from: '2020-09-08T14:03:36.140Z', to: '2020-09-09T14:03:36.140Z' },
defaultIndex: [
'apm-*-transaction*',
'auditbeat-*',
Expand All @@ -16,6 +16,9 @@ export const mockOptions = {
'packetbeat-*',
'winlogbeat-*',
],
filterQuery: '{"bool":{"must":[],"filter":[{"match_all":{}}],"should":[],"must_not":[]}}',
histogramType: MatrixHistogramType.authentications,
timerange: { interval: '12h', from: '2020-09-08T15:22:00.325Z', to: '2020-09-09T15:22:00.325Z' },
stackByField: 'event.outcome',
};

Expand Down Expand Up @@ -46,7 +49,7 @@ export const expectedDsl = {
field: '@timestamp',
fixed_interval: '2700000ms',
min_doc_count: 0,
extended_bounds: { min: 1599573816140, max: 1599660216140 },
extended_bounds: { min: 1599578520325, max: 1599664920325 },
},
},
},
Expand All @@ -60,8 +63,8 @@ export const expectedDsl = {
{
range: {
'@timestamp': {
gte: '2020-09-08T14:03:36.140Z',
lte: '2020-09-09T14:03:36.140Z',
gte: '2020-09-08T15:22:00.325Z',
lte: '2020-09-09T15:22:00.325Z',
format: 'strict_date_optional_time',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { MatrixHistogramType } from '../../../../../../../common/search_strategy';

export const mockOptions = {
filterQuery: '{"bool":{"must":[],"filter":[{"match_all":{}}],"should":[],"must_not":[]}}',
timerange: { from: '2020-09-08T14:18:23.719Z', to: '2020-09-09T14:18:23.719Z' },
defaultIndex: [
'apm-*-transaction*',
'auditbeat-*',
Expand All @@ -16,6 +16,9 @@ export const mockOptions = {
'packetbeat-*',
'winlogbeat-*',
],
filterQuery: '{"bool":{"must":[],"filter":[{"match_all":{}}],"should":[],"must_not":[]}}',
histogramType: MatrixHistogramType.dns,
timerange: { interval: '12h', from: '2020-09-08T15:41:15.528Z', to: '2020-09-09T15:41:15.529Z' },
stackByField: 'dns.question.registered_domain',
};

Expand Down Expand Up @@ -54,8 +57,8 @@ export const expectedDsl = {
{
range: {
'@timestamp': {
gte: '2020-09-08T14:18:23.719Z',
lte: '2020-09-09T14:18:23.719Z',
gte: '2020-09-08T15:41:15.528Z',
lte: '2020-09-09T15:41:15.529Z',
format: 'strict_date_optional_time',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const mockOptions = {
filterQuery: '{"bool":{"must":[],"filter":[{"match_all":{}}],"should":[],"must_not":[]}}',
timerange: { from: '2020-09-08T14:23:04.482Z', to: '2020-09-09T14:23:04.482Z' },
import {
MatrixHistogramQuery,
MatrixHistogramRequestOptions,
MatrixHistogramType,
} from '../../../../../../../common/search_strategy';

export const mockOptions: MatrixHistogramRequestOptions = {
defaultIndex: [
'apm-*-transaction*',
'auditbeat-*',
Expand All @@ -16,6 +20,10 @@ export const mockOptions = {
'packetbeat-*',
'winlogbeat-*',
],
factoryQueryType: MatrixHistogramQuery,
filterQuery: '{"bool":{"must":[],"filter":[{"match_all":{}}],"should":[],"must_not":[]}}',
histogramType: MatrixHistogramType.events,
timerange: { interval: '12h', from: '2020-09-08T16:11:26.215Z', to: '2020-09-09T16:11:26.215Z' },
stackByField: 'event.action',
};

Expand Down Expand Up @@ -46,7 +54,7 @@ export const expectedDsl = {
field: '@timestamp',
fixed_interval: '2700000ms',
min_doc_count: 0,
extended_bounds: { min: 1599574984482, max: 1599661384482 },
extended_bounds: { min: 1599581486215, max: 1599667886215 },
},
},
},
Expand All @@ -59,8 +67,8 @@ export const expectedDsl = {
{
range: {
'@timestamp': {
gte: '2020-09-08T14:23:04.482Z',
lte: '2020-09-09T14:23:04.482Z',
gte: '2020-09-08T16:11:26.215Z',
lte: '2020-09-09T16:11:26.215Z',
format: 'strict_date_optional_time',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { eventsMatrixHistogramConfig } from '.';
import { buildEventsHistogramQuery } from './query.events_histogram.dsl.ts';
import { buildEventsHistogramQuery } from './query.events_histogram.dsl';

jest.mock('./query.events_histogram.dsl.ts', () => ({
buildEventsHistogramQuery: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { buildEventsHistogramQuery } from './query.events_histogram.dsl.ts';
import { buildEventsHistogramQuery } from './query.events_histogram.dsl';
import { mockOptions, expectedDsl } from './__mocks__/';

describe('buildEventsHistogramQuery', () => {
Expand Down
Loading

0 comments on commit 7e183e6

Please sign in to comment.