[Alerting] Update alerting action variables to follow new terminology (#93836)

* Removing duplicate ActionVariable interface. Updating common action variables in UI

* Passing in alert values as rule variables in transform_action_params

* Fixing unit tests

* Fixing functional test

* Adding functiional test

* Updating paths

* Fixing i18n

* Fixing i18n

* Fixing api docs

* Plugin api build

* Moving spaceId and tags under rule prefix

* Using top level alert prefix

* Fixing i18n

* build api docs

* Fixing functional test

* Fixing functional test
This commit is contained in:
ymao1 2021-03-09 07:48:38 -05:00 committed by GitHub
parent ed2a1bfb1f
commit 023d9a028b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 934 additions and 517 deletions

View file

@ -197,56 +197,6 @@
},
"initialIsOpen": false
},
{
"id": "def-server.ActionVariable",
"type": "Interface",
"label": "ActionVariable",
"description": [],
"tags": [],
"children": [
{
"tags": [],
"id": "def-server.ActionVariable.name",
"type": "string",
"label": "name",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 106
}
},
{
"tags": [],
"id": "def-server.ActionVariable.description",
"type": "string",
"label": "description",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 107
}
},
{
"tags": [],
"id": "def-server.ActionVariable.useWithTripleBracesInTemplates",
"type": "CompoundType",
"label": "useWithTripleBracesInTemplates",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 108
},
"signature": [
"boolean | undefined"
]
}
],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 105
},
"initialIsOpen": false
},
{
"id": "def-server.AlertExecutorOptions",
"type": "Interface",
@ -272,7 +222,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 91
"lineNumber": 92
}
},
{
@ -283,7 +233,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 92
"lineNumber": 93
},
"signature": [
"Date"
@ -297,7 +247,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 93
"lineNumber": 94
},
"signature": [
"Date | null"
@ -311,7 +261,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 94
"lineNumber": 95
},
"signature": [
{
@ -332,7 +282,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 95
"lineNumber": 96
},
"signature": [
"Params"
@ -346,7 +296,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 96
"lineNumber": 97
},
"signature": [
"State"
@ -360,7 +310,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 97
"lineNumber": 98
}
},
{
@ -371,7 +321,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 98
"lineNumber": 99
},
"signature": [
"string | undefined"
@ -385,7 +335,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 99
"lineNumber": 100
}
},
{
@ -396,7 +346,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 100
"lineNumber": 101
},
"signature": [
"string[]"
@ -410,7 +360,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 101
"lineNumber": 102
},
"signature": [
"string | null"
@ -424,7 +374,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 102
"lineNumber": 103
},
"signature": [
"string | null"
@ -433,7 +383,7 @@
],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 84
"lineNumber": 85
},
"initialIsOpen": false
},
@ -454,7 +404,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 47
"lineNumber": 48
},
"signature": [
"() => ",
@ -475,7 +425,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 48
"lineNumber": 49
},
"signature": [
"() => Set<",
@ -497,7 +447,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 49
"lineNumber": 50
},
"signature": [
"() => Promise<",
@ -514,7 +464,7 @@
],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 46
"lineNumber": 47
},
"initialIsOpen": false
},
@ -533,7 +483,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 231
"lineNumber": 226
},
"signature": [
{
@ -553,7 +503,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 232
"lineNumber": 227
},
"signature": [
{
@ -568,7 +518,7 @@
],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 230
"lineNumber": 225
},
"initialIsOpen": false
},
@ -598,7 +548,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 79
"lineNumber": 80
},
"signature": [
"(id: string) => Pick<",
@ -615,7 +565,7 @@
],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 74
"lineNumber": 75
},
"initialIsOpen": false
},
@ -644,7 +594,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 132
"lineNumber": 127
}
},
{
@ -655,7 +605,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 133
"lineNumber": 128
}
},
{
@ -666,7 +616,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 134
"lineNumber": 129
},
"signature": [
"{ params?: ",
@ -688,7 +638,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 137
"lineNumber": 132
},
"signature": [
{
@ -709,7 +659,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 138
"lineNumber": 133
},
"signature": [
"ActionGroupIds"
@ -723,7 +673,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 139
"lineNumber": 134
},
"signature": [
{
@ -744,7 +694,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 140
"lineNumber": 135
},
"signature": [
{
@ -773,7 +723,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 151
"lineNumber": 146
}
},
{
@ -784,31 +734,31 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 152
"lineNumber": 147
},
"signature": [
"{ context?: ",
{
"pluginId": "alerting",
"scope": "server",
"scope": "common",
"docId": "kibAlertingPluginApi",
"section": "def-server.ActionVariable",
"section": "def-common.ActionVariable",
"text": "ActionVariable"
},
"[] | undefined; state?: ",
{
"pluginId": "alerting",
"scope": "server",
"scope": "common",
"docId": "kibAlertingPluginApi",
"section": "def-server.ActionVariable",
"section": "def-common.ActionVariable",
"text": "ActionVariable"
},
"[] | undefined; params?: ",
{
"pluginId": "alerting",
"scope": "server",
"scope": "common",
"docId": "kibAlertingPluginApi",
"section": "def-server.ActionVariable",
"section": "def-common.ActionVariable",
"text": "ActionVariable"
},
"[] | undefined; } | undefined"
@ -822,7 +772,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 157
"lineNumber": 152
},
"signature": [
"\"basic\" | \"standard\" | \"gold\" | \"platinum\" | \"enterprise\" | \"trial\""
@ -831,7 +781,7 @@
],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 124
"lineNumber": 119
},
"initialIsOpen": false
},
@ -1227,7 +1177,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/alerting/server/types.ts",
"lineNumber": 190
"lineNumber": 185
},
"signature": [
"Pick<Alert<Params>, \"id\"> & Partial<Pick<Alert<Params>, \"enabled\" | \"name\" | \"params\" | \"actions\" | \"muteAll\" | \"apiKey\" | \"tags\" | \"alertTypeId\" | \"consumer\" | \"schedule\" | \"scheduledTaskId\" | \"createdBy\" | \"updatedBy\" | \"createdAt\" | \"updatedAt\" | \"apiKeyOwner\" | \"throttle\" | \"notifyWhen\" | \"mutedInstanceIds\" | \"executionStatus\">>"
@ -1567,6 +1517,70 @@
},
"initialIsOpen": false
},
{
"id": "def-common.ActionVariable",
"type": "Interface",
"label": "ActionVariable",
"description": [],
"tags": [],
"children": [
{
"tags": [],
"id": "def-common.ActionVariable.name",
"type": "string",
"label": "name",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/common/alert.ts",
"lineNumber": 102
}
},
{
"tags": [],
"id": "def-common.ActionVariable.description",
"type": "string",
"label": "description",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/common/alert.ts",
"lineNumber": 103
}
},
{
"tags": [],
"id": "def-common.ActionVariable.deprecated",
"type": "CompoundType",
"label": "deprecated",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/common/alert.ts",
"lineNumber": 104
},
"signature": [
"boolean | undefined"
]
},
{
"tags": [],
"id": "def-common.ActionVariable.useWithTripleBracesInTemplates",
"type": "CompoundType",
"label": "useWithTripleBracesInTemplates",
"description": [],
"source": {
"path": "x-pack/plugins/alerting/common/alert.ts",
"lineNumber": 105
},
"signature": [
"boolean | undefined"
]
}
],
"source": {
"path": "x-pack/plugins/alerting/common/alert.ts",
"lineNumber": 101
},
"initialIsOpen": false
},
{
"id": "def-common.Alert",
"type": "Interface",

View file

@ -927,56 +927,6 @@
},
"initialIsOpen": false
},
{
"id": "def-public.ActionVariable",
"type": "Interface",
"label": "ActionVariable",
"description": [],
"tags": [],
"children": [
{
"tags": [],
"id": "def-public.ActionVariable.name",
"type": "string",
"label": "name",
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 161
}
},
{
"tags": [],
"id": "def-public.ActionVariable.description",
"type": "string",
"label": "description",
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 162
}
},
{
"tags": [],
"id": "def-public.ActionVariable.useWithTripleBracesInTemplates",
"type": "CompoundType",
"label": "useWithTripleBracesInTemplates",
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 163
},
"signature": [
"boolean | undefined"
]
}
],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 160
},
"initialIsOpen": false
},
{
"id": "def-public.AggregationType",
"type": "Interface",
@ -1130,7 +1080,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 227
"lineNumber": 222
}
},
{
@ -1141,7 +1091,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 228
"lineNumber": 223
}
},
{
@ -1152,7 +1102,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 229
"lineNumber": 224
}
},
{
@ -1163,7 +1113,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 230
"lineNumber": 225
},
"signature": [
"string | ((docLinks: ",
@ -1185,7 +1135,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 231
"lineNumber": 226
},
"signature": [
"(alertParams: Params) => ",
@ -1206,7 +1156,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 232
"lineNumber": 227
},
"signature": [
"React.FunctionComponent<any> | React.LazyExoticComponent<React.ComponentType<",
@ -1228,7 +1178,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 235
"lineNumber": 230
}
},
{
@ -1239,7 +1189,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 236
"lineNumber": 231
},
"signature": [
"string | undefined"
@ -1248,7 +1198,7 @@
],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 226
"lineNumber": 221
},
"initialIsOpen": false
},
@ -1277,7 +1227,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 209
"lineNumber": 204
},
"signature": [
"Params"
@ -1291,7 +1241,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 210
"lineNumber": 205
}
},
{
@ -1302,7 +1252,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 211
"lineNumber": 206
}
},
{
@ -1313,7 +1263,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 212
"lineNumber": 207
},
"signature": [
"\"onActionGroupChange\" | \"onActiveAlert\" | \"onThrottleInterval\""
@ -1327,7 +1277,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 213
"lineNumber": 208
},
"signature": [
"<Key extends keyof Params>(property: Key, value: Params[Key] | undefined) => void"
@ -1341,7 +1291,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 214
"lineNumber": 209
},
"signature": [
"<Prop extends \"enabled\" | \"id\" | \"name\" | \"params\" | \"actions\" | \"muteAll\" | \"tags\" | \"alertTypeId\" | \"consumer\" | \"schedule\" | \"scheduledTaskId\" | \"createdBy\" | \"updatedBy\" | \"createdAt\" | \"updatedAt\" | \"apiKeyOwner\" | \"throttle\" | \"notifyWhen\" | \"mutedInstanceIds\" | \"executionStatus\">(key: Prop, value: Pick<",
@ -1363,7 +1313,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 218
"lineNumber": 213
},
"signature": [
{
@ -1383,7 +1333,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 219
"lineNumber": 214
}
},
{
@ -1394,7 +1344,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 220
"lineNumber": 215
},
"signature": [
{
@ -1415,7 +1365,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 221
"lineNumber": 216
},
"signature": [
"MetaData | undefined"
@ -1429,7 +1379,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 222
"lineNumber": 217
},
"signature": [
{
@ -1449,7 +1399,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 223
"lineNumber": 218
},
"signature": [
{
@ -1464,7 +1414,7 @@
],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 204
"lineNumber": 199
},
"initialIsOpen": false
},
@ -1591,7 +1541,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 240
"lineNumber": 235
},
"signature": [
"any"
@ -1600,7 +1550,7 @@
],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 239
"lineNumber": 234
},
"initialIsOpen": false
},
@ -1924,7 +1874,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 115
"lineNumber": 116
},
"signature": [
"Record<string, any>"
@ -1933,7 +1883,7 @@
],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 114
"lineNumber": 115
},
"initialIsOpen": false
}
@ -1959,7 +1909,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 66
"lineNumber": 67
},
"initialIsOpen": false
},
@ -1997,7 +1947,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 147
"lineNumber": 148
},
"signature": [
"PreConfiguredActionConnector",
@ -2045,7 +1995,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 51
"lineNumber": 52
},
"signature": [
"{ get: (id: string) => ActionTypeModel<ActionConnector, ActionParams, any>; register: (objectType: ActionTypeModel<ActionConnector, ActionParams, any>) => void; list: () => ActionTypeModel<ActionConnector, ActionParams, any>[]; has: (id: string) => boolean; }"
@ -2060,7 +2010,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 171
"lineNumber": 166
},
"signature": [
"AsActionVariables<\"params\" | \"state\"> & Partial<AsActionVariables<\"context\">>"
@ -2075,7 +2025,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 33
"lineNumber": 34
},
"signature": [
"{ enabled: boolean; id: string; name: string; params: Record<string, unknown>; actions: AlertAction[]; muteAll: boolean; tags: string[]; alertTypeId: string; consumer: string; schedule: ",
@ -2121,7 +2071,7 @@
"description": [],
"source": {
"path": "x-pack/plugins/triggers_actions_ui/public/types.ts",
"lineNumber": 55
"lineNumber": 56
},
"signature": [
"{ get: (id: string) => AlertTypeModel<Record<string, unknown>>; register: (objectType: AlertTypeModel<Record<string, unknown>>) => void; list: () => AlertTypeModel<Record<string, unknown>>[]; has: (id: string) => boolean; }"

View file

@ -97,3 +97,10 @@ export interface AlertsHealth {
timestamp: string;
};
}
export interface ActionVariable {
name: string;
description: string;
deprecated?: boolean;
useWithTripleBracesInTemplates?: boolean;
}

View file

@ -15,7 +15,6 @@ import { AlertsConfigType } from './types';
export type AlertsClient = PublicMethodsOf<AlertsClientClass>;
export type {
ActionVariable,
AlertType,
ActionGroup,
ActionGroupIdsOf,

View file

@ -369,6 +369,61 @@ test('alertActionGroupName is passed to templates', () => {
`);
});
test('rule variables are passed to templates', () => {
const actionParams = {
message: 'Value "{{rule.id}}", "{{rule.name}}", "{{rule.spaceId}}" and "{{rule.tags}}" exist',
};
const result = transformActionParams({
actionsPlugin,
actionTypeId,
actionParams,
state: {},
context: {},
alertId: '1',
alertName: 'alert-name',
tags: ['tag-A', 'tag-B'],
spaceId: 'spaceId-A',
alertInstanceId: '2',
alertActionGroup: 'action-group',
alertActionGroupName: 'Action Group',
alertActionSubgroup: 'subgroup',
alertParams: {},
});
expect(result).toMatchInlineSnapshot(`
Object {
"message": "Value \\"1\\", \\"alert-name\\", \\"spaceId-A\\" and \\"tag-A,tag-B\\" exist",
}
`);
});
test('rule alert variables are passed to templates', () => {
const actionParams = {
message:
'Value "{{alert.id}}", "{{alert.actionGroup}}", "{{alert.actionGroupName}}" and "{{alert.actionSubgroup}}" exist',
};
const result = transformActionParams({
actionsPlugin,
actionTypeId,
actionParams,
state: {},
context: {},
alertId: '1',
alertName: 'alert-name',
tags: ['tag-A', 'tag-B'],
spaceId: 'spaceId-A',
alertInstanceId: '2',
alertActionGroup: 'action-group',
alertActionGroupName: 'Action Group',
alertActionSubgroup: 'subgroup',
alertParams: {},
});
expect(result).toMatchInlineSnapshot(`
Object {
"message": "Value \\"2\\", \\"action-group\\", \\"Action Group\\" and \\"subgroup\\" exist",
}
`);
});
test('date is passed to templates', () => {
const actionParams = {
message: '{{date}}',

View file

@ -65,6 +65,18 @@ export function transformActionParams({
state,
kibanaBaseUrl,
params: alertParams,
rule: {
id: alertId,
name: alertName,
spaceId,
tags,
},
alert: {
id: alertInstanceId,
actionGroup: alertActionGroup,
actionGroupName: alertActionGroupName,
actionSubgroup: alertActionSubgroup,
},
};
return actionsPlugin.renderActionParameterTemplates(actionTypeId, actionParams, variables);
}

View file

@ -33,6 +33,7 @@ import {
AlertsHealth,
AlertNotifyWhenType,
WithoutReservedActionGroups,
ActionVariable,
} from '../common';
import { LicenseType } from '../../licensing/server';
@ -102,12 +103,6 @@ export interface AlertExecutorOptions<
updatedBy: string | null;
}
export interface ActionVariable {
name: string;
description: string;
useWithTripleBracesInTemplates?: boolean;
}
export type ExecutorType<
Params extends AlertTypeParams = never,
State extends AlertTypeState = never,

View file

@ -22207,16 +22207,7 @@
"xpack.transform.transformsWizard.transformDocsLinkText": "変換ドキュメント",
"xpack.transform.wizard.nextStepButton": "次へ",
"xpack.transform.wizard.previousStepButton": "前へ",
"xpack.triggersActionsUI.actionVariables.alertActionGroupLabel": "アラートのスケジュールされたアクションに使用されたアラートアクショングループ。",
"xpack.triggersActionsUI.actionVariables.alertActionGroupNameLabel": "アラートのスケジュールされたアクションに使用されたアラートアクショングループの人間が読み取れる名前。",
"xpack.triggersActionsUI.actionVariables.alertActionSubgroupLabel": "アラートのスケジュールされたアクションに使用されたアラートアクションサブグループ。",
"xpack.triggersActionsUI.actionVariables.alertIdLabel": "アラートの ID。",
"xpack.triggersActionsUI.actionVariables.alertInstanceIdLabel": "アラートのアクションを予定したアラートインスタンス ID。",
"xpack.triggersActionsUI.actionVariables.alertNameLabel": "アラートの名前。",
"xpack.triggersActionsUI.actionVariables.dateLabel": "アラートがアクションをスケジュールした日付。",
"xpack.triggersActionsUI.actionVariables.kibanaBaseUrlLabel": "構成したserver.publicBaseUrl値。構成していない場合は、空の文字列。",
"xpack.triggersActionsUI.actionVariables.spaceIdLabel": "アラートのスペース ID。",
"xpack.triggersActionsUI.actionVariables.tagsLabel": "アラートのタグ。",
"xpack.triggersActionsUI.alerts.breadcrumbTitle": "アラート",
"xpack.triggersActionsUI.appName": "アラートとアクション",
"xpack.triggersActionsUI.case.configureCases.mappingFieldSummary": "まとめ",

View file

@ -22559,16 +22559,7 @@
"xpack.transform.transformsWizard.transformDocsLinkText": "转换文档",
"xpack.transform.wizard.nextStepButton": "下一步",
"xpack.transform.wizard.previousStepButton": "上一步",
"xpack.triggersActionsUI.actionVariables.alertActionGroupLabel": "用于为告警计划操作的告警操作组。",
"xpack.triggersActionsUI.actionVariables.alertActionGroupNameLabel": "用于为告警计划操作的告警操作组的可人工读取名称。",
"xpack.triggersActionsUI.actionVariables.alertActionSubgroupLabel": "用于为告警计划操作的告警操作子组。",
"xpack.triggersActionsUI.actionVariables.alertIdLabel": "告警的 ID。",
"xpack.triggersActionsUI.actionVariables.alertInstanceIdLabel": "为告警排定操作的告警实例 ID。",
"xpack.triggersActionsUI.actionVariables.alertNameLabel": "告警的名称。",
"xpack.triggersActionsUI.actionVariables.dateLabel": "告警计划操作的日期。",
"xpack.triggersActionsUI.actionVariables.kibanaBaseUrlLabel": "配置的 server.publicBaseUrl 值,如果未配置,则为空字符串。",
"xpack.triggersActionsUI.actionVariables.spaceIdLabel": "告警的 spaceId。",
"xpack.triggersActionsUI.actionVariables.tagsLabel": "告警的标签。",
"xpack.triggersActionsUI.alerts.breadcrumbTitle": "告警",
"xpack.triggersActionsUI.appName": "告警和操作",
"xpack.triggersActionsUI.case.configureCases.mappingFieldSummary": "摘要",

View file

@ -88,4 +88,33 @@ describe('AddMessageVariables', () => {
useWithTripleBracesInTemplates: true,
});
});
test('it renders deprecated variables as disabled', () => {
const wrapper = mountWithIntl(
<AddMessageVariables
messageVariables={[
{
name: 'myVar',
description: 'My variable description',
},
{
name: 'deprecatedVar',
description: 'This variable is deprecated',
deprecated: true,
},
]}
paramsProperty="foo"
onSelectEventHandler={jest.fn()}
/>
);
wrapper.find('[data-test-subj="fooAddVariableButton"]').first().simulate('click');
expect(
wrapper.find('button[data-test-subj="variableMenuButton-myVar"]').getDOMNode()
).not.toBeDisabled();
expect(
wrapper.find('button[data-test-subj="variableMenuButton-deprecatedVar"]').getDOMNode()
).toBeDisabled();
});
});

View file

@ -15,8 +15,8 @@ import {
EuiText,
} from '@elastic/eui';
import './add_message_variables.scss';
import { ActionVariable } from '../../types';
import { templateActionVariable } from '../lib';
import { ActionVariable } from '../../../../alerting/common';
interface Props {
messageVariables?: ActionVariable[];
@ -37,6 +37,7 @@ export const AddMessageVariables: React.FunctionComponent<Props> = ({
key={variable.name}
data-test-subj={`variableMenuButton-${variable.name}`}
icon="empty"
disabled={variable.deprecated}
onClick={() => {
onSelectEventHandler(variable);
setIsVariablesPopoverOpen(false);

View file

@ -6,7 +6,7 @@
*/
import { fromNullable, Option } from 'fp-ts/lib/Option';
import { ActionVariable } from '../../../types';
import { ActionVariable } from '../../../../../alerting/common';
export function extractActionVariable(
actionVariables: ActionVariable[],

View file

@ -15,7 +15,7 @@ import './add_message_variables.scss';
import { XJson } from '../../../../../../src/plugins/es_ui_shared/public';
import { AddMessageVariables } from './add_message_variables';
import { ActionVariable } from '../../types';
import { ActionVariable } from '../../../../alerting/common';
import { templateActionVariable } from '../lib';
interface Props {

View file

@ -9,7 +9,7 @@ import React, { useState } from 'react';
import { EuiTextArea, EuiFormRow } from '@elastic/eui';
import './add_message_variables.scss';
import { AddMessageVariables } from './add_message_variables';
import { ActionVariable } from '../../types';
import { ActionVariable } from '../../../../alerting/common';
import { templateActionVariable } from '../lib';
interface Props {

View file

@ -9,7 +9,7 @@ import React, { useState } from 'react';
import { EuiFieldText } from '@elastic/eui';
import './add_message_variables.scss';
import { AddMessageVariables } from './add_message_variables';
import { ActionVariable } from '../../types';
import { ActionVariable } from '../../../../alerting/common';
import { templateActionVariable } from '../lib';
interface Props {

View file

@ -17,45 +17,85 @@ describe('transformActionVariables', () => {
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
"name": "alertId",
"description": "The ID of the rule.",
"name": "rule.id",
},
Object {
"description": "The name of the alert.",
"name": "alertName",
"description": "The name of the rule.",
"name": "rule.name",
},
Object {
"description": "The spaceId of the alert.",
"name": "spaceId",
"description": "The space ID of the rule.",
"name": "rule.spaceId",
},
Object {
"description": "The tags of the alert.",
"name": "tags",
"description": "The tags of the rule.",
"name": "rule.tags",
},
Object {
"description": "The date the alert scheduled the action.",
"description": "The date the rule scheduled the action.",
"name": "date",
},
Object {
"description": "The alert instance id that scheduled actions for the alert.",
"name": "alertInstanceId",
"description": "The ID of the alert that scheduled actions for the rule.",
"name": "alert.id",
},
Object {
"description": "The alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroup",
"description": "The action group of the alert that scheduled actions for the rule.",
"name": "alert.actionGroup",
},
Object {
"description": "The alert action subgroup that was used to scheduled actions for the alert.",
"name": "alertActionSubgroup",
"description": "The action subgroup of the alert that scheduled actions for the rule.",
"name": "alert.actionSubgroup",
},
Object {
"description": "The human readable name of the alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroupName",
"description": "The human readable name of the action group of the alert that scheduled actions for the rule.",
"name": "alert.actionGroupName",
},
Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.id.",
"name": "alertId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.name.",
"name": "alertName",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.id.",
"name": "alertInstanceId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionGroup.",
"name": "alertActionGroup",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionGroupName.",
"name": "alertActionGroupName",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionSubgroup.",
"name": "alertActionSubgroup",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.spaceId.",
"name": "spaceId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.tags.",
"name": "tags",
},
]
`);
});
@ -70,57 +110,97 @@ describe('transformActionVariables', () => {
params: [],
});
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
"name": "alertId",
},
Object {
"description": "The name of the alert.",
"name": "alertName",
},
Object {
"description": "The spaceId of the alert.",
"name": "spaceId",
},
Object {
"description": "The tags of the alert.",
"name": "tags",
},
Object {
"description": "The date the alert scheduled the action.",
"name": "date",
},
Object {
"description": "The alert instance id that scheduled actions for the alert.",
"name": "alertInstanceId",
},
Object {
"description": "The alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroup",
},
Object {
"description": "The alert action subgroup that was used to scheduled actions for the alert.",
"name": "alertActionSubgroup",
},
Object {
"description": "The human readable name of the alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroupName",
},
Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl",
},
Object {
"description": "foo-description",
"name": "context.foo",
},
Object {
"description": "bar-description",
"name": "context.bar",
},
]
`);
Array [
Object {
"description": "The ID of the rule.",
"name": "rule.id",
},
Object {
"description": "The name of the rule.",
"name": "rule.name",
},
Object {
"description": "The space ID of the rule.",
"name": "rule.spaceId",
},
Object {
"description": "The tags of the rule.",
"name": "rule.tags",
},
Object {
"description": "The date the rule scheduled the action.",
"name": "date",
},
Object {
"description": "The ID of the alert that scheduled actions for the rule.",
"name": "alert.id",
},
Object {
"description": "The action group of the alert that scheduled actions for the rule.",
"name": "alert.actionGroup",
},
Object {
"description": "The action subgroup of the alert that scheduled actions for the rule.",
"name": "alert.actionSubgroup",
},
Object {
"description": "The human readable name of the action group of the alert that scheduled actions for the rule.",
"name": "alert.actionGroupName",
},
Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.id.",
"name": "alertId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.name.",
"name": "alertName",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.id.",
"name": "alertInstanceId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionGroup.",
"name": "alertActionGroup",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionGroupName.",
"name": "alertActionGroupName",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionSubgroup.",
"name": "alertActionSubgroup",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.spaceId.",
"name": "spaceId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.tags.",
"name": "tags",
},
Object {
"description": "foo-description",
"name": "context.foo",
},
Object {
"description": "bar-description",
"name": "context.bar",
},
]
`);
});
test('should return correct variables when no context provided', async () => {
@ -133,57 +213,97 @@ describe('transformActionVariables', () => {
params: [],
});
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
"name": "alertId",
},
Object {
"description": "The name of the alert.",
"name": "alertName",
},
Object {
"description": "The spaceId of the alert.",
"name": "spaceId",
},
Object {
"description": "The tags of the alert.",
"name": "tags",
},
Object {
"description": "The date the alert scheduled the action.",
"name": "date",
},
Object {
"description": "The alert instance id that scheduled actions for the alert.",
"name": "alertInstanceId",
},
Object {
"description": "The alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroup",
},
Object {
"description": "The alert action subgroup that was used to scheduled actions for the alert.",
"name": "alertActionSubgroup",
},
Object {
"description": "The human readable name of the alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroupName",
},
Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl",
},
Object {
"description": "foo-description",
"name": "state.foo",
},
Object {
"description": "bar-description",
"name": "state.bar",
},
]
`);
Array [
Object {
"description": "The ID of the rule.",
"name": "rule.id",
},
Object {
"description": "The name of the rule.",
"name": "rule.name",
},
Object {
"description": "The space ID of the rule.",
"name": "rule.spaceId",
},
Object {
"description": "The tags of the rule.",
"name": "rule.tags",
},
Object {
"description": "The date the rule scheduled the action.",
"name": "date",
},
Object {
"description": "The ID of the alert that scheduled actions for the rule.",
"name": "alert.id",
},
Object {
"description": "The action group of the alert that scheduled actions for the rule.",
"name": "alert.actionGroup",
},
Object {
"description": "The action subgroup of the alert that scheduled actions for the rule.",
"name": "alert.actionSubgroup",
},
Object {
"description": "The human readable name of the action group of the alert that scheduled actions for the rule.",
"name": "alert.actionGroupName",
},
Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.id.",
"name": "alertId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.name.",
"name": "alertName",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.id.",
"name": "alertInstanceId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionGroup.",
"name": "alertActionGroup",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionGroupName.",
"name": "alertActionGroupName",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionSubgroup.",
"name": "alertActionSubgroup",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.spaceId.",
"name": "spaceId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.tags.",
"name": "tags",
},
Object {
"description": "foo-description",
"name": "state.foo",
},
Object {
"description": "bar-description",
"name": "state.bar",
},
]
`);
});
test('should return correct variables when both context and state provided', async () => {
@ -199,69 +319,109 @@ describe('transformActionVariables', () => {
params: [{ name: 'fooP', description: 'fooP-description' }],
});
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
"name": "alertId",
},
Object {
"description": "The name of the alert.",
"name": "alertName",
},
Object {
"description": "The spaceId of the alert.",
"name": "spaceId",
},
Object {
"description": "The tags of the alert.",
"name": "tags",
},
Object {
"description": "The date the alert scheduled the action.",
"name": "date",
},
Object {
"description": "The alert instance id that scheduled actions for the alert.",
"name": "alertInstanceId",
},
Object {
"description": "The alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroup",
},
Object {
"description": "The alert action subgroup that was used to scheduled actions for the alert.",
"name": "alertActionSubgroup",
},
Object {
"description": "The human readable name of the alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroupName",
},
Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl",
},
Object {
"description": "fooC-description",
"name": "context.fooC",
},
Object {
"description": "barC-description",
"name": "context.barC",
},
Object {
"description": "fooP-description",
"name": "params.fooP",
},
Object {
"description": "fooS-description",
"name": "state.fooS",
},
Object {
"description": "barS-description",
"name": "state.barS",
},
]
`);
Array [
Object {
"description": "The ID of the rule.",
"name": "rule.id",
},
Object {
"description": "The name of the rule.",
"name": "rule.name",
},
Object {
"description": "The space ID of the rule.",
"name": "rule.spaceId",
},
Object {
"description": "The tags of the rule.",
"name": "rule.tags",
},
Object {
"description": "The date the rule scheduled the action.",
"name": "date",
},
Object {
"description": "The ID of the alert that scheduled actions for the rule.",
"name": "alert.id",
},
Object {
"description": "The action group of the alert that scheduled actions for the rule.",
"name": "alert.actionGroup",
},
Object {
"description": "The action subgroup of the alert that scheduled actions for the rule.",
"name": "alert.actionSubgroup",
},
Object {
"description": "The human readable name of the action group of the alert that scheduled actions for the rule.",
"name": "alert.actionGroupName",
},
Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.id.",
"name": "alertId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.name.",
"name": "alertName",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.id.",
"name": "alertInstanceId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionGroup.",
"name": "alertActionGroup",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionGroupName.",
"name": "alertActionGroupName",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionSubgroup.",
"name": "alertActionSubgroup",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.spaceId.",
"name": "spaceId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.tags.",
"name": "tags",
},
Object {
"description": "fooC-description",
"name": "context.fooC",
},
Object {
"description": "barC-description",
"name": "context.barC",
},
Object {
"description": "fooP-description",
"name": "params.fooP",
},
Object {
"description": "fooS-description",
"name": "state.fooS",
},
Object {
"description": "barS-description",
"name": "state.barS",
},
]
`);
});
test('should return useWithTripleBracesInTemplates with action variables if specified', () => {
@ -283,72 +443,112 @@ describe('transformActionVariables', () => {
],
});
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [
Object {
"description": "The id of the alert.",
"name": "alertId",
},
Object {
"description": "The name of the alert.",
"name": "alertName",
},
Object {
"description": "The spaceId of the alert.",
"name": "spaceId",
},
Object {
"description": "The tags of the alert.",
"name": "tags",
},
Object {
"description": "The date the alert scheduled the action.",
"name": "date",
},
Object {
"description": "The alert instance id that scheduled actions for the alert.",
"name": "alertInstanceId",
},
Object {
"description": "The alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroup",
},
Object {
"description": "The alert action subgroup that was used to scheduled actions for the alert.",
"name": "alertActionSubgroup",
},
Object {
"description": "The human readable name of the alert action group that was used to scheduled actions for the alert.",
"name": "alertActionGroupName",
},
Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl",
},
Object {
"description": "fooC-description",
"name": "context.fooC",
"useWithTripleBracesInTemplates": true,
},
Object {
"description": "barC-description",
"name": "context.barC",
},
Object {
"description": "fooP-description",
"name": "params.fooP",
"useWithTripleBracesInTemplates": true,
},
Object {
"description": "fooS-description",
"name": "state.fooS",
},
Object {
"description": "barS-description",
"name": "state.barS",
"useWithTripleBracesInTemplates": true,
},
]
`);
Array [
Object {
"description": "The ID of the rule.",
"name": "rule.id",
},
Object {
"description": "The name of the rule.",
"name": "rule.name",
},
Object {
"description": "The space ID of the rule.",
"name": "rule.spaceId",
},
Object {
"description": "The tags of the rule.",
"name": "rule.tags",
},
Object {
"description": "The date the rule scheduled the action.",
"name": "date",
},
Object {
"description": "The ID of the alert that scheduled actions for the rule.",
"name": "alert.id",
},
Object {
"description": "The action group of the alert that scheduled actions for the rule.",
"name": "alert.actionGroup",
},
Object {
"description": "The action subgroup of the alert that scheduled actions for the rule.",
"name": "alert.actionSubgroup",
},
Object {
"description": "The human readable name of the action group of the alert that scheduled actions for the rule.",
"name": "alert.actionGroupName",
},
Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.id.",
"name": "alertId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.name.",
"name": "alertName",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.id.",
"name": "alertInstanceId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionGroup.",
"name": "alertActionGroup",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionGroupName.",
"name": "alertActionGroupName",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of alert.actionSubgroup.",
"name": "alertActionSubgroup",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.spaceId.",
"name": "spaceId",
},
Object {
"deprecated": true,
"description": "This has been deprecated in favor of rule.tags.",
"name": "tags",
},
Object {
"description": "fooC-description",
"name": "context.fooC",
"useWithTripleBracesInTemplates": true,
},
Object {
"description": "barC-description",
"name": "context.barC",
},
Object {
"description": "fooP-description",
"name": "params.fooP",
"useWithTripleBracesInTemplates": true,
},
Object {
"description": "fooS-description",
"name": "state.fooS",
},
Object {
"description": "barS-description",
"name": "state.barS",
"useWithTripleBracesInTemplates": true,
},
]
`);
});
});

View file

@ -6,7 +6,8 @@
*/
import { i18n } from '@kbn/i18n';
import { ActionVariable, ActionVariables } from '../../types';
import { ActionVariables } from '../../types';
import { ActionVariable } from '../../../../alerting/common';
// return a "flattened" list of action variables for an alertType
export function transformActionVariables(actionVariables: ActionVariables): ActionVariable[] {
@ -21,11 +22,26 @@ export function transformActionVariables(actionVariables: ActionVariables): Acti
}
export enum AlertProvidedActionVariables {
ruleId = 'rule.id',
ruleName = 'rule.name',
ruleSpaceId = 'rule.spaceId',
ruleTags = 'rule.tags',
date = 'date',
alertId = 'alert.id',
alertActionGroup = 'alert.actionGroup',
alertActionGroupName = 'alert.actionGroupName',
alertActionSubgroup = 'alert.actionSubgroup',
}
export enum LegacyAlertProvidedActionVariables {
alertId = 'alertId',
alertName = 'alertName',
spaceId = 'spaceId',
tags = 'tags',
alertInstanceId = 'alertInstanceId',
alertActionGroup = 'alertActionGroup',
alertActionGroupName = 'alertActionGroupName',
alertActionSubgroup = 'alertActionSubgroup',
tags = 'tags',
spaceId = 'spaceId',
}
function prefixKeys(actionVariables: ActionVariable[], prefix: string): ActionVariable[] {
@ -39,73 +55,72 @@ function prefixKeys(actionVariables: ActionVariable[], prefix: string): ActionVa
function getAlwaysProvidedActionVariables(): ActionVariable[] {
const result: ActionVariable[] = [];
result.push({
name: AlertProvidedActionVariables.ruleId,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.ruleIdLabel', {
defaultMessage: 'The ID of the rule.',
}),
});
result.push({
name: AlertProvidedActionVariables.ruleName,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.ruleNameLabel', {
defaultMessage: 'The name of the rule.',
}),
});
result.push({
name: AlertProvidedActionVariables.ruleSpaceId,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.ruleSpaceIdLabel', {
defaultMessage: 'The space ID of the rule.',
}),
});
result.push({
name: AlertProvidedActionVariables.ruleTags,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.ruleTagsLabel', {
defaultMessage: 'The tags of the rule.',
}),
});
result.push({
name: AlertProvidedActionVariables.date,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.dateLabel', {
defaultMessage: 'The date the rule scheduled the action.',
}),
});
result.push({
name: AlertProvidedActionVariables.alertId,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.alertIdLabel', {
defaultMessage: 'The id of the alert.',
defaultMessage: 'The ID of the alert that scheduled actions for the rule.',
}),
});
result.push({
name: AlertProvidedActionVariables.alertName,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.alertNameLabel', {
defaultMessage: 'The name of the alert.',
}),
});
result.push({
name: AlertProvidedActionVariables.spaceId,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.spaceIdLabel', {
defaultMessage: 'The spaceId of the alert.',
}),
});
result.push({
name: AlertProvidedActionVariables.tags,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.tagsLabel', {
defaultMessage: 'The tags of the alert.',
}),
});
result.push({
name: 'date',
description: i18n.translate('xpack.triggersActionsUI.actionVariables.dateLabel', {
defaultMessage: 'The date the alert scheduled the action.',
}),
});
result.push({
name: 'alertInstanceId',
description: i18n.translate('xpack.triggersActionsUI.actionVariables.alertInstanceIdLabel', {
defaultMessage: 'The alert instance id that scheduled actions for the alert.',
}),
});
result.push({
name: 'alertActionGroup',
name: AlertProvidedActionVariables.alertActionGroup,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.alertActionGroupLabel', {
defaultMessage: 'The alert action group that was used to scheduled actions for the alert.',
defaultMessage: 'The action group of the alert that scheduled actions for the rule.',
}),
});
result.push({
name: 'alertActionSubgroup',
name: AlertProvidedActionVariables.alertActionSubgroup,
description: i18n.translate(
'xpack.triggersActionsUI.actionVariables.alertActionSubgroupLabel',
{
defaultMessage:
'The alert action subgroup that was used to scheduled actions for the alert.',
defaultMessage: 'The action subgroup of the alert that scheduled actions for the rule.',
}
),
});
result.push({
name: 'alertActionGroupName',
name: AlertProvidedActionVariables.alertActionGroupName,
description: i18n.translate(
'xpack.triggersActionsUI.actionVariables.alertActionGroupNameLabel',
{
defaultMessage:
'The human readable name of the alert action group that was used to scheduled actions for the alert.',
'The human readable name of the action group of the alert that scheduled actions for the rule.',
}
),
});
@ -118,5 +133,105 @@ function getAlwaysProvidedActionVariables(): ActionVariable[] {
}),
});
result.push({
name: LegacyAlertProvidedActionVariables.alertId,
deprecated: true,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.legacyAlertIdLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.ruleId,
},
}),
});
result.push({
name: LegacyAlertProvidedActionVariables.alertName,
deprecated: true,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.legacyAlertNameLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.ruleName,
},
}),
});
result.push({
name: LegacyAlertProvidedActionVariables.alertInstanceId,
deprecated: true,
description: i18n.translate(
'xpack.triggersActionsUI.actionVariables.legacyAlertInstanceIdLabel',
{
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.alertId,
},
}
),
});
result.push({
name: LegacyAlertProvidedActionVariables.alertActionGroup,
deprecated: true,
description: i18n.translate(
'xpack.triggersActionsUI.actionVariables.legacyAlertActionGroupLabel',
{
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.alertActionGroup,
},
}
),
});
result.push({
name: LegacyAlertProvidedActionVariables.alertActionGroupName,
deprecated: true,
description: i18n.translate(
'xpack.triggersActionsUI.actionVariables.legacyAlertActionGroupNameLabel',
{
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.alertActionGroupName,
},
}
),
});
result.push({
name: LegacyAlertProvidedActionVariables.alertActionSubgroup,
deprecated: true,
description: i18n.translate(
'xpack.triggersActionsUI.actionVariables.legacyAlertActionSubGroupLabel',
{
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.alertActionSubgroup,
},
}
),
});
result.push({
name: LegacyAlertProvidedActionVariables.spaceId,
deprecated: true,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.legacySpaceIdLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.ruleSpaceId,
},
}),
});
result.push({
name: LegacyAlertProvidedActionVariables.tags,
deprecated: true,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.legacyTagsLabel', {
defaultMessage: 'This has been deprecated in favor of {variable}.',
values: {
variable: AlertProvidedActionVariables.ruleTags,
},
}),
});
return result;
}

View file

@ -12,14 +12,14 @@ import { getDefaultsForActionParams } from './get_defaults_for_action_params';
describe('getDefaultsForActionParams', () => {
test('pagerduty defaults', async () => {
expect(getDefaultsForActionParams('.pagerduty', 'test', false)).toEqual({
dedupKey: `{{${AlertProvidedActionVariables.alertId}}}:{{${AlertProvidedActionVariables.alertInstanceId}}}`,
dedupKey: `{{${AlertProvidedActionVariables.ruleId}}}:{{${AlertProvidedActionVariables.alertId}}}`,
eventAction: 'trigger',
});
});
test('pagerduty defaults for recovered action group', async () => {
expect(getDefaultsForActionParams('.pagerduty', RecoveredActionGroup.id, true)).toEqual({
dedupKey: `{{${AlertProvidedActionVariables.alertId}}}:{{${AlertProvidedActionVariables.alertInstanceId}}}`,
dedupKey: `{{${AlertProvidedActionVariables.ruleId}}}:{{${AlertProvidedActionVariables.alertId}}}`,
eventAction: 'resolve',
});
});

View file

@ -22,7 +22,7 @@ export const getDefaultsForActionParams = (
switch (actionTypeId) {
case '.pagerduty':
const pagerDutyDefaults = {
dedupKey: `{{${AlertProvidedActionVariables.alertId}}}:{{${AlertProvidedActionVariables.alertInstanceId}}}`,
dedupKey: `{{${AlertProvidedActionVariables.ruleId}}}:{{${AlertProvidedActionVariables.alertId}}}`,
eventAction: EventActionOptions.TRIGGER,
};
if (isRecoveryActionGroup) {

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { ActionVariable } from '../../types';
import { ActionVariable } from '../../../../alerting/common';
export function templateActionVariable(variable: ActionVariable) {
return variable.useWithTripleBracesInTemplates

View file

@ -26,15 +26,14 @@ import {
EuiBadge,
EuiErrorBoundary,
} from '@elastic/eui';
import { pick } from 'lodash';
import { AlertActionParam } from '../../../../../alerting/common';
import { partition, pick } from 'lodash';
import { ActionVariable, AlertActionParam } from '../../../../../alerting/common';
import {
IErrorObject,
AlertAction,
ActionTypeIndex,
ActionConnector,
ActionVariables,
ActionVariable,
ActionTypeRegistryContract,
REQUIRED_ACTION_VARIABLES,
} from '../../../types';
@ -382,9 +381,21 @@ function getAvailableActionVariables(
actionVariables: ActionVariables,
actionGroup?: ActionGroupWithMessageVariables
) {
return transformActionVariables(
const transformedActionVariables: ActionVariable[] = transformActionVariables(
actionGroup?.omitOptionalMessageVariables
? pick(actionVariables, ...REQUIRED_ACTION_VARIABLES)
: actionVariables
).sort((a, b) => a.name.toUpperCase().localeCompare(b.name.toUpperCase()));
);
// partition deprecated items so they show up last
const partitionedActionVariables = partition(
transformedActionVariables,
(v) => v.deprecated !== true
);
return partitionedActionVariables.reduce((acc, curr) => {
return [
...acc,
...curr.sort((a, b) => a.name.toUpperCase().localeCompare(b.name.toUpperCase())),
];
}, []);
}

View file

@ -24,7 +24,6 @@ export type {
AlertTypeRegistryContract,
AlertTypeParamsExpressionProps,
ValidationResult,
ActionVariable,
ActionVariables,
ActionConnector,
IErrorObject,

View file

@ -12,7 +12,6 @@ import { ChartsPluginSetup } from 'src/plugins/charts/public';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { ActionType } from '../../actions/common';
import { TypeRegistry } from './application/type_registry';
import { AlertType as CommonAlertType } from '../../alerting/common';
import {
ActionGroup,
AlertActionParam,
@ -26,6 +25,8 @@ import {
AlertingFrameworkHealth,
AlertNotifyWhenType,
AlertTypeParams,
ActionVariable,
AlertType as CommonAlertType,
} from '../../alerting/common';
// In Triggers and Actions we treat all `Alert`s as `SanitizedAlert<AlertTypeParams>`
@ -157,12 +158,6 @@ export type ActionConnectorTableItem = ActionConnector & {
actionType: ActionType['name'];
};
export interface ActionVariable {
name: string;
description: string;
useWithTripleBracesInTemplates?: boolean;
}
type AsActionVariables<Keys extends string> = {
[Req in Keys]: ActionVariable[];
};

View file

@ -265,6 +265,59 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon
);
expect(body).to.be('kibanaBaseUrl: ""');
});
it('should render action variables in rule action', async () => {
const url = formatUrl(new URL(webhookSimulatorURL), { auth: false });
const actionResponse = await supertest
.post(`${getUrlPrefix(Spaces.space1.id)}/api/actions/action`)
.set('kbn-xsrf', 'test')
.send({
name: 'testing action variable rendering',
actionTypeId: '.webhook',
secrets: {},
config: {
headers: {
'Content-Type': 'text/plain',
},
url,
},
});
expect(actionResponse.status).to.eql(200);
const createdAction = actionResponse.body;
objectRemover.add(Spaces.space1.id, createdAction.id, 'action', 'actions');
const alertResponse = await supertest
.post(`${getUrlPrefix(Spaces.space1.id)}/api/alerts/alert`)
.set('kbn-xsrf', 'foo')
.send(
getTestAlertData({
name: 'testing variable escapes for webhook',
alertTypeId: 'test.patternFiring',
params: {
pattern: { instance: [true] },
},
actions: [
{
id: createdAction.id,
group: 'default',
params: {
body: `payload {{rule.id}} - old id variable: {{alertId}}, new id variable: {{rule.id}}, old name variable: {{alertName}}, new name variable: {{rule.name}}`,
},
},
],
})
);
expect(alertResponse.status).to.eql(200);
const createdAlert = alertResponse.body;
objectRemover.add(Spaces.space1.id, createdAlert.id, 'alert', 'alerts');
const body = await retry.try(async () =>
waitForActionBody(webhookSimulatorURL, createdAlert.id)
);
expect(body).to.be(
`old id variable: ${createdAlert.id}, new id variable: ${createdAlert.id}, old name variable: ${createdAlert.name}, new name variable: ${createdAlert.name}`
);
});
});
async function waitForActionBody(url: string, id: string): Promise<string> {

View file

@ -129,17 +129,17 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
);
await testSubjects.setValue('messageTextArea', 'test message ');
await testSubjects.click('messageAddVariableButton');
await testSubjects.click('variableMenuButton-alertActionGroup');
await testSubjects.click('variableMenuButton-alert.actionGroup');
expect(await messageTextArea.getAttribute('value')).to.eql(
'test message {{alertActionGroup}}'
'test message {{alert.actionGroup}}'
);
await messageTextArea.type(' some additional text ');
await testSubjects.click('messageAddVariableButton');
await testSubjects.click('variableMenuButton-alertId');
await testSubjects.click('variableMenuButton-rule.id');
expect(await messageTextArea.getAttribute('value')).to.eql(
'test message {{alertActionGroup}} some additional text {{alertId}}'
'test message {{alert.actionGroup}} some additional text {{rule.id}}'
);
await testSubjects.click('saveAlertButton');