Skip to content

Commit 04a0d77

Browse files
committed
Pass alert id to the alert type executor (#47379)
* Pass alert id to the alert type executor * Rename id to alertId * Rename id to alertId in actions plugin * Fix translation variables
1 parent 0bb4ce0 commit 04a0d77

20 files changed

Lines changed: 143 additions & 83 deletions

File tree

x-pack/legacy/plugins/actions/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ This is the primary function for an action type. Whenever the action needs to ex
7474

7575
|Property|Description|
7676
|---|---|
77+
|actionId|The action saved object id that the action type is executing for.|
7778
|config|The decrypted configuration given to an action. This comes from the action saved object that is partially or fully encrypted within the data store. If you would like to validate the config before being passed to the executor, define `validate.config` within the action type.|
7879
|params|Parameters for the execution. These will be given at execution time by either an alert or manually provided when calling the plugin provided execute function.|
7980
|services.callCluster(path, opts)|Use this to do Elasticsearch queries on the cluster Kibana connects to. This function is the same as any other `callCluster` in Kibana.<br><br>**NOTE**: This currently authenticates as the Kibana internal user, but will change in a future PR.|

x-pack/legacy/plugins/actions/server/builtin_action_types/email.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,14 @@ describe('execute()', () => {
183183
message: 'a message to you',
184184
};
185185

186-
const id = 'some-id';
187-
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
186+
const actionId = 'some-id';
187+
const executorOptions: ActionTypeExecutorOptions = {
188+
actionId,
189+
config,
190+
params,
191+
secrets,
192+
services,
193+
};
188194
sendEmailMock.mockReset();
189195
await actionType.executor(executorOptions);
190196
expect(sendEmailMock.mock.calls[0][1]).toMatchInlineSnapshot(`

x-pack/legacy/plugins/actions/server/builtin_action_types/email.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async function executor(
118118
{ logger }: { logger: Logger },
119119
execOptions: ActionTypeExecutorOptions
120120
): Promise<ActionTypeExecutorResult> {
121-
const id = execOptions.id;
121+
const actionId = execOptions.actionId;
122122
const config = execOptions.config as ActionTypeConfigType;
123123
const secrets = execOptions.secrets as ActionTypeSecretsType;
124124
const params = execOptions.params as ActionParamsType;
@@ -156,9 +156,9 @@ async function executor(
156156
result = await sendEmail(logger, sendEmailOptions);
157157
} catch (err) {
158158
const message = i18n.translate('xpack.actions.builtin.email.errorSendingErrorMessage', {
159-
defaultMessage: 'error in action "{id}" sending email: {errorMessage}',
159+
defaultMessage: 'error in action "{actionId}" sending email: {errorMessage}',
160160
values: {
161-
id,
161+
actionId,
162162
errorMessage: err.message,
163163
},
164164
});

x-pack/legacy/plugins/actions/server/builtin_action_types/es_index.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ describe('execute()', () => {
171171
refresh: undefined,
172172
};
173173

174-
const id = 'some-id';
174+
const actionId = 'some-id';
175175

176-
executorOptions = { id, config, secrets, params, services };
176+
executorOptions = { actionId, config, secrets, params, services };
177177
services.callCluster.mockClear();
178178
await actionType.executor(executorOptions);
179179

@@ -205,7 +205,7 @@ describe('execute()', () => {
205205
refresh: true,
206206
};
207207

208-
executorOptions = { id, config, secrets, params, services };
208+
executorOptions = { actionId, config, secrets, params, services };
209209
services.callCluster.mockClear();
210210
await actionType.executor(executorOptions);
211211

@@ -242,7 +242,7 @@ describe('execute()', () => {
242242
refresh: undefined,
243243
};
244244

245-
executorOptions = { id, config, secrets, params, services };
245+
executorOptions = { actionId, config, secrets, params, services };
246246
services.callCluster.mockClear();
247247
await actionType.executor(executorOptions);
248248

@@ -274,7 +274,7 @@ describe('execute()', () => {
274274
refresh: undefined,
275275
};
276276

277-
executorOptions = { id, config, secrets, params, services };
277+
executorOptions = { actionId, config, secrets, params, services };
278278
services.callCluster.mockClear();
279279
await actionType.executor(executorOptions);
280280

x-pack/legacy/plugins/actions/server/builtin_action_types/es_index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ async function executor(
5353
{ logger }: { logger: Logger },
5454
execOptions: ActionTypeExecutorOptions
5555
): Promise<ActionTypeExecutorResult> {
56-
const id = execOptions.id;
56+
const actionId = execOptions.actionId;
5757
const config = execOptions.config as ActionTypeConfigType;
5858
const params = execOptions.params as ActionParamsType;
5959
const services = execOptions.services;
6060

6161
if (config.index == null && params.index == null) {
6262
const message = i18n.translate('xpack.actions.builtin.esIndex.indexParamRequiredErrorMessage', {
63-
defaultMessage: 'index param needs to be set because not set in config for action {id}',
63+
defaultMessage: 'index param needs to be set because not set in config for action {actionId}',
6464
values: {
65-
id,
65+
actionId,
6666
},
6767
});
6868
return {
@@ -72,7 +72,7 @@ async function executor(
7272
}
7373

7474
if (config.index != null && params.index != null) {
75-
logger.debug(`index passed in params overridden by index set in config for action ${id}`);
75+
logger.debug(`index passed in params overridden by index set in config for action ${actionId}`);
7676
}
7777

7878
const index = config.index || params.index;
@@ -101,9 +101,9 @@ async function executor(
101101
result = await services.callCluster('bulk', bulkParams);
102102
} catch (err) {
103103
const message = i18n.translate('xpack.actions.builtin.esIndex.errorIndexingErrorMessage', {
104-
defaultMessage: 'error in action "{id}" indexing data: {errorMessage}',
104+
defaultMessage: 'error in action "{actionId}" indexing data: {errorMessage}',
105105
values: {
106-
id,
106+
actionId,
107107
errorMessage: err.message,
108108
},
109109
});

x-pack/legacy/plugins/actions/server/builtin_action_types/pagerduty.test.ts

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,14 @@ describe('execute()', () => {
119119
return { status: 202, data: 'data-here' };
120120
});
121121

122-
const id = 'some-action-id';
123-
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
122+
const actionId = 'some-action-id';
123+
const executorOptions: ActionTypeExecutorOptions = {
124+
actionId,
125+
config,
126+
params,
127+
secrets,
128+
services,
129+
};
124130
const actionResponse = await actionType.executor(executorOptions);
125131
const { apiUrl, data, headers } = postPagerdutyMock.mock.calls[0][0];
126132
expect({ apiUrl, data, headers }).toMatchInlineSnapshot(`
@@ -173,8 +179,14 @@ describe('execute()', () => {
173179
return { status: 202, data: 'data-here' };
174180
});
175181

176-
const id = 'some-action-id';
177-
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
182+
const actionId = 'some-action-id';
183+
const executorOptions: ActionTypeExecutorOptions = {
184+
actionId,
185+
config,
186+
params,
187+
secrets,
188+
services,
189+
};
178190
const actionResponse = await actionType.executor(executorOptions);
179191
const { apiUrl, data, headers } = postPagerdutyMock.mock.calls[0][0];
180192
expect({ apiUrl, data, headers }).toMatchInlineSnapshot(`
@@ -231,8 +243,14 @@ describe('execute()', () => {
231243
return { status: 202, data: 'data-here' };
232244
});
233245

234-
const id = 'some-action-id';
235-
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
246+
const actionId = 'some-action-id';
247+
const executorOptions: ActionTypeExecutorOptions = {
248+
actionId,
249+
config,
250+
params,
251+
secrets,
252+
services,
253+
};
236254
const actionResponse = await actionType.executor(executorOptions);
237255
const { apiUrl, data, headers } = postPagerdutyMock.mock.calls[0][0];
238256
expect({ apiUrl, data, headers }).toMatchInlineSnapshot(`
@@ -280,8 +298,14 @@ describe('execute()', () => {
280298
return { status: 202, data: 'data-here' };
281299
});
282300

283-
const id = 'some-action-id';
284-
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
301+
const actionId = 'some-action-id';
302+
const executorOptions: ActionTypeExecutorOptions = {
303+
actionId,
304+
config,
305+
params,
306+
secrets,
307+
services,
308+
};
285309
const actionResponse = await actionType.executor(executorOptions);
286310
const { apiUrl, data, headers } = postPagerdutyMock.mock.calls[0][0];
287311
expect({ apiUrl, data, headers }).toMatchInlineSnapshot(`
@@ -314,8 +338,14 @@ describe('execute()', () => {
314338
throw new Error('doing some testing');
315339
});
316340

317-
const id = 'some-action-id';
318-
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
341+
const actionId = 'some-action-id';
342+
const executorOptions: ActionTypeExecutorOptions = {
343+
actionId,
344+
config,
345+
params,
346+
secrets,
347+
services,
348+
};
319349
const actionResponse = await actionType.executor(executorOptions);
320350
expect(actionResponse).toMatchInlineSnapshot(`
321351
Object {
@@ -334,8 +364,14 @@ describe('execute()', () => {
334364
return { status: 429, data: 'data-here' };
335365
});
336366

337-
const id = 'some-action-id';
338-
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
367+
const actionId = 'some-action-id';
368+
const executorOptions: ActionTypeExecutorOptions = {
369+
actionId,
370+
config,
371+
params,
372+
secrets,
373+
services,
374+
};
339375
const actionResponse = await actionType.executor(executorOptions);
340376
expect(actionResponse).toMatchInlineSnapshot(`
341377
Object {
@@ -355,8 +391,14 @@ describe('execute()', () => {
355391
return { status: 501, data: 'data-here' };
356392
});
357393

358-
const id = 'some-action-id';
359-
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
394+
const actionId = 'some-action-id';
395+
const executorOptions: ActionTypeExecutorOptions = {
396+
actionId,
397+
config,
398+
params,
399+
secrets,
400+
services,
401+
};
360402
const actionResponse = await actionType.executor(executorOptions);
361403
expect(actionResponse).toMatchInlineSnapshot(`
362404
Object {
@@ -376,8 +418,14 @@ describe('execute()', () => {
376418
return { status: 418, data: 'data-here' };
377419
});
378420

379-
const id = 'some-action-id';
380-
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
421+
const actionId = 'some-action-id';
422+
const executorOptions: ActionTypeExecutorOptions = {
423+
actionId,
424+
config,
425+
params,
426+
secrets,
427+
services,
428+
};
381429
const actionResponse = await actionType.executor(executorOptions);
382430
expect(actionResponse).toMatchInlineSnapshot(`
383431
Object {

x-pack/legacy/plugins/actions/server/builtin_action_types/pagerduty.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ async function executor(
105105
{ logger }: { logger: Logger },
106106
execOptions: ActionTypeExecutorOptions
107107
): Promise<ActionTypeExecutorResult> {
108-
const id = execOptions.id;
108+
const actionId = execOptions.actionId;
109109
const config = execOptions.config as ActionTypeConfigType;
110110
const secrets = execOptions.secrets as ActionTypeSecretsType;
111111
const params = execOptions.params as ActionParamsType;
@@ -116,16 +116,16 @@ async function executor(
116116
'Content-Type': 'application/json',
117117
'X-Routing-Key': secrets.routingKey,
118118
};
119-
const data = getBodyForEventAction(id, params);
119+
const data = getBodyForEventAction(actionId, params);
120120

121121
let response;
122122
try {
123123
response = await postPagerduty({ apiUrl, data, headers, services });
124124
} catch (err) {
125125
const message = i18n.translate('xpack.actions.builtin.pagerduty.postingErrorMessage', {
126-
defaultMessage: 'error in pagerduty action "{id}" posting event: {errorMessage}',
126+
defaultMessage: 'error in pagerduty action "{actionId}" posting event: {errorMessage}',
127127
values: {
128-
id,
128+
actionId,
129129
errorMessage: err.message,
130130
},
131131
});
@@ -148,9 +148,9 @@ async function executor(
148148
if (response.status === 429 || response.status >= 500) {
149149
const message = i18n.translate('xpack.actions.builtin.pagerduty.postingRetryErrorMessage', {
150150
defaultMessage:
151-
'error in pagerduty action "{id}" posting event: status {status}, retry later',
151+
'error in pagerduty action "{actionId}" posting event: status {status}, retry later',
152152
values: {
153-
id,
153+
actionId,
154154
status: response.status,
155155
},
156156
});
@@ -163,9 +163,10 @@ async function executor(
163163
}
164164

165165
const message = i18n.translate('xpack.actions.builtin.pagerduty.postingUnexpectedErrorMessage', {
166-
defaultMessage: 'error in pagerduty action "{id}" posting event: unexpected status {status}',
166+
defaultMessage:
167+
'error in pagerduty action "{actionId}" posting event: unexpected status {status}',
167168
values: {
168-
id,
169+
actionId,
169170
status: response.status,
170171
},
171172
});

x-pack/legacy/plugins/actions/server/builtin_action_types/server_log.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ describe('validateParams()', () => {
8787

8888
describe('execute()', () => {
8989
test('calls the executor with proper params', async () => {
90-
const id = 'some-id';
90+
const actionId = 'some-id';
9191
await actionType.executor({
92-
id,
92+
actionId,
9393
services: {
9494
callCluster: async (path: string, opts: any) => {},
9595
savedObjectsClient: SavedObjectsClientMock.create(),

x-pack/legacy/plugins/actions/server/builtin_action_types/server_log.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ async function executor(
4545
{ logger }: { logger: Logger },
4646
execOptions: ActionTypeExecutorOptions
4747
): Promise<ActionTypeExecutorResult> {
48-
const id = execOptions.id;
48+
const actionId = execOptions.actionId;
4949
const params = execOptions.params as ActionParamsType;
5050

5151
try {
5252
logger[params.level](params.message);
5353
} catch (err) {
5454
const message = i18n.translate('xpack.actions.builtin.serverLog.errorLoggingErrorMessage', {
55-
defaultMessage: 'error in action "{id}" logging message: {errorMessage}',
55+
defaultMessage: 'error in action "{actionId}" logging message: {errorMessage}',
5656
values: {
57-
id,
57+
actionId,
5858
errorMessage: err.message,
5959
},
6060
});

x-pack/legacy/plugins/actions/server/builtin_action_types/slack.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('validateActionTypeSecrets()', () => {
109109
describe('execute()', () => {
110110
test('calls the mock executor with success', async () => {
111111
const response = await actionType.executor({
112-
id: 'some-id',
112+
actionId: 'some-id',
113113
services,
114114
config: {},
115115
secrets: { webhookUrl: 'http://example.com' },
@@ -125,7 +125,7 @@ Object {
125125
test('calls the mock executor with failure', async () => {
126126
await expect(
127127
actionType.executor({
128-
id: 'some-id',
128+
actionId: 'some-id',
129129
services,
130130
config: {},
131131
secrets: { webhookUrl: 'http://example.com' },

0 commit comments

Comments
 (0)