-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hosts Risk Step 1 - Hosts Page - Risky Hosts KPI (#119734)
* Fix HostsRiskScore interface to match new transform version This reverts commit c29886c. Revert "Host Risk Filtering POC" This reverts commit c1540e54f6ec3d892035bb7aeecb40e5da219ac1. * Move hosts risk API client to hosts folder structure * Add Risky Hosts KPI to Hosts page * Fix type issues and add unit tests * Add cypress test * Fix unit test * Fix cypress tests * Add 'EuiCallOut' message when Host risk index doesn't exist * Fix singular hosts internationalization * Fix conflict with main * Update risky_hosts es_archives mappings Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
7fc30d5
commit f2ef652
Showing
39 changed files
with
961 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...security_solution/common/search_strategy/security_solution/hosts/kpi/risky_hosts/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { IEsSearchResponse } from '../../../../../../../../../src/plugins/data/common'; | ||
import type { Inspect, Maybe } from '../../../../common'; | ||
import type { RequestBasicOptions } from '../../..'; | ||
|
||
export type HostsKpiRiskyHostsRequestOptions = RequestBasicOptions; | ||
|
||
export interface HostsKpiRiskyHostsStrategyResponse extends IEsSearchResponse { | ||
inspect?: Maybe<Inspect>; | ||
riskyHosts: { | ||
[key in HostRiskSeverity]: number; | ||
}; | ||
} | ||
|
||
export enum HostRiskSeverity { | ||
unknown = 'Unknown', | ||
low = 'Low', | ||
moderate = 'Moderate', | ||
high = 'High', | ||
critical = 'Critical', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
x-pack/plugins/security_solution/cypress/integration/hosts/risky_hosts_kpi.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { loginAndWaitForPage } from '../../tasks/login'; | ||
|
||
import { HOSTS_URL } from '../../urls/navigation'; | ||
import { cleanKibana } from '../../tasks/common'; | ||
|
||
describe('RiskyHosts KPI', () => { | ||
before(() => { | ||
cleanKibana(); | ||
}); | ||
|
||
it('it renders', () => { | ||
loginAndWaitForPage(HOSTS_URL); | ||
|
||
cy.get('[data-test-subj="riskyHostsTotal"]').should('have.text', '0 Risky Hosts'); | ||
cy.get('[data-test-subj="riskyHostsCriticalQuantity"]').should('have.text', '0 hosts'); | ||
cy.get('[data-test-subj="riskyHostsHighQuantity"]').should('have.text', '0 hosts'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/security_solution/public/common/hooks/use_error_toast.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useErrorToast } from './use_error_toast'; | ||
|
||
jest.mock('./use_app_toasts'); | ||
|
||
import { useAppToasts } from './use_app_toasts'; | ||
|
||
describe('useErrorToast', () => { | ||
let addErrorMock: jest.Mock; | ||
|
||
beforeEach(() => { | ||
addErrorMock = jest.fn(); | ||
(useAppToasts as jest.Mock).mockImplementation(() => ({ | ||
addError: addErrorMock, | ||
})); | ||
}); | ||
|
||
it('calls useAppToasts error when an error param is provided', () => { | ||
const title = 'testErrorTitle'; | ||
const error = new Error(); | ||
renderHook(() => useErrorToast(title, error)); | ||
|
||
expect(addErrorMock).toHaveBeenCalledWith(error, { title }); | ||
}); | ||
|
||
it("doesn't call useAppToasts error when an error param is undefined", () => { | ||
const title = 'testErrorTitle'; | ||
const error = undefined; | ||
renderHook(() => useErrorToast(title, error)); | ||
|
||
expect(addErrorMock).not.toHaveBeenCalled(); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
x-pack/plugins/security_solution/public/common/hooks/use_error_toast.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useEffect } from 'react'; | ||
import { useAppToasts } from './use_app_toasts'; | ||
|
||
/** | ||
* Display App error toast when error is defined. | ||
*/ | ||
export const useErrorToast = (title: string, error: unknown) => { | ||
const { addError } = useAppToasts(); | ||
|
||
useEffect(() => { | ||
if (error) { | ||
addError(error, { title }); | ||
} | ||
}, [error, title, addError]); | ||
}; |
85 changes: 85 additions & 0 deletions
85
x-pack/plugins/security_solution/public/common/hooks/use_inspect_query.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useInspectQuery } from './use_inspect_query'; | ||
|
||
import { useGlobalTime } from '../containers/use_global_time'; | ||
|
||
jest.mock('../containers/use_global_time'); | ||
|
||
const QUERY_ID = 'tes_query_id'; | ||
|
||
const RESPONSE = { | ||
inspect: { dsl: [], response: [] }, | ||
isPartial: false, | ||
isRunning: false, | ||
total: 0, | ||
loaded: 0, | ||
rawResponse: { | ||
took: 0, | ||
timed_out: false, | ||
_shards: { | ||
total: 0, | ||
successful: 0, | ||
failed: 0, | ||
skipped: 0, | ||
}, | ||
results: { | ||
hits: { | ||
total: 0, | ||
}, | ||
}, | ||
hits: { | ||
total: 0, | ||
max_score: 0, | ||
hits: [], | ||
}, | ||
}, | ||
totalCount: 0, | ||
enrichments: [], | ||
}; | ||
|
||
describe('useInspectQuery', () => { | ||
let deleteQuery: jest.Mock; | ||
let setQuery: jest.Mock; | ||
|
||
beforeEach(() => { | ||
deleteQuery = jest.fn(); | ||
setQuery = jest.fn(); | ||
(useGlobalTime as jest.Mock).mockImplementation(() => ({ | ||
deleteQuery, | ||
setQuery, | ||
isInitializing: false, | ||
})); | ||
}); | ||
|
||
it('it calls setQuery', () => { | ||
renderHook(() => useInspectQuery(QUERY_ID, false, RESPONSE)); | ||
|
||
expect(setQuery).toHaveBeenCalledTimes(1); | ||
expect(setQuery.mock.calls[0][0].id).toBe(QUERY_ID); | ||
}); | ||
|
||
it("doesn't call setQuery when response is undefined", () => { | ||
renderHook(() => useInspectQuery(QUERY_ID, false, undefined)); | ||
|
||
expect(setQuery).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("doesn't call setQuery when loading", () => { | ||
renderHook(() => useInspectQuery(QUERY_ID, true)); | ||
|
||
expect(setQuery).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('calls deleteQuery when unmouting', () => { | ||
const result = renderHook(() => useInspectQuery(QUERY_ID, false, RESPONSE)); | ||
result.unmount(); | ||
|
||
expect(deleteQuery).toHaveBeenCalledWith({ id: QUERY_ID }); | ||
}); | ||
}); |
Oops, something went wrong.