-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Added ability to fire actions when an alert instance is resolved #82799
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
Changes from all commits
fad1fe2
39f8587
378fa7c
8f48a39
676d8f1
f781dcb
e231074
53ac140
b4dc1f5
2d8f830
78a15c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { ActionGroup } from './alert_type'; | ||
|
|
||
| export const ResolvedActionGroup: ActionGroup = { | ||
| id: 'resolved', | ||
| name: i18n.translate('xpack.alerts.builtinActionGroups.resolved', { | ||
| defaultMessage: 'Resolved', | ||
| }), | ||
| }; | ||
|
|
||
| export function getBuiltinActionGroups(): ActionGroup[] { | ||
| return [ResolvedActionGroup]; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ import { IEvent, IEventLogger, SAVED_OBJECT_REL_PRIMARY } from '../../../event_l | |
| import { isAlertSavedObjectNotFoundError } from '../lib/is_alert_not_found_error'; | ||
| import { AlertsClient } from '../alerts_client'; | ||
| import { partiallyUpdateAlert } from '../saved_objects'; | ||
| import { ResolvedActionGroup } from '../../common'; | ||
|
|
||
| const FALLBACK_RETRY_INTERVAL = '5m'; | ||
|
|
||
|
|
@@ -210,6 +211,7 @@ export class TaskRunner { | |
| const instancesWithScheduledActions = pickBy(alertInstances, (alertInstance: AlertInstance) => | ||
| alertInstance.hasScheduledActions() | ||
| ); | ||
|
|
||
| generateNewAndResolvedInstanceEvents({ | ||
| eventLogger, | ||
| originalAlertInstances, | ||
|
|
@@ -220,6 +222,14 @@ export class TaskRunner { | |
| }); | ||
|
|
||
| if (!muteAll) { | ||
| scheduleActionsForResolvedInstances( | ||
| alertInstances, | ||
| executionHandler, | ||
| originalAlertInstances, | ||
| instancesWithScheduledActions, | ||
| alert.mutedInstanceIds | ||
| ); | ||
|
|
||
| const mutedInstanceIdsSet = new Set(mutedInstanceIds); | ||
|
|
||
| await Promise.all( | ||
|
|
@@ -479,6 +489,34 @@ function generateNewAndResolvedInstanceEvents(params: GenerateNewAndResolvedInst | |
| } | ||
| } | ||
|
|
||
| function scheduleActionsForResolvedInstances( | ||
| alertInstancesMap: Record<string, AlertInstance>, | ||
| executionHandler: ReturnType<typeof createExecutionHandler>, | ||
| originalAlertInstances: Record<string, AlertInstance>, | ||
| currentAlertInstances: Dictionary<AlertInstance>, | ||
| mutedInstanceIds: string[] | ||
| ) { | ||
| const currentAlertInstanceIds = Object.keys(currentAlertInstances); | ||
| const originalAlertInstanceIds = Object.keys(originalAlertInstances); | ||
| const resolvedIds = without( | ||
| originalAlertInstanceIds, | ||
| ...currentAlertInstanceIds, | ||
| ...mutedInstanceIds | ||
| ); | ||
| for (const id of resolvedIds) { | ||
| const instance = alertInstancesMap[id]; | ||
| instance.updateLastScheduledActions(ResolvedActionGroup.id); | ||
| instance.unscheduleActions(); | ||
| executionHandler({ | ||
| actionGroup: ResolvedActionGroup.id, | ||
| context: {}, | ||
| state: {}, | ||
|
Comment on lines
+512
to
+513
Contributor
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. Wondering if we're going to find the empty context and state to be a problem 🤔
Contributor
Author
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. I did it in the UI PR |
||
| alertInstanceId: id, | ||
| }); | ||
| instance.scheduleActions(ResolvedActionGroup.id); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * If an error is thrown, wrap it in an AlertTaskRunResult | ||
| * so that we can treat each field independantly | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.