Skip to content
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

[Security Solution] Add reason field #108449

Merged
merged 3 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ const AlertSummaryViewComponent: React.FC<{

return (
<>
<EuiSpacer size="l" />
<SummaryView summaryColumns={summaryColumns} summaryRows={summaryRows} title={title} />
{maybeRule?.note && (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
timelineDataToEnrichment,
} from './cti_details/helpers';
import { EnrichmentRangePicker } from './cti_details/enrichment_range_picker';
import { Reason } from './reason';

type EventViewTab = EuiTabbedContentTab;

Expand Down Expand Up @@ -137,6 +138,7 @@ const EventDetailsComponent: React.FC<Props> = ({
name: i18n.OVERVIEW,
content: (
<>
<Reason eventId={id} data={data} />
<AlertSummaryView
{...{
data,
Expand Down
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 { EuiTextColor, EuiFlexItem, EuiSpacer, EuiHorizontalRule, EuiTitle } from '@elastic/eui';
import React, { useMemo } from 'react';

import styled from 'styled-components';
import { getRuleDetailsUrl, useFormatUrl } from '../link_to';
import * as i18n from './translations';
import { TimelineEventsDetailsItem } from '../../../../common';
import { LinkAnchor } from '../links';
import { useKibana } from '../../lib/kibana';
import { APP_ID, SecurityPageName } from '../../../../common/constants';
import { EVENT_DETAILS_PLACEHOLDER } from '../../../timelines/components/side_panel/event_details/translations';
import { getFieldValue } from '../../../detections/components/host_isolation/helpers';

interface Props {
data: TimelineEventsDetailsItem[];
eventId: string;
}

export const Indent = styled.div`
padding: 0 8px;
word-break: break-word;
line-height: 1.7em;
`;

export const ReasonComponent: React.FC<Props> = ({ eventId, data }) => {
const { navigateToApp } = useKibana().services.application;
const { formatUrl } = useFormatUrl(SecurityPageName.rules);

const reason = useMemo(
() => getFieldValue({ category: 'signal', field: 'signal.reason' }, data),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to want to make this kibana.alert.reason and use the constant here, but we can replace all of that as a wholesale change once the shared constants file is created

[data]
);

const ruleId = useMemo(
() => getFieldValue({ category: 'signal', field: 'signal.rule.id' }, data),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here

[data]
);

if (!eventId) {
return <EuiTextColor color="subdued">{EVENT_DETAILS_PLACEHOLDER}</EuiTextColor>;
}

return reason ? (
<EuiFlexItem grow={false}>
<EuiSpacer size="l" />
<EuiTitle size="xxxs">
<h5>{i18n.REASON}</h5>
</EuiTitle>
<EuiSpacer size="s" />

<Indent>{reason}</Indent>

<EuiSpacer size="s" />

<Indent>
<LinkAnchor
data-test-subj="ruleName"
onClick={(ev: { preventDefault: () => void }) => {
ev.preventDefault();
navigateToApp(APP_ID, {
deepLinkId: SecurityPageName.rules,
path: getRuleDetailsUrl(ruleId),
});
}}
href={formatUrl(getRuleDetailsUrl(ruleId))}
>
{i18n.VIEW_RULE_DETAIL_PAGE}
</LinkAnchor>
</Indent>

<EuiHorizontalRule />
</EuiFlexItem>
) : null;
};

ReasonComponent.displayName = 'ReasonComponent';

export const Reason = React.memo(ReasonComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,14 @@ export const MULTI_FIELD_BADGE = i18n.translate(
export const ACTIONS = i18n.translate('xpack.securitySolution.eventDetails.table.actions', {
defaultMessage: 'Actions',
});

export const REASON = i18n.translate('xpack.securitySolution.eventDetails.reason', {
defaultMessage: 'Reason',
});

export const VIEW_RULE_DETAIL_PAGE = i18n.translate(
'xpack.securitySolution.eventDetails.viewRuleDetailPage',
{
defaultMessage: 'View Rule detail page',
}
);