-
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
[CTI] Adds Threat Intel dashboard links to Overview page #100423
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
32afd68
[CTI] Adds Dashboard Links to Overview Page
ecezalp 1fac228
adds timerange to dashboard links
ecezalp 929fdfb
refetches data when timeRange is updated
ecezalp 42f4aec
incorporates feedback
ecezalp cff1557
Merge branch 'master' into security-team-1098
kibanamachine 9158563
Merge branch 'master' into security-team-1098
kibanamachine c4bb293
Merge branch 'master' into security-team-1098
kibanamachine fb57edf
Merge branch 'master' into security-team-1098
kibanamachine 40c278d
Adds CTI dashboard states
ecezalp a137105
Merge branch 'master' into security-team-1098
kibanamachine 989fc56
adds unit tests
ecezalp 0940db9
Merge branch 'master' into security-team-1098
kibanamachine 80e8483
updates query
ecezalp 2d4d1fd
adds Anomali ThreatStream
ecezalp f4dba26
updates change according to comments
ecezalp 797c0ab
fix test
ecezalp 114253d
Merge branch 'master' into security-team-1098
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
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"encryptedSavedObjects", | ||
"fleet", | ||
"ml", | ||
"dashboard", | ||
"newsfeed", | ||
"security", | ||
"spaces", | ||
|
54 changes: 54 additions & 0 deletions
54
...urity_solution/public/overview/components/overview_cti_links/cti_disabled_module.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,54 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { cloneDeep } from 'lodash/fp'; | ||
import { mount } from 'enzyme'; | ||
import { I18nProvider } from '@kbn/i18n/react'; | ||
import { CtiDisabledModule } from './cti_disabled_module'; | ||
import { ThemeProvider } from 'styled-components'; | ||
import { createStore, State } from '../../../common/store'; | ||
import { | ||
createSecuritySolutionStorageMock, | ||
kibanaObservable, | ||
mockGlobalState, | ||
SUB_PLUGINS_REDUCER, | ||
} from '../../../common/mock'; | ||
import { mockTheme } from './mock'; | ||
|
||
jest.mock('../../../common/lib/kibana'); | ||
|
||
describe('CtiDisabledModule', () => { | ||
const state: State = mockGlobalState; | ||
|
||
const { storage } = createSecuritySolutionStorageMock(); | ||
let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); | ||
|
||
beforeEach(() => { | ||
const myState = cloneDeep(state); | ||
store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); | ||
}); | ||
|
||
it('renders splitPanel with "danger" variant', () => { | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<I18nProvider> | ||
<ThemeProvider theme={mockTheme}> | ||
<CtiDisabledModule /> | ||
</ThemeProvider> | ||
</I18nProvider> | ||
</Provider> | ||
); | ||
|
||
expect( | ||
wrapper.find( | ||
'[data-test-subj="cti-dashboard-links"] [data-test-subj="cti-inner-panel-danger"]' | ||
).length | ||
).toEqual(1); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
...s/security_solution/public/overview/components/overview_cti_links/cti_disabled_module.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,45 @@ | ||
/* | ||
* 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 React, { useMemo } from 'react'; | ||
import { EuiButton } from '@elastic/eui'; | ||
import { ThreatIntelPanelView } from './threat_intel_panel_view'; | ||
import { EMPTY_LIST_ITEMS } from '../../containers/overview_cti_links/helpers'; | ||
import { useKibana } from '../../../common/lib/kibana'; | ||
import { CtiInnerPanel } from './cti_inner_panel'; | ||
import * as i18n from './translations'; | ||
|
||
export const CtiDisabledModuleComponent = () => { | ||
const threatIntelDocLink = `${ | ||
useKibana().services.docLinks.links.filebeat.base | ||
}/filebeat-module-threatintel.html`; | ||
|
||
const danger = useMemo( | ||
() => ( | ||
<CtiInnerPanel | ||
color={'danger'} | ||
title={i18n.DANGER_TITLE} | ||
body={i18n.DANGER_BODY} | ||
button={ | ||
<EuiButton href={threatIntelDocLink} color={'danger'} fill> | ||
{i18n.DANGER_BUTTON} | ||
</EuiButton> | ||
} | ||
data-test-subj="cti-inner-panel-danger" | ||
/> | ||
), | ||
[threatIntelDocLink] | ||
); | ||
|
||
return ( | ||
<ThreatIntelPanelView totalEventCount={0} splitPanel={danger} listItems={EMPTY_LIST_ITEMS} /> | ||
); | ||
}; | ||
|
||
CtiDisabledModuleComponent.displayName = 'CtiDisabledModule'; | ||
|
||
export const CtiDisabledModule = React.memo(CtiDisabledModuleComponent); |
90 changes: 90 additions & 0 deletions
90
...curity_solution/public/overview/components/overview_cti_links/cti_enabled_module.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,90 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { cloneDeep } from 'lodash/fp'; | ||
import { mount } from 'enzyme'; | ||
import { I18nProvider } from '@kbn/i18n/react'; | ||
import { CtiEnabledModule } from './cti_enabled_module'; | ||
import { ThemeProvider } from 'styled-components'; | ||
import { createStore, State } from '../../../common/store'; | ||
import { | ||
createSecuritySolutionStorageMock, | ||
kibanaObservable, | ||
mockGlobalState, | ||
SUB_PLUGINS_REDUCER, | ||
} from '../../../common/mock'; | ||
import { mockTheme, mockProps, mockCtiEventCountsResponse, mockCtiLinksResponse } from './mock'; | ||
import { useCtiEventCounts } from '../../containers/overview_cti_links/use_cti_event_counts'; | ||
import { useCtiDashboardLinks } from '../../containers/overview_cti_links'; | ||
|
||
jest.mock('../../../common/lib/kibana'); | ||
|
||
jest.mock('../../containers/overview_cti_links/use_cti_event_counts'); | ||
const useCTIEventCountsMock = useCtiEventCounts as jest.Mock; | ||
useCTIEventCountsMock.mockReturnValue(mockCtiEventCountsResponse); | ||
|
||
jest.mock('../../containers/overview_cti_links'); | ||
const useCtiDashboardLinksMock = useCtiDashboardLinks as jest.Mock; | ||
useCtiDashboardLinksMock.mockReturnValue(mockCtiLinksResponse); | ||
|
||
describe('CtiEnabledModule', () => { | ||
const state: State = mockGlobalState; | ||
|
||
const { storage } = createSecuritySolutionStorageMock(); | ||
let store = createStore(state, SUB_PLUGINS_REDUCER, kibanaObservable, storage); | ||
|
||
beforeEach(() => { | ||
const myState = cloneDeep(state); | ||
store = createStore(myState, SUB_PLUGINS_REDUCER, kibanaObservable, storage); | ||
}); | ||
|
||
it('renders CtiWithEvents when there are events', () => { | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<I18nProvider> | ||
<ThemeProvider theme={mockTheme}> | ||
<CtiEnabledModule {...mockProps} /> | ||
</ThemeProvider> | ||
</I18nProvider> | ||
</Provider> | ||
); | ||
|
||
expect(wrapper.find('[data-test-subj="cti-with-events"]').length).toEqual(1); | ||
}); | ||
|
||
it('renders CtiWithNoEvents when there are no events', () => { | ||
useCTIEventCountsMock.mockReturnValueOnce({ totalCount: 0 }); | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<I18nProvider> | ||
<ThemeProvider theme={mockTheme}> | ||
<CtiEnabledModule {...mockProps} /> | ||
</ThemeProvider> | ||
</I18nProvider> | ||
</Provider> | ||
); | ||
|
||
expect(wrapper.exists('[data-test-subj="cti-with-events"]')).toBe(true); | ||
}); | ||
|
||
it('renders null while event counts are loading', () => { | ||
useCTIEventCountsMock.mockReturnValueOnce({ totalCount: -1 }); | ||
const wrapper = mount( | ||
<Provider store={store}> | ||
<I18nProvider> | ||
<ThemeProvider theme={mockTheme}> | ||
<CtiEnabledModule {...mockProps} /> | ||
</ThemeProvider> | ||
</I18nProvider> | ||
</Provider> | ||
); | ||
|
||
expect(wrapper.html()).toEqual(''); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
...ns/security_solution/public/overview/components/overview_cti_links/cti_enabled_module.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,38 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { ThreatIntelLinkPanelProps } from './index'; | ||
import { useCtiEventCounts } from '../../containers/overview_cti_links/use_cti_event_counts'; | ||
import { CtiNoEvents } from './cti_no_events'; | ||
import { CtiWithEvents } from './cti_with_events'; | ||
|
||
export const CtiEnabledModuleComponent: React.FC<ThreatIntelLinkPanelProps> = (props) => { | ||
const { eventCountsByDataset, totalCount } = useCtiEventCounts(props); | ||
const { to, from } = props; | ||
|
||
switch (totalCount) { | ||
case -1: | ||
return null; | ||
case 0: | ||
return <CtiNoEvents to={to} from={from} data-test-subj="cti-with-no-events" />; | ||
default: | ||
return ( | ||
<CtiWithEvents | ||
data-test-subj="cti-with-events" | ||
eventCountsByDataset={eventCountsByDataset} | ||
totalCount={totalCount} | ||
to={to} | ||
from={from} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
CtiEnabledModuleComponent.displayName = 'CtiEnabledModule'; | ||
|
||
export const CtiEnabledModule = React.memo(CtiEnabledModuleComponent); |
69 changes: 69 additions & 0 deletions
69
...ugins/security_solution/public/overview/components/overview_cti_links/cti_inner_panel.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,69 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import styled from 'styled-components'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiSplitPanel, EuiText } from '@elastic/eui'; | ||
|
||
const PanelContainer = styled(EuiSplitPanel.Inner)` | ||
margin-bottom: ${({ theme }) => theme.eui.paddingSizes.m}; | ||
`; | ||
|
||
const ButtonContainer = styled(EuiFlexGroup)` | ||
padding: ${({ theme }) => theme.eui.paddingSizes.s}; | ||
`; | ||
|
||
const Title = styled(EuiText)<{ textcolor: 'primary' | 'warning' | 'danger' }>` | ||
color: ${({ theme, textcolor }) => | ||
textcolor === 'primary' | ||
? theme.eui.euiColorPrimary | ||
: textcolor === 'warning' | ||
? theme.eui.euiColorWarningText | ||
: theme.eui.euiColorDangerText}; | ||
margin-bottom: ${({ theme }) => theme.eui.paddingSizes.m}; | ||
`; | ||
|
||
const Icon = styled(EuiIcon)` | ||
padding: 0; | ||
margin-top: ${({ theme }) => theme.eui.paddingSizes.m}; | ||
margin-left: 12px; | ||
transform: scale(${({ color }) => (color === 'primary' ? 1.4 : 1)}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this to make the (i) icon closer in size to the other icons? |
||
`; | ||
|
||
export const CtiInnerPanel = ({ | ||
color, | ||
title, | ||
body, | ||
button, | ||
}: { | ||
color: 'primary' | 'warning' | 'danger'; | ||
title: string; | ||
body: string; | ||
button?: JSX.Element; | ||
}) => { | ||
const iconType = color === 'primary' ? 'iInCircle' : color === 'warning' ? 'help' : 'alert'; | ||
return ( | ||
<PanelContainer grow={false} color={color}> | ||
<EuiFlexGroup direction={'column'}> | ||
<EuiFlexItem> | ||
<EuiFlexGroup direction={'row'}> | ||
<Icon type={iconType} size="m" color={color} /> | ||
<EuiFlexItem> | ||
<Title textcolor={color}>{title}</Title> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
{body} | ||
</EuiFlexItem> | ||
{button && ( | ||
<ButtonContainer> | ||
<EuiFlexItem grow={false}>{button}</EuiFlexItem> | ||
</ButtonContainer> | ||
)} | ||
</EuiFlexGroup> | ||
</PanelContainer> | ||
); | ||
}; |
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.
Nit: I think this form reads a little better: