diff --git a/x-pack/plugins/alerting/common/alert.ts b/x-pack/plugins/alerting/common/alert.ts index 06ab4c8d1796..3f4af5777b0e 100644 --- a/x-pack/plugins/alerting/common/alert.ts +++ b/x-pack/plugins/alerting/common/alert.ts @@ -77,6 +77,22 @@ export interface Alert { export type SanitizedAlert = Omit, 'apiKey'>; +export type SanitizedRuleConfig = Pick< + SanitizedAlert, + | 'name' + | 'tags' + | 'consumer' + | 'enabled' + | 'schedule' + | 'actions' + | 'createdBy' + | 'updatedBy' + | 'createdAt' + | 'updatedAt' + | 'throttle' + | 'notifyWhen' +>; + export enum HealthStatus { OK = 'ok', Warning = 'warn', diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts index bf6418323f79..3c6091fd2bdf 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts @@ -207,18 +207,23 @@ describe('Task Runner', () => { expect(call.tags).toEqual(['alert-', '-tags']); expect(call.createdBy).toBe('alert-creator'); expect(call.updatedBy).toBe('alert-updater'); - expect(call.consumer).toBe('bar'); - expect(call.schedule).toMatchInlineSnapshot(` + expect(call.rule).not.toBe(null); + expect(call.rule.name).toBe('alert-name'); + expect(call.rule.tags).toEqual(['alert-', '-tags']); + expect(call.rule.consumer).toBe('bar'); + expect(call.rule.enabled).toBe(true); + expect(call.rule.schedule).toMatchInlineSnapshot(` Object { "interval": "10s", } `); - expect(call.createdAt).toBe(mockDate); - expect(call.updatedAt).toBe(mockDate); - expect(call.notifyWhen).toBe('onActiveAlert'); - expect(call.throttle).toBe(null); - expect(call.enabled).toBe(true); - expect(call.actions).toMatchInlineSnapshot(` + expect(call.rule.createdBy).toBe('alert-creator'); + expect(call.rule.updatedBy).toBe('alert-updater'); + expect(call.rule.createdAt).toBe(mockDate); + expect(call.rule.updatedAt).toBe(mockDate); + expect(call.rule.notifyWhen).toBe('onActiveAlert'); + expect(call.rule.throttle).toBe(null); + expect(call.rule.actions).toMatchInlineSnapshot(` Array [ Object { "actionTypeId": "action", diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.ts index c282caccf718..477921612b84 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.ts @@ -271,14 +271,20 @@ export class TaskRunner< tags, createdBy, updatedBy, - consumer, - schedule, - createdAt, - updatedAt, - throttle, - notifyWhen, - enabled, - actions, + rule: { + name, + tags, + consumer, + enabled, + schedule, + actions, + createdBy, + updatedBy, + createdAt, + updatedAt, + throttle, + notifyWhen, + }, }); } catch (err) { event.message = `alert execution failure: ${alertLabel}`; diff --git a/x-pack/plugins/alerting/server/types.ts b/x-pack/plugins/alerting/server/types.ts index d2cd44866c0f..f8846035e6b0 100644 --- a/x-pack/plugins/alerting/server/types.ts +++ b/x-pack/plugins/alerting/server/types.ts @@ -32,8 +32,7 @@ import { AlertNotifyWhenType, WithoutReservedActionGroups, ActionVariable, - IntervalSchedule, - AlertAction, + SanitizedRuleConfig, } from '../common'; import { LicenseType } from '../../licensing/server'; @@ -91,20 +90,13 @@ export interface AlertExecutorOptions< services: AlertServices; params: Params; state: State; + rule: SanitizedRuleConfig; spaceId: string; namespace?: string; - consumer: string; name: string; tags: string[]; createdBy: string | null; updatedBy: string | null; - createdAt: Date; - updatedAt: Date; - throttle: string | null; - notifyWhen: AlertNotifyWhenType | null; - schedule: IntervalSchedule; - enabled: boolean; - actions: AlertAction[]; } export type ExecutorType< diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts index 01c193085bcc..d5256f8eb2be 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts @@ -37,16 +37,22 @@ const mockOptions = { tags: [], createdBy: null, updatedBy: null, - createdAt: new Date(), - updatedAt: new Date(), - consumer: '', - throttle: null, - notifyWhen: null, - schedule: { - interval: '1h', + rule: { + name: '', + tags: [], + consumer: '', + enabled: true, + schedule: { + interval: '1h', + }, + actions: [], + createdBy: null, + updatedBy: null, + createdAt: new Date(), + updatedAt: new Date(), + throttle: null, + notifyWhen: null, }, - enabled: true, - actions: [], }; describe('The metric threshold alert type', () => { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.test.ts index 613f83de4081..c382689c25a8 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.test.ts @@ -44,16 +44,22 @@ describe('rules_notification_alert_type', () => { previousStartedAt: new Date('2019-12-13T16:40:33.400Z'), createdBy: 'elastic', updatedBy: 'elastic', - createdAt: new Date('2019-12-14T16:40:33.400Z'), - updatedAt: new Date('2019-12-14T16:40:33.400Z'), - consumer: 'foo', - throttle: null, - notifyWhen: null, - schedule: { - interval: '1h', + rule: { + name: 'name', + tags: [], + consumer: 'foo', + enabled: true, + schedule: { + interval: '1h', + }, + actions: [], + createdBy: 'elastic', + updatedBy: 'elastic', + createdAt: new Date('2019-12-14T16:40:33.400Z'), + updatedAt: new Date('2019-12-14T16:40:33.400Z'), + throttle: null, + notifyWhen: null, }, - enabled: true, - actions: [], }; alert = rulesNotificationAlertType({ diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.test.ts index f5235b1d2ae2..a8bf34a9c58c 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.test.ts @@ -66,16 +66,22 @@ const getPayload = ( previousStartedAt: new Date('2019-12-13T16:40:33.400Z'), createdBy: 'elastic', updatedBy: 'elastic', - createdAt: new Date('2019-12-13T16:50:33.400Z'), - updatedAt: new Date('2019-12-13T16:50:33.400Z'), - consumer: 'foo', - throttle: null, - notifyWhen: null, - schedule: { - interval: '1h', + rule: { + name: ruleAlert.name, + tags: ruleAlert.tags, + consumer: 'foo', + enabled: true, + schedule: { + interval: '1h', + }, + actions: [], + createdBy: 'elastic', + updatedBy: 'elastic', + createdAt: new Date('2019-12-13T16:50:33.400Z'), + updatedAt: new Date('2019-12-13T16:50:33.400Z'), + throttle: null, + notifyWhen: null, }, - enabled: true, - actions: [], }); describe('signal_rule_alert_type', () => { diff --git a/x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_type.test.ts b/x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_type.test.ts index 475dcd7adeed..64eda2b0f8d7 100644 --- a/x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_type.test.ts +++ b/x-pack/plugins/stack_alerts/server/alert_types/es_query/alert_type.test.ts @@ -157,16 +157,22 @@ describe('alertType', () => { tags: [], createdBy: null, updatedBy: null, - createdAt: new Date(), - updatedAt: new Date(), - consumer: '', - throttle: null, - notifyWhen: null, - schedule: { - interval: '1h', + rule: { + name: uuid.v4(), + tags: [], + consumer: '', + enabled: true, + schedule: { + interval: '1h', + }, + actions: [], + createdBy: null, + updatedBy: null, + createdAt: new Date(), + updatedAt: new Date(), + throttle: null, + notifyWhen: null, }, - enabled: true, - actions: [], }); expect(alertServices.alertInstanceFactory).not.toHaveBeenCalled(); @@ -227,16 +233,22 @@ describe('alertType', () => { tags: [], createdBy: null, updatedBy: null, - createdAt: new Date(), - updatedAt: new Date(), - consumer: '', - throttle: null, - notifyWhen: null, - schedule: { - interval: '1h', + rule: { + name: uuid.v4(), + tags: [], + consumer: '', + enabled: true, + schedule: { + interval: '1h', + }, + actions: [], + createdBy: null, + updatedBy: null, + createdAt: new Date(), + updatedAt: new Date(), + throttle: null, + notifyWhen: null, }, - enabled: true, - actions: [], }); expect(alertServices.alertInstanceFactory).toHaveBeenCalledWith(ConditionMetAlertInstanceId); @@ -372,16 +384,22 @@ describe('alertType', () => { tags: [], createdBy: null, updatedBy: null, - createdAt: new Date(), - updatedAt: new Date(), - consumer: '', - throttle: null, - notifyWhen: null, - schedule: { - interval: '1h', + rule: { + name: uuid.v4(), + tags: [], + consumer: '', + enabled: true, + schedule: { + interval: '1h', + }, + actions: [], + createdBy: null, + updatedBy: null, + createdAt: new Date(), + updatedAt: new Date(), + throttle: null, + notifyWhen: null, }, - enabled: true, - actions: [], }); const instance: AlertInstanceMock = alertServices.alertInstanceFactory.mock.results[0].value; @@ -440,16 +458,22 @@ describe('alertType', () => { tags: [], createdBy: null, updatedBy: null, - createdAt: new Date(), - updatedAt: new Date(), - consumer: '', - throttle: null, - notifyWhen: null, - schedule: { - interval: '1h', + rule: { + name: uuid.v4(), + tags: [], + consumer: '', + enabled: true, + schedule: { + interval: '1h', + }, + actions: [], + createdBy: null, + updatedBy: null, + createdAt: new Date(), + updatedAt: new Date(), + throttle: null, + notifyWhen: null, }, - enabled: true, - actions: [], }; const result = await alertType.executor(executorOptions); @@ -546,16 +570,22 @@ describe('alertType', () => { tags: [], createdBy: null, updatedBy: null, - createdAt: new Date(), - updatedAt: new Date(), - consumer: '', - throttle: null, - notifyWhen: null, - schedule: { - interval: '1h', + rule: { + name: uuid.v4(), + tags: [], + consumer: '', + enabled: true, + schedule: { + interval: '1h', + }, + actions: [], + createdBy: null, + updatedBy: null, + createdAt: new Date(), + updatedAt: new Date(), + throttle: null, + notifyWhen: null, }, - enabled: true, - actions: [], }); const instance: AlertInstanceMock = alertServices.alertInstanceFactory.mock.results[0].value; @@ -621,16 +651,22 @@ describe('alertType', () => { tags: [], createdBy: null, updatedBy: null, - createdAt: new Date(), - updatedAt: new Date(), - consumer: '', - throttle: null, - notifyWhen: null, - schedule: { - interval: '1h', + rule: { + name: uuid.v4(), + tags: [], + consumer: '', + enabled: true, + schedule: { + interval: '1h', + }, + actions: [], + createdBy: null, + updatedBy: null, + createdAt: new Date(), + updatedAt: new Date(), + throttle: null, + notifyWhen: null, }, - enabled: true, - actions: [], }); const instance: AlertInstanceMock = alertServices.alertInstanceFactory.mock.results[0].value;