Skip to content

Commit

Permalink
[8.8] [ResponseOps][Alerting] Some legacy mustache variables are not …
Browse files Browse the repository at this point in the history
…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)](#160451)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Alexi
Doak","email":"109488926+doakalexi@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-06-23T20:34:31Z","message":"[ResponseOps][Alerting]
Some legacy mustache variables are not rendering for Security Solution
rules after upgrading to 8.8.x (#160451)\n\nResolves
#160446
Summary\r\n\r\nAdding the following variables
to\r\n`x-pack/plugins/alerting/server/task_runner/transform_action_params.ts`:\r\n\r\n-
alertId\r\n- alertName\r\n- spaceId\r\n- tags\r\n- params\r\n-
alertInstanceId\r\n- alertActionGroup\r\n- alertActionGroupName\r\n-
alert.id\r\n- alert.uuid\r\n- alert.actionGroup\r\n-
alert.actionGroupName\r\n- alert.flapping\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"857ca82352d5bec70814b52d524fbe4c8757625a","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","v8.8.0","v8.9.0","v8.10.0"],"number":160451,"url":"#160451
Some legacy mustache variables are not rendering for Security Solution
rules after upgrading to 8.8.x (#160451)\n\nResolves
#160446
Summary\r\n\r\nAdding the following variables
to\r\n`x-pack/plugins/alerting/server/task_runner/transform_action_params.ts`:\r\n\r\n-
alertId\r\n- alertName\r\n- spaceId\r\n- tags\r\n- params\r\n-
alertInstanceId\r\n- alertActionGroup\r\n- alertActionGroupName\r\n-
alert.id\r\n- alert.uuid\r\n- alert.actionGroup\r\n-
alert.actionGroupName\r\n- alert.flapping\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"857ca82352d5bec70814b52d524fbe4c8757625a"}},"sourceBranch":"main","suggestedTargetBranches":["8.8","8.9"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"#160451
Some legacy mustache variables are not rendering for Security Solution
rules after upgrading to 8.8.x (#160451)\n\nResolves
#160446
Summary\r\n\r\nAdding the following variables
to\r\n`x-pack/plugins/alerting/server/task_runner/transform_action_params.ts`:\r\n\r\n-
alertId\r\n- alertName\r\n- spaceId\r\n- tags\r\n- params\r\n-
alertInstanceId\r\n- alertActionGroup\r\n- alertActionGroupName\r\n-
alert.id\r\n- alert.uuid\r\n- alert.actionGroup\r\n-
alert.actionGroupName\r\n- alert.flapping\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"857ca82352d5bec70814b52d524fbe4c8757625a"}}]}]
BACKPORT-->

Co-authored-by: Alexi Doak <109488926+doakalexi@users.noreply.github.com>
  • Loading branch information
kibanamachine and doakalexi committed Jun 23, 2023
1 parent 3e974f3 commit c7c0747
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 0 deletions.
Expand Up @@ -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",
}
`);
});
});
Expand Up @@ -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
Expand Down

0 comments on commit c7c0747

Please sign in to comment.