-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hosts Risk Step 1 - Hosts Page - Risky Hosts KPI #119734
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0443efe
Fix HostsRiskScore interface to match new transform version
machadoum 988f0df
Move hosts risk API client to hosts folder structure
machadoum 25a717d
Add Risky Hosts KPI to Hosts page
machadoum 35367f8
Fix type issues and add unit tests
machadoum e5b66d4
Add cypress test
machadoum 4ba9698
Fix unit test
machadoum f6494f7
Fix cypress tests
machadoum 24f4709
Add 'EuiCallOut' message when Host risk index doesn't exist
machadoum c130256
Fix singular hosts internationalization
machadoum 59611a8
Fix conflict with main
machadoum d531c48
Update risky_hosts es_archives mappings
machadoum 5d9e112
Merge branch 'main' into siem-explore-issue-119024
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ecezalp I am updating the
HostsRiskScore
interface to match the new version of the transform.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit unsure about the implications - what would happen if someone installed the host risk score module during 7.16 (or 8.0) and then upgraded to 8.1? Do we have a mechanism to tell them that the also need to update the host risk score package? How would they know? Would they get a broken UI (all 0s on the Host Risk Score card, or a javascript error?)
Maybe we don't care at this stage about breaking changes because the feature is experimental, but I think it's still something we should clear with product, what happens if users have an older version of the host risk score package installed. What issue would the users encounter, and how would they know how to fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajosh0504 @SourinPaul Could you help us with this question? ⬆️