forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request elastic#11 from Elastic-AWP-Platform/alerted_proce…
…sses Alerted processes
- Loading branch information
Showing
12 changed files
with
443 additions
and
85 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
x-pack/plugins/session_view/common/utils/expand_dotted_object.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,55 @@ | ||
/* | ||
* 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 { merge } from '@kbn/std'; | ||
|
||
const expandDottedField = (dottedFieldName: string, val: unknown): object => { | ||
const parts = dottedFieldName.split('.'); | ||
if (parts.length === 1) { | ||
return { [parts[0]]: val }; | ||
} else { | ||
return { [parts[0]]: expandDottedField(parts.slice(1).join('.'), val) }; | ||
} | ||
}; | ||
|
||
/* | ||
* Expands an object with "dotted" fields to a nested object with unflattened fields. | ||
* | ||
* Example: | ||
* expandDottedObject({ | ||
* "kibana.alert.depth": 1, | ||
* "kibana.alert.ancestors": [{ | ||
* id: "d5e8eb51-a6a0-456d-8a15-4b79bfec3d71", | ||
* type: "event", | ||
* index: "signal_index", | ||
* depth: 0, | ||
* }], | ||
* }) | ||
* | ||
* => { | ||
* kibana: { | ||
* alert: { | ||
* ancestors: [ | ||
* id: "d5e8eb51-a6a0-456d-8a15-4b79bfec3d71", | ||
* type: "event", | ||
* index: "signal_index", | ||
* depth: 0, | ||
* ], | ||
* depth: 1, | ||
* }, | ||
* }, | ||
* } | ||
*/ | ||
export const expandDottedObject = (dottedObj: object) => { | ||
if (Array.isArray(dottedObj)) { | ||
return dottedObj; | ||
} | ||
return Object.entries(dottedObj).reduce( | ||
(acc, [key, val]) => merge(acc, expandDottedField(key, val)), | ||
{} | ||
); | ||
}; |
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
96 changes: 96 additions & 0 deletions
96
x-pack/plugins/session_view/public/components/ProcessTreeAlerts/index.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,96 @@ | ||
/* | ||
* 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 { | ||
EuiButton, | ||
EuiText, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiHorizontalRule, | ||
EuiSpacer, | ||
} from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { useStyles } from './styles'; | ||
import { ProcessEvent } from '../../hooks/use_process_tree'; | ||
import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; | ||
import { CoreStart } from '../../../../../../src/core/public'; | ||
|
||
interface ProcessTreeAlertsDeps { | ||
alerts: ProcessEvent[]; | ||
} | ||
|
||
export function ProcessTreeAlerts({ alerts }: ProcessTreeAlertsDeps) { | ||
const styles = useStyles(); | ||
const { http } = useKibana<CoreStart>().services; | ||
|
||
if (alerts.length === 0) { | ||
return null; | ||
} | ||
|
||
const getRuleUrl = (alert: ProcessEvent) => { | ||
return http.basePath.prepend(`/app/security/rules/id/${alert.kibana?.alert.rule.uuid}`); | ||
}; | ||
|
||
const renderAlertDetails = (alert: ProcessEvent, index: number) => { | ||
if (!alert.kibana) { | ||
return null; | ||
} | ||
|
||
const { uuid, rule, original_event: event, workflow_status: status } = alert.kibana.alert; | ||
const { name, query, severity } = rule; | ||
|
||
return ( | ||
<EuiText key={uuid} size="s"> | ||
<EuiFlexGroup> | ||
<EuiFlexItem> | ||
<h6> | ||
<FormattedMessage id="kbn.sessionView.rule" defaultMessage="Rule" /> | ||
</h6> | ||
{name} | ||
<h6> | ||
<FormattedMessage id="kbn.sessionView.query" defaultMessage="Query" /> | ||
</h6> | ||
{query} | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<h6> | ||
<FormattedMessage id="kbn.sessionView.severity" defaultMessage="Severity" /> | ||
</h6> | ||
{severity} | ||
<h6> | ||
<FormattedMessage | ||
id="kbn.sessionView.workflowStatus" | ||
defaultMessage="Workflow status" | ||
/> | ||
</h6> | ||
{status} | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<h6> | ||
<FormattedMessage id="kbn.sessionView.action" defaultMessage="Action" /> | ||
</h6> | ||
{event.action} | ||
<EuiSpacer /> | ||
<div> | ||
<EuiButton size="s" href={getRuleUrl(alert)}> | ||
<FormattedMessage id="kbn.sessionView.viewRule" defaultMessage="View rule" /> | ||
</EuiButton> | ||
</div> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
{index < alerts.length - 1 && ( | ||
<div> | ||
<EuiHorizontalRule margin="m" /> | ||
</div> | ||
)} | ||
</EuiText> | ||
); | ||
}; | ||
|
||
return <div css={styles.container}>{alerts.map(renderAlertDetails)}</div>; | ||
} |
37 changes: 37 additions & 0 deletions
37
x-pack/plugins/session_view/public/components/ProcessTreeAlerts/styles.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,37 @@ | ||
/* | ||
* 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 { useMemo } from 'react'; | ||
import { useEuiTheme } from '@elastic/eui'; | ||
import { CSSObject } from '@emotion/react'; | ||
|
||
export const useStyles = () => { | ||
const { euiTheme } = useEuiTheme(); | ||
|
||
const cached = useMemo(() => { | ||
const { size, colors, border } = euiTheme; | ||
|
||
const container: CSSObject = { | ||
marginTop: size.s, | ||
marginRight: size.s, | ||
color: colors.text, | ||
padding: size.m, | ||
borderStyle: 'solid', | ||
borderColor: colors.lightShade, | ||
borderWidth: border.width.thin, | ||
borderRadius: border.radius.medium, | ||
maxWidth: 800, | ||
backgroundColor: 'white', | ||
}; | ||
|
||
return { | ||
container, | ||
}; | ||
}, [euiTheme]); | ||
|
||
return cached; | ||
}; |
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
Oops, something went wrong.