From c7c074756dcb999f9fdf4c153c5445a00653fa44 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 23 Jun 2023 18:06:26 -0400 Subject: [PATCH] [8.8] [ResponseOps][Alerting] Some legacy mustache variables are not rendering for Security Solution rules after upgrading to 8.8.x (#160451) (#160459) # Backport This will backport the following commits from `main` to `8.8`: - [[ResponseOps][Alerting] Some legacy mustache variables are not rendering for Security Solution rules after upgrading to 8.8.x (#160451)](https://github.com/elastic/kibana/pull/160451) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Alexi Doak <109488926+doakalexi@users.noreply.github.com> --- .../transform_action_params.test.ts | 118 ++++++++++++++++++ .../task_runner/transform_action_params.ts | 15 +++ 2 files changed, 133 insertions(+) diff --git a/x-pack/plugins/alerting/server/task_runner/transform_action_params.test.ts b/x-pack/plugins/alerting/server/task_runner/transform_action_params.test.ts index a8889bc620c83f..14eb0b386f5aa6 100644 --- a/x-pack/plugins/alerting/server/task_runner/transform_action_params.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/transform_action_params.test.ts @@ -724,4 +724,122 @@ describe('transformSummaryActionParams', () => { expect(dateVariable).toBeGreaterThanOrEqual(dateBefore); expect(dateVariable).toBeLessThanOrEqual(dateAfter); }); + + test('renders alertId', () => { + const actionParams = { + message: 'Value: {{alertId}}', + }; + + const result = transformSummaryActionParams({ ...params, actionParams }); + expect(result).toMatchInlineSnapshot(` + Object { + "message": "Value: 1", + } + `); + }); + + test('renders alertName', () => { + const actionParams = { + message: 'Value: {{alertName}}', + }; + + const result = transformSummaryActionParams({ ...params, actionParams }); + expect(result).toMatchInlineSnapshot(` + Object { + "message": "Value: test-rule", + } + `); + }); + + test('renders spaceId', () => { + const actionParams = { + message: 'Value: {{spaceId}}', + }; + + const result = transformSummaryActionParams({ ...params, actionParams }); + expect(result).toMatchInlineSnapshot(` + Object { + "message": "Value: space-id", + } + `); + }); + + test('renders tags', () => { + const actionParams = { + message: 'Value: {{tags}}', + }; + + const result = transformSummaryActionParams({ ...params, actionParams }); + expect(result).toMatchInlineSnapshot(` + Object { + "message": "Value: test-tag", + } + `); + }); + + test('renders params', () => { + const actionParams = { + message: 'Value: {{params}}', + }; + + const result = transformSummaryActionParams({ ...params, actionParams }); + expect(result).toMatchInlineSnapshot(` + Object { + "message": "Value: {\\"foo\\":\\"bar\\",\\"fooBar\\":true}", + } + `); + }); + + test('renders alertInstanceId', () => { + const actionParams = { + message: 'Value: {{alertInstanceId}}', + }; + + const result = transformSummaryActionParams({ ...params, actionParams }); + expect(result).toMatchInlineSnapshot(` + Object { + "message": "Value: 1", + } + `); + }); + + test('renders alertActionGroup', () => { + const actionParams = { + message: 'Value: {{alertActionGroup}}', + }; + + const result = transformSummaryActionParams({ ...params, actionParams }); + expect(result).toMatchInlineSnapshot(` + Object { + "message": "Value: default", + } + `); + }); + + test('renders alertActionGroupName', () => { + const actionParams = { + message: 'Value: {{alertActionGroupName}}', + }; + + const result = transformSummaryActionParams({ ...params, actionParams }); + expect(result).toMatchInlineSnapshot(` + Object { + "message": "Value: Default", + } + `); + }); + + test('renders alert values', () => { + const actionParams = { + message: + 'Value "{{alert.id}}", "{{alert.uuid}}", "{{alert.actionGroup}}", "{{alert.actionGroupName}}", and "{{alert.flapping}}" exist', + }; + + const result = transformSummaryActionParams({ ...params, actionParams }); + expect(result).toMatchInlineSnapshot(` + Object { + "message": "Value \\"1\\", \\"1\\", \\"default\\", \\"Default\\", and \\"false\\" exist", + } + `); + }); }); diff --git a/x-pack/plugins/alerting/server/task_runner/transform_action_params.ts b/x-pack/plugins/alerting/server/task_runner/transform_action_params.ts index b4a3727863169d..7076e1fc7e35ec 100644 --- a/x-pack/plugins/alerting/server/task_runner/transform_action_params.ts +++ b/x-pack/plugins/alerting/server/task_runner/transform_action_params.ts @@ -142,6 +142,21 @@ export function transformSummaryActionParams({ ruleUrl?: string; }): RuleActionParams { const variables = { + alertId: rule.id, + alertName: rule.name, + spaceId, + tags: rule.tags, + params: rule.params, + alertInstanceId: rule.id, + alertActionGroup: 'default', + alertActionGroupName: 'Default', + alert: { + id: rule.id, + uuid: rule.id, + actionGroup: 'default', + actionGroupName: 'Default', + flapping: false, + }, kibanaBaseUrl, date: new Date().toISOString(), // For backwards compatibility with security solutions rules