Skip to content

Commit ccf48e9

Browse files
[Security Solution] Refactor NetworkDns to use Search Strategy (#76250) (#76870)
1 parent 2bdeb7c commit ccf48e9

File tree

13 files changed

+600
-231
lines changed

13 files changed

+600
-231
lines changed

x-pack/plugins/security_solution/common/search_strategy/security_solution/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
} from './hosts';
2222
import {
2323
NetworkQueries,
24+
NetworkDnsStrategyResponse,
25+
NetworkDnsRequestOptions,
2426
NetworkTlsStrategyResponse,
2527
NetworkTlsRequestOptions,
2628
NetworkHttpStrategyResponse,
@@ -79,10 +81,12 @@ export type StrategyResponseType<T extends FactoryQueryTypes> = T extends HostsQ
7981
? HostFirstLastSeenStrategyResponse
8082
: T extends HostsQueries.uncommonProcesses
8183
? HostUncommonProcessesStrategyResponse
82-
: T extends NetworkQueries.tls
83-
? NetworkTlsStrategyResponse
84+
: T extends NetworkQueries.dns
85+
? NetworkDnsStrategyResponse
8486
: T extends NetworkQueries.http
8587
? NetworkHttpStrategyResponse
88+
: T extends NetworkQueries.tls
89+
? NetworkTlsStrategyResponse
8690
: T extends NetworkQueries.topCountries
8791
? NetworkTopCountriesStrategyResponse
8892
: T extends NetworkQueries.topNFlow
@@ -101,10 +105,12 @@ export type StrategyRequestType<T extends FactoryQueryTypes> = T extends HostsQu
101105
? HostFirstLastSeenRequestOptions
102106
: T extends HostsQueries.uncommonProcesses
103107
? HostUncommonProcessesRequestOptions
104-
: T extends NetworkQueries.tls
105-
? NetworkTlsRequestOptions
108+
: T extends NetworkQueries.dns
109+
? NetworkDnsRequestOptions
106110
: T extends NetworkQueries.http
107111
? NetworkHttpRequestOptions
112+
: T extends NetworkQueries.tls
113+
? NetworkTlsRequestOptions
108114
: T extends NetworkQueries.topCountries
109115
? NetworkTopCountriesRequestOptions
110116
: T extends NetworkQueries.topNFlow
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { IEsSearchResponse } from '../../../../../../../../src/plugins/data/common';
8+
import { CursorType, Inspect, Maybe, PageInfoPaginated, SortField } from '../../../common';
9+
import { RequestOptionsPaginated } from '../..';
10+
11+
export enum NetworkDnsFields {
12+
dnsName = 'dnsName',
13+
queryCount = 'queryCount',
14+
uniqueDomains = 'uniqueDomains',
15+
dnsBytesIn = 'dnsBytesIn',
16+
dnsBytesOut = 'dnsBytesOut',
17+
}
18+
19+
export interface NetworkDnsRequestOptions extends RequestOptionsPaginated {
20+
isPtrIncluded: boolean;
21+
sort: SortField<NetworkDnsFields>;
22+
stackByField?: Maybe<string>;
23+
}
24+
25+
export interface NetworkDnsStrategyResponse extends IEsSearchResponse {
26+
edges: NetworkDnsEdges[];
27+
totalCount: number;
28+
pageInfo: PageInfoPaginated;
29+
inspect?: Maybe<Inspect>;
30+
histogram?: Maybe<MatrixOverOrdinalHistogramData[]>;
31+
}
32+
33+
export interface NetworkDnsEdges {
34+
node: NetworkDnsItem;
35+
cursor: CursorType;
36+
}
37+
38+
export interface NetworkDnsItem {
39+
_id?: Maybe<string>;
40+
dnsBytesIn?: Maybe<number>;
41+
dnsBytesOut?: Maybe<number>;
42+
dnsName?: Maybe<string>;
43+
queryCount?: Maybe<number>;
44+
uniqueDomains?: Maybe<number>;
45+
}
46+
47+
export interface MatrixOverOrdinalHistogramData {
48+
x: string;
49+
y: number;
50+
g: string;
51+
}
52+
53+
export interface NetworkDnsBuckets {
54+
key: string;
55+
doc_count: number;
56+
unique_domains: {
57+
value: number;
58+
};
59+
dns_bytes_in: {
60+
value: number;
61+
};
62+
dns_bytes_out: {
63+
value: number;
64+
};
65+
}

x-pack/plugins/security_solution/common/search_strategy/security_solution/network/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
*/
66

77
export * from './common';
8+
export * from './dns';
89
export * from './http';
910
export * from './tls';
1011
export * from './top_countries';
1112
export * from './top_n_flow';
1213

1314
export enum NetworkQueries {
15+
dns = 'dns',
1416
http = 'http',
1517
tls = 'tls',
1618
topCountries = 'topCountries',

x-pack/plugins/security_solution/common/search_strategy/security_solution/network/top_countries/index.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ import {
1414
TopNetworkTablesEcsField,
1515
} from '../common';
1616

17-
export enum NetworkDnsFields {
18-
dnsName = 'dnsName',
19-
queryCount = 'queryCount',
20-
uniqueDomains = 'uniqueDomains',
21-
dnsBytesIn = 'dnsBytesIn',
22-
dnsBytesOut = 'dnsBytesOut',
23-
}
24-
2517
export enum FlowTarget {
2618
client = 'client',
2719
destination = 'destination',
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React from 'react';
8+
import { connect } from 'react-redux';
9+
import { compose } from 'redux';
10+
import { DocumentNode } from 'graphql';
11+
import { ScaleType } from '@elastic/charts';
12+
13+
import { MatrixHistogram } from '../../../common/components/matrix_histogram';
14+
import {
15+
MatrixHistogramOption,
16+
GetSubTitle,
17+
} from '../../../common/components/matrix_histogram/types';
18+
import { UpdateDateRange } from '../../../common/components/charts/common';
19+
import { GlobalTimeArgs } from '../../../common/containers/use_global_time';
20+
import { withKibana } from '../../../common/lib/kibana';
21+
import { QueryTemplatePaginatedProps } from '../../../common/containers/query_template_paginated';
22+
import { DEFAULT_TABLE_ACTIVE_PAGE, DEFAULT_TABLE_LIMIT } from '../../../common/store/constants';
23+
import { networkModel, networkSelectors } from '../../store';
24+
import { State, inputsSelectors } from '../../../common/store';
25+
26+
export const HISTOGRAM_ID = 'networkDnsHistogramQuery';
27+
28+
interface DnsHistogramOwnProps extends QueryTemplatePaginatedProps {
29+
dataKey: string | string[];
30+
defaultStackByOption: MatrixHistogramOption;
31+
errorMessage: string;
32+
isDnsHistogram?: boolean;
33+
query: DocumentNode;
34+
scaleType: ScaleType;
35+
setQuery: GlobalTimeArgs['setQuery'];
36+
showLegend?: boolean;
37+
stackByOptions: MatrixHistogramOption[];
38+
subtitle?: string | GetSubTitle;
39+
title: string;
40+
type: networkModel.NetworkType;
41+
updateDateRange: UpdateDateRange;
42+
yTickFormatter?: (value: number) => string;
43+
}
44+
45+
const makeMapHistogramStateToProps = () => {
46+
const getNetworkDnsSelector = networkSelectors.dnsSelector();
47+
const getQuery = inputsSelectors.globalQueryByIdSelector();
48+
const mapStateToProps = (state: State, { id = HISTOGRAM_ID }: DnsHistogramOwnProps) => {
49+
const { isInspected } = getQuery(state, id);
50+
return {
51+
...getNetworkDnsSelector(state),
52+
activePage: DEFAULT_TABLE_ACTIVE_PAGE,
53+
limit: DEFAULT_TABLE_LIMIT,
54+
isInspected,
55+
id,
56+
};
57+
};
58+
59+
return mapStateToProps;
60+
};
61+
62+
export const NetworkDnsHistogramQuery = compose<React.ComponentClass<DnsHistogramOwnProps>>(
63+
connect(makeMapHistogramStateToProps),
64+
withKibana
65+
)(MatrixHistogram);

0 commit comments

Comments
 (0)