Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ test('enqueues execution per selected action', async () => {
`);

expect(jest.requireMock('./inject_action_params').injectActionParams).toHaveBeenCalledWith({
alertId: '1',
ruleId: '1',
spaceId: 'default',
actionTypeId: 'test',
actionParams: {
alertVal: 'My 1 name-of-alert default tag-A,tag-B 2 goes here',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ export function createExecutionHandler<
.map((action) => ({
...action,
params: injectActionParams({
alertId,
ruleId: alertId,
spaceId,
actionParams: action.params,
actionTypeId: action.actionTypeId,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ describe('injectActionParams', () => {
};
const result = injectActionParams({
actionParams,
alertId: '1',
ruleId: '1',
spaceId: 'the-space',
actionTypeId: '.server-log',
});
expect(result).toMatchInlineSnapshot(`
Expand All @@ -32,7 +33,8 @@ describe('injectActionParams', () => {
};
const result = injectActionParams({
actionParams,
alertId: '1',
ruleId: '1',
spaceId: 'default',
actionTypeId: '.email',
});
expect(result).toMatchInlineSnapshot(`
Expand All @@ -41,8 +43,58 @@ describe('injectActionParams', () => {
"message": "State: \\"{{state.value}}\\", Context: \\"{{context.value}}\\"",
},
"kibanaFooterLink": Object {
"path": "/app/management/insightsAndAlerting/triggersActions/alert/1",
"text": "View alert in Kibana",
"path": "/app/management/insightsAndAlerting/triggersActions/rule/1",
"text": "View rule in Kibana",
},
}
`);
});

test('injects viewInKibanaPath and viewInKibanaText when actionTypeId is .email and spaceId is undefined', () => {
const actionParams = {
body: {
message: 'State: "{{state.value}}", Context: "{{context.value}}"',
},
};
const result = injectActionParams({
actionParams,
ruleId: '1',
spaceId: undefined,
actionTypeId: '.email',
});
expect(result).toMatchInlineSnapshot(`
Object {
"body": Object {
"message": "State: \\"{{state.value}}\\", Context: \\"{{context.value}}\\"",
},
"kibanaFooterLink": Object {
"path": "/app/management/insightsAndAlerting/triggersActions/rule/1",
"text": "View rule in Kibana",
},
}
`);
});

test('injects viewInKibanaPath with space ID and viewInKibanaText when actionTypeId is .email', () => {
const actionParams = {
body: {
message: 'State: "{{state.value}}", Context: "{{context.value}}"',
},
};
const result = injectActionParams({
actionParams,
ruleId: '1',
spaceId: 'not-the-default',
actionTypeId: '.email',
});
expect(result).toMatchInlineSnapshot(`
Object {
"body": Object {
"message": "State: \\"{{state.value}}\\", Context: \\"{{context.value}}\\"",
},
"kibanaFooterLink": Object {
"path": "/s/not-the-default/app/management/insightsAndAlerting/triggersActions/rule/1",
"text": "View rule in Kibana",
},
}
`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,29 @@ import { i18n } from '@kbn/i18n';
import { AlertActionParams } from '../types';

export interface InjectActionParamsOpts {
alertId: string;
ruleId: string;
spaceId: string | undefined;
actionTypeId: string;
actionParams: AlertActionParams;
}

export function injectActionParams({
alertId,
ruleId,
spaceId,
actionTypeId,
actionParams,
}: InjectActionParamsOpts) {
// Inject kibanaFooterLink if action type is email. This is used by the email action type
// to inject a "View alert in Kibana" with a URL in the email's footer.
if (actionTypeId === '.email') {
const spacePrefix =
spaceId && spaceId.length > 0 && spaceId !== 'default' ? `/s/${spaceId}` : '';
return {
...actionParams,
kibanaFooterLink: {
path: `/app/management/insightsAndAlerting/triggersActions/alert/${alertId}`,
path: `${spacePrefix}/app/management/insightsAndAlerting/triggersActions/rule/${ruleId}`,
text: i18n.translate('xpack.alerting.injectActionParams.email.kibanaFooterLinkText', {
defaultMessage: 'View alert in Kibana',
defaultMessage: 'View rule in Kibana',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

}),
},
};
Expand Down