Skip to content

Commit

Permalink
[Security Solution] Refactor Hosts Kpi to use Search Strategy (#77606)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykkopycinski authored Sep 22, 2020
1 parent c63ee1b commit c03c7b3
Show file tree
Hide file tree
Showing 60 changed files with 1,663 additions and 842 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './authentications';
export * from './common';
export * from './details';
export * from './first_last_seen';
export * from './kpi';
export * from './overview';
export * from './uncommon_processes';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { IEsSearchResponse } from '../../../../../../../../../src/plugins/data/common';
import { Inspect, Maybe } from '../../../../common';
import { RequestBasicOptions } from '../../..';
import { HostsKpiHistogramData } from '../common';

export interface HostsKpiAuthenticationsHistogramCount {
doc_count: number;
}

export type HostsKpiAuthenticationsRequestOptions = RequestBasicOptions;

export interface HostsKpiAuthenticationsStrategyResponse extends IEsSearchResponse {
authenticationsSuccess: Maybe<number>;
authenticationsSuccessHistogram: Maybe<HostsKpiHistogramData[]>;
authenticationsFailure: Maybe<number>;
authenticationsFailureHistogram: Maybe<HostsKpiHistogramData[]>;
inspect?: Maybe<Inspect>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { Maybe } from '../../../../common';

export interface HostsKpiHistogramData {
x?: Maybe<number>;
y?: Maybe<number>;
}

export interface HostsKpiHistogram<T> {
key_as_string: string;
key: number;
doc_count: number;
count: T;
}

export interface HostsKpiGeneralHistogramCount {
value: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { IEsSearchResponse } from '../../../../../../../../../src/plugins/data/common';
import { Inspect, Maybe } from '../../../../common';
import { RequestBasicOptions } from '../../..';
import { HostsKpiHistogramData } from '../common';

export type HostsKpiHostsRequestOptions = RequestBasicOptions;

export interface HostsKpiHostsStrategyResponse extends IEsSearchResponse {
hosts: Maybe<number>;
hostsHistogram: Maybe<HostsKpiHistogramData[]>;
inspect?: Maybe<Inspect>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export * from './authentications';
export * from './common';
export * from './hosts';
export * from './unique_ips';

import { HostsKpiAuthenticationsStrategyResponse } from './authentications';
import { HostsKpiHostsStrategyResponse } from './hosts';
import { HostsKpiUniqueIpsStrategyResponse } from './unique_ips';

export enum HostsKpiQueries {
kpiAuthentications = 'hostsKpiAuthentications',
kpiHosts = 'hostsKpiHosts',
kpiUniqueIps = 'hostsKpiUniqueIps',
}

export type HostsKpiStrategyResponse =
| Omit<HostsKpiAuthenticationsStrategyResponse, 'rawResponse'>
| Omit<HostsKpiHostsStrategyResponse, 'rawResponse'>
| Omit<HostsKpiUniqueIpsStrategyResponse, 'rawResponse'>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { IEsSearchResponse } from '../../../../../../../../../src/plugins/data/common';
import { Inspect, Maybe } from '../../../../common';
import { RequestBasicOptions } from '../../..';
import { HostsKpiHistogramData } from '../common';

export type HostsKpiUniqueIpsRequestOptions = RequestBasicOptions;

export interface HostsKpiUniqueIpsStrategyResponse extends IEsSearchResponse {
uniqueSourceIps: Maybe<number>;
uniqueSourceIpsHistogram: Maybe<HostsKpiHistogramData[]>;
uniqueDestinationIps: Maybe<number>;
uniqueDestinationIpsHistogram: Maybe<HostsKpiHistogramData[]>;
inspect?: Maybe<Inspect>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import {
HostsStrategyResponse,
HostUncommonProcessesStrategyResponse,
HostUncommonProcessesRequestOptions,
HostsKpiQueries,
HostsKpiAuthenticationsStrategyResponse,
HostsKpiAuthenticationsRequestOptions,
HostsKpiHostsStrategyResponse,
HostsKpiHostsRequestOptions,
HostsKpiUniqueIpsStrategyResponse,
HostsKpiUniqueIpsRequestOptions,
} from './hosts';
import {
NetworkQueries,
Expand Down Expand Up @@ -70,6 +77,7 @@ export * from './network';

export type FactoryQueryTypes =
| HostsQueries
| HostsKpiQueries
| NetworkQueries
| NetworkKpiQueries
| typeof MatrixHistogramQuery;
Expand Down Expand Up @@ -106,6 +114,12 @@ export type StrategyResponseType<T extends FactoryQueryTypes> = T extends HostsQ
? HostFirstLastSeenStrategyResponse
: T extends HostsQueries.uncommonProcesses
? HostUncommonProcessesStrategyResponse
: T extends HostsKpiQueries.kpiAuthentications
? HostsKpiAuthenticationsStrategyResponse
: T extends HostsKpiQueries.kpiHosts
? HostsKpiHostsStrategyResponse
: T extends HostsKpiQueries.kpiUniqueIps
? HostsKpiUniqueIpsStrategyResponse
: T extends NetworkQueries.details
? NetworkDetailsStrategyResponse
: T extends NetworkQueries.dns
Expand Down Expand Up @@ -148,6 +162,12 @@ export type StrategyRequestType<T extends FactoryQueryTypes> = T extends HostsQu
? HostFirstLastSeenRequestOptions
: T extends HostsQueries.uncommonProcesses
? HostUncommonProcessesRequestOptions
: T extends HostsKpiQueries.kpiAuthentications
? HostsKpiAuthenticationsRequestOptions
: T extends HostsKpiQueries.kpiHosts
? HostsKpiHostsRequestOptions
: T extends HostsKpiQueries.kpiUniqueIps
? HostsKpiUniqueIpsRequestOptions
: T extends NetworkQueries.details
? NetworkDetailsRequestOptions
: T extends NetworkQueries.dns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ import {
} from '../../mock';
import { State, createStore } from '../../store';
import { Provider as ReduxStoreProvider } from 'react-redux';
import { KpiHostsData } from '../../../graphql/types';
import { NetworkKpiStrategyResponse } from '../../../../common/search_strategy';
import {
HostsKpiStrategyResponse,
NetworkKpiStrategyResponse,
} from '../../../../common/search_strategy';

const from = '2019-06-15T06:00:00.000Z';
const to = '2019-06-18T06:00:00.000Z';
Expand Down Expand Up @@ -242,7 +244,7 @@ describe('useKpiMatrixStatus', () => {
data,
}: {
fieldsMapping: Readonly<StatItems[]>;
data: NetworkKpiStrategyResponse | KpiHostsData;
data: NetworkKpiStrategyResponse | HostsKpiStrategyResponse;
}) => {
const statItemsProps: StatItemsProps[] = useKpiMatrixStatus(
fieldsMapping,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import { get, getOr } from 'lodash/fp';
import React, { useState, useEffect } from 'react';
import styled from 'styled-components';

import { NetworkKpiStrategyResponse } from '../../../../common/search_strategy';
import { KpiHostsData } from '../../../graphql/types';
import {
HostsKpiStrategyResponse,
NetworkKpiStrategyResponse,
} from '../../../../common/search_strategy';
import { AreaChart } from '../charts/areachart';
import { BarChart } from '../charts/barchart';
import { ChartSeriesData, ChartData, ChartSeriesConfigs, UpdateDateRange } from '../charts/common';
Expand Down Expand Up @@ -113,12 +115,12 @@ export const barchartConfigs = (config?: { onElementClick?: ElementClickListener

export const addValueToFields = (
fields: StatItem[],
data: KpiHostsData | NetworkKpiStrategyResponse
data: HostsKpiStrategyResponse | NetworkKpiStrategyResponse
): StatItem[] => fields.map((field) => ({ ...field, value: get(field.key, data) }));

export const addValueToAreaChart = (
fields: StatItem[],
data: KpiHostsData | NetworkKpiStrategyResponse
data: HostsKpiStrategyResponse | NetworkKpiStrategyResponse
): ChartSeriesData[] =>
fields
.filter((field) => get(`${field.key}Histogram`, data) != null)
Expand All @@ -130,7 +132,7 @@ export const addValueToAreaChart = (

export const addValueToBarChart = (
fields: StatItem[],
data: KpiHostsData | NetworkKpiStrategyResponse
data: HostsKpiStrategyResponse | NetworkKpiStrategyResponse
): ChartSeriesData[] => {
if (fields.length === 0) return [];
return fields.reduce((acc: ChartSeriesData[], field: StatItem, idx: number) => {
Expand Down Expand Up @@ -159,7 +161,7 @@ export const addValueToBarChart = (

export const useKpiMatrixStatus = (
mappings: Readonly<StatItems[]>,
data: KpiHostsData | NetworkKpiStrategyResponse,
data: HostsKpiStrategyResponse | NetworkKpiStrategyResponse,
id: string,
from: string,
to: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { i18n } from '@kbn/i18n';

export const AUTHENTICATIONS = i18n.translate(
'xpack.securitySolution.authenticationsTable.authenticationFailures',
'xpack.securitySolution.authenticationsTable.authentications',
{
defaultMessage: 'Authentications',
}
Expand Down
Loading

0 comments on commit c03c7b3

Please sign in to comment.