-
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.
Merge branch 'main' into retaining.api.key.rules
- Loading branch information
Showing
49 changed files
with
729 additions
and
318 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/cases/public/client/helpers/group_alerts_by_rule.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,44 @@ | ||
/* | ||
* 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 { CommentRequestAlertType } from '../../../common/api'; | ||
import { CommentType, Ecs } from '../../../common'; | ||
import { getRuleIdFromEvent } from './get_rule_id_from_event'; | ||
import { CaseAttachments } from '../../types'; | ||
|
||
type Maybe<T> = T | null; | ||
interface Event { | ||
data: EventNonEcsData[]; | ||
ecs: Ecs; | ||
} | ||
interface EventNonEcsData { | ||
field: string; | ||
value?: Maybe<string[]>; | ||
} | ||
|
||
export const groupAlertsByRule = (items: Event[], owner: string): CaseAttachments => { | ||
const attachmentsByRule = items.reduce<Record<string, CommentRequestAlertType>>((acc, item) => { | ||
const rule = getRuleIdFromEvent(item); | ||
if (!acc[rule.id]) { | ||
acc[rule.id] = { | ||
alertId: [], | ||
index: [], | ||
owner, | ||
type: CommentType.alert as const, | ||
rule, | ||
}; | ||
} | ||
const alerts = acc[rule.id].alertId; | ||
const indexes = acc[rule.id].index; | ||
if (Array.isArray(alerts) && Array.isArray(indexes)) { | ||
alerts.push(item.ecs._id ?? ''); | ||
indexes.push(item.ecs._index ?? ''); | ||
} | ||
return acc; | ||
}, {}); | ||
return Object.values(attachmentsByRule); | ||
}; |
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
Oops, something went wrong.