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

View file

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

View file

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

View file

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

View file

@ -22207,16 +22207,7 @@
"xpack.transform.transformsWizard.transformDocsLinkText": "変換ドキュメント", "xpack.transform.transformsWizard.transformDocsLinkText": "変換ドキュメント",
"xpack.transform.wizard.nextStepButton": "次へ", "xpack.transform.wizard.nextStepButton": "次へ",
"xpack.transform.wizard.previousStepButton": "前へ", "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.dateLabel": "アラートがアクションをスケジュールした日付。",
"xpack.triggersActionsUI.actionVariables.kibanaBaseUrlLabel": "構成したserver.publicBaseUrl値。構成していない場合は、空の文字列。",
"xpack.triggersActionsUI.actionVariables.spaceIdLabel": "アラートのスペース ID。",
"xpack.triggersActionsUI.actionVariables.tagsLabel": "アラートのタグ。",
"xpack.triggersActionsUI.alerts.breadcrumbTitle": "アラート", "xpack.triggersActionsUI.alerts.breadcrumbTitle": "アラート",
"xpack.triggersActionsUI.appName": "アラートとアクション", "xpack.triggersActionsUI.appName": "アラートとアクション",
"xpack.triggersActionsUI.case.configureCases.mappingFieldSummary": "まとめ", "xpack.triggersActionsUI.case.configureCases.mappingFieldSummary": "まとめ",

View file

@ -22559,16 +22559,7 @@
"xpack.transform.transformsWizard.transformDocsLinkText": "转换文档", "xpack.transform.transformsWizard.transformDocsLinkText": "转换文档",
"xpack.transform.wizard.nextStepButton": "下一步", "xpack.transform.wizard.nextStepButton": "下一步",
"xpack.transform.wizard.previousStepButton": "上一步", "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.dateLabel": "告警计划操作的日期。",
"xpack.triggersActionsUI.actionVariables.kibanaBaseUrlLabel": "配置的 server.publicBaseUrl 值,如果未配置,则为空字符串。",
"xpack.triggersActionsUI.actionVariables.spaceIdLabel": "告警的 spaceId。",
"xpack.triggersActionsUI.actionVariables.tagsLabel": "告警的标签。",
"xpack.triggersActionsUI.alerts.breadcrumbTitle": "告警", "xpack.triggersActionsUI.alerts.breadcrumbTitle": "告警",
"xpack.triggersActionsUI.appName": "告警和操作", "xpack.triggersActionsUI.appName": "告警和操作",
"xpack.triggersActionsUI.case.configureCases.mappingFieldSummary": "摘要", "xpack.triggersActionsUI.case.configureCases.mappingFieldSummary": "摘要",

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -17,45 +17,85 @@ describe('transformActionVariables', () => {
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(` expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [ Array [
Object { Object {
"description": "The id of the alert.", "description": "The ID of the rule.",
"name": "alertId", "name": "rule.id",
}, },
Object { Object {
"description": "The name of the alert.", "description": "The name of the rule.",
"name": "alertName", "name": "rule.name",
}, },
Object { Object {
"description": "The spaceId of the alert.", "description": "The space ID of the rule.",
"name": "spaceId", "name": "rule.spaceId",
}, },
Object { Object {
"description": "The tags of the alert.", "description": "The tags of the rule.",
"name": "tags", "name": "rule.tags",
}, },
Object { Object {
"description": "The date the alert scheduled the action.", "description": "The date the rule scheduled the action.",
"name": "date", "name": "date",
}, },
Object { Object {
"description": "The alert instance id that scheduled actions for the alert.", "description": "The ID of the alert that scheduled actions for the rule.",
"name": "alertInstanceId", "name": "alert.id",
}, },
Object { Object {
"description": "The alert action group that was used to scheduled actions for the alert.", "description": "The action group of the alert that scheduled actions for the rule.",
"name": "alertActionGroup", "name": "alert.actionGroup",
}, },
Object { Object {
"description": "The alert action subgroup that was used to scheduled actions for the alert.", "description": "The action subgroup of the alert that scheduled actions for the rule.",
"name": "alertActionSubgroup", "name": "alert.actionSubgroup",
}, },
Object { Object {
"description": "The human readable name of the alert action group that was used to scheduled actions for the alert.", "description": "The human readable name of the action group of the alert that scheduled actions for the rule.",
"name": "alertActionGroupName", "name": "alert.actionGroupName",
}, },
Object { Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.", "description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl", "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: [], params: [],
}); });
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(` expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [ Array [
Object { Object {
"description": "The id of the alert.", "description": "The ID of the rule.",
"name": "alertId", "name": "rule.id",
}, },
Object { Object {
"description": "The name of the alert.", "description": "The name of the rule.",
"name": "alertName", "name": "rule.name",
}, },
Object { Object {
"description": "The spaceId of the alert.", "description": "The space ID of the rule.",
"name": "spaceId", "name": "rule.spaceId",
}, },
Object { Object {
"description": "The tags of the alert.", "description": "The tags of the rule.",
"name": "tags", "name": "rule.tags",
}, },
Object { Object {
"description": "The date the alert scheduled the action.", "description": "The date the rule scheduled the action.",
"name": "date", "name": "date",
}, },
Object { Object {
"description": "The alert instance id that scheduled actions for the alert.", "description": "The ID of the alert that scheduled actions for the rule.",
"name": "alertInstanceId", "name": "alert.id",
}, },
Object { Object {
"description": "The alert action group that was used to scheduled actions for the alert.", "description": "The action group of the alert that scheduled actions for the rule.",
"name": "alertActionGroup", "name": "alert.actionGroup",
}, },
Object { Object {
"description": "The alert action subgroup that was used to scheduled actions for the alert.", "description": "The action subgroup of the alert that scheduled actions for the rule.",
"name": "alertActionSubgroup", "name": "alert.actionSubgroup",
}, },
Object { Object {
"description": "The human readable name of the alert action group that was used to scheduled actions for the alert.", "description": "The human readable name of the action group of the alert that scheduled actions for the rule.",
"name": "alertActionGroupName", "name": "alert.actionGroupName",
}, },
Object { Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.", "description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl", "name": "kibanaBaseUrl",
}, },
Object { Object {
"description": "foo-description", "deprecated": true,
"name": "context.foo", "description": "This has been deprecated in favor of rule.id.",
}, "name": "alertId",
Object { },
"description": "bar-description", Object {
"name": "context.bar", "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 () => { test('should return correct variables when no context provided', async () => {
@ -133,57 +213,97 @@ describe('transformActionVariables', () => {
params: [], params: [],
}); });
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(` expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [ Array [
Object { Object {
"description": "The id of the alert.", "description": "The ID of the rule.",
"name": "alertId", "name": "rule.id",
}, },
Object { Object {
"description": "The name of the alert.", "description": "The name of the rule.",
"name": "alertName", "name": "rule.name",
}, },
Object { Object {
"description": "The spaceId of the alert.", "description": "The space ID of the rule.",
"name": "spaceId", "name": "rule.spaceId",
}, },
Object { Object {
"description": "The tags of the alert.", "description": "The tags of the rule.",
"name": "tags", "name": "rule.tags",
}, },
Object { Object {
"description": "The date the alert scheduled the action.", "description": "The date the rule scheduled the action.",
"name": "date", "name": "date",
}, },
Object { Object {
"description": "The alert instance id that scheduled actions for the alert.", "description": "The ID of the alert that scheduled actions for the rule.",
"name": "alertInstanceId", "name": "alert.id",
}, },
Object { Object {
"description": "The alert action group that was used to scheduled actions for the alert.", "description": "The action group of the alert that scheduled actions for the rule.",
"name": "alertActionGroup", "name": "alert.actionGroup",
}, },
Object { Object {
"description": "The alert action subgroup that was used to scheduled actions for the alert.", "description": "The action subgroup of the alert that scheduled actions for the rule.",
"name": "alertActionSubgroup", "name": "alert.actionSubgroup",
}, },
Object { Object {
"description": "The human readable name of the alert action group that was used to scheduled actions for the alert.", "description": "The human readable name of the action group of the alert that scheduled actions for the rule.",
"name": "alertActionGroupName", "name": "alert.actionGroupName",
}, },
Object { Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.", "description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl", "name": "kibanaBaseUrl",
}, },
Object { Object {
"description": "foo-description", "deprecated": true,
"name": "state.foo", "description": "This has been deprecated in favor of rule.id.",
}, "name": "alertId",
Object { },
"description": "bar-description", Object {
"name": "state.bar", "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 () => { test('should return correct variables when both context and state provided', async () => {
@ -199,69 +319,109 @@ describe('transformActionVariables', () => {
params: [{ name: 'fooP', description: 'fooP-description' }], params: [{ name: 'fooP', description: 'fooP-description' }],
}); });
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(` expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [ Array [
Object { Object {
"description": "The id of the alert.", "description": "The ID of the rule.",
"name": "alertId", "name": "rule.id",
}, },
Object { Object {
"description": "The name of the alert.", "description": "The name of the rule.",
"name": "alertName", "name": "rule.name",
}, },
Object { Object {
"description": "The spaceId of the alert.", "description": "The space ID of the rule.",
"name": "spaceId", "name": "rule.spaceId",
}, },
Object { Object {
"description": "The tags of the alert.", "description": "The tags of the rule.",
"name": "tags", "name": "rule.tags",
}, },
Object { Object {
"description": "The date the alert scheduled the action.", "description": "The date the rule scheduled the action.",
"name": "date", "name": "date",
}, },
Object { Object {
"description": "The alert instance id that scheduled actions for the alert.", "description": "The ID of the alert that scheduled actions for the rule.",
"name": "alertInstanceId", "name": "alert.id",
}, },
Object { Object {
"description": "The alert action group that was used to scheduled actions for the alert.", "description": "The action group of the alert that scheduled actions for the rule.",
"name": "alertActionGroup", "name": "alert.actionGroup",
}, },
Object { Object {
"description": "The alert action subgroup that was used to scheduled actions for the alert.", "description": "The action subgroup of the alert that scheduled actions for the rule.",
"name": "alertActionSubgroup", "name": "alert.actionSubgroup",
}, },
Object { Object {
"description": "The human readable name of the alert action group that was used to scheduled actions for the alert.", "description": "The human readable name of the action group of the alert that scheduled actions for the rule.",
"name": "alertActionGroupName", "name": "alert.actionGroupName",
}, },
Object { Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.", "description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl", "name": "kibanaBaseUrl",
}, },
Object { Object {
"description": "fooC-description", "deprecated": true,
"name": "context.fooC", "description": "This has been deprecated in favor of rule.id.",
}, "name": "alertId",
Object { },
"description": "barC-description", Object {
"name": "context.barC", "deprecated": true,
}, "description": "This has been deprecated in favor of rule.name.",
Object { "name": "alertName",
"description": "fooP-description", },
"name": "params.fooP", Object {
}, "deprecated": true,
Object { "description": "This has been deprecated in favor of alert.id.",
"description": "fooS-description", "name": "alertInstanceId",
"name": "state.fooS", },
}, Object {
Object { "deprecated": true,
"description": "barS-description", "description": "This has been deprecated in favor of alert.actionGroup.",
"name": "state.barS", "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', () => { test('should return useWithTripleBracesInTemplates with action variables if specified', () => {
@ -283,72 +443,112 @@ describe('transformActionVariables', () => {
], ],
}); });
expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(` expect(transformActionVariables(alertType.actionVariables)).toMatchInlineSnapshot(`
Array [ Array [
Object { Object {
"description": "The id of the alert.", "description": "The ID of the rule.",
"name": "alertId", "name": "rule.id",
}, },
Object { Object {
"description": "The name of the alert.", "description": "The name of the rule.",
"name": "alertName", "name": "rule.name",
}, },
Object { Object {
"description": "The spaceId of the alert.", "description": "The space ID of the rule.",
"name": "spaceId", "name": "rule.spaceId",
}, },
Object { Object {
"description": "The tags of the alert.", "description": "The tags of the rule.",
"name": "tags", "name": "rule.tags",
}, },
Object { Object {
"description": "The date the alert scheduled the action.", "description": "The date the rule scheduled the action.",
"name": "date", "name": "date",
}, },
Object { Object {
"description": "The alert instance id that scheduled actions for the alert.", "description": "The ID of the alert that scheduled actions for the rule.",
"name": "alertInstanceId", "name": "alert.id",
}, },
Object { Object {
"description": "The alert action group that was used to scheduled actions for the alert.", "description": "The action group of the alert that scheduled actions for the rule.",
"name": "alertActionGroup", "name": "alert.actionGroup",
}, },
Object { Object {
"description": "The alert action subgroup that was used to scheduled actions for the alert.", "description": "The action subgroup of the alert that scheduled actions for the rule.",
"name": "alertActionSubgroup", "name": "alert.actionSubgroup",
}, },
Object { Object {
"description": "The human readable name of the alert action group that was used to scheduled actions for the alert.", "description": "The human readable name of the action group of the alert that scheduled actions for the rule.",
"name": "alertActionGroupName", "name": "alert.actionGroupName",
}, },
Object { Object {
"description": "The configured server.publicBaseUrl value or empty string if not configured.", "description": "The configured server.publicBaseUrl value or empty string if not configured.",
"name": "kibanaBaseUrl", "name": "kibanaBaseUrl",
}, },
Object { Object {
"description": "fooC-description", "deprecated": true,
"name": "context.fooC", "description": "This has been deprecated in favor of rule.id.",
"useWithTripleBracesInTemplates": true, "name": "alertId",
}, },
Object { Object {
"description": "barC-description", "deprecated": true,
"name": "context.barC", "description": "This has been deprecated in favor of rule.name.",
}, "name": "alertName",
Object { },
"description": "fooP-description", Object {
"name": "params.fooP", "deprecated": true,
"useWithTripleBracesInTemplates": true, "description": "This has been deprecated in favor of alert.id.",
}, "name": "alertInstanceId",
Object { },
"description": "fooS-description", Object {
"name": "state.fooS", "deprecated": true,
}, "description": "This has been deprecated in favor of alert.actionGroup.",
Object { "name": "alertActionGroup",
"description": "barS-description", },
"name": "state.barS", Object {
"useWithTripleBracesInTemplates": true, "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 { 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 // return a "flattened" list of action variables for an alertType
export function transformActionVariables(actionVariables: ActionVariables): ActionVariable[] { export function transformActionVariables(actionVariables: ActionVariables): ActionVariable[] {
@ -21,11 +22,26 @@ export function transformActionVariables(actionVariables: ActionVariables): Acti
} }
export enum AlertProvidedActionVariables { 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', alertId = 'alertId',
alertName = 'alertName', alertName = 'alertName',
spaceId = 'spaceId',
tags = 'tags',
alertInstanceId = 'alertInstanceId', alertInstanceId = 'alertInstanceId',
alertActionGroup = 'alertActionGroup',
alertActionGroupName = 'alertActionGroupName',
alertActionSubgroup = 'alertActionSubgroup',
tags = 'tags',
spaceId = 'spaceId',
} }
function prefixKeys(actionVariables: ActionVariable[], prefix: string): ActionVariable[] { function prefixKeys(actionVariables: ActionVariable[], prefix: string): ActionVariable[] {
@ -39,73 +55,72 @@ function prefixKeys(actionVariables: ActionVariable[], prefix: string): ActionVa
function getAlwaysProvidedActionVariables(): ActionVariable[] { function getAlwaysProvidedActionVariables(): ActionVariable[] {
const result: 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({ result.push({
name: AlertProvidedActionVariables.alertId, name: AlertProvidedActionVariables.alertId,
description: i18n.translate('xpack.triggersActionsUI.actionVariables.alertIdLabel', { 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({ result.push({
name: AlertProvidedActionVariables.alertName, name: AlertProvidedActionVariables.alertActionGroup,
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',
description: i18n.translate('xpack.triggersActionsUI.actionVariables.alertActionGroupLabel', { 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({ result.push({
name: 'alertActionSubgroup', name: AlertProvidedActionVariables.alertActionSubgroup,
description: i18n.translate( description: i18n.translate(
'xpack.triggersActionsUI.actionVariables.alertActionSubgroupLabel', 'xpack.triggersActionsUI.actionVariables.alertActionSubgroupLabel',
{ {
defaultMessage: defaultMessage: 'The action subgroup of the alert that scheduled actions for the rule.',
'The alert action subgroup that was used to scheduled actions for the alert.',
} }
), ),
}); });
result.push({ result.push({
name: 'alertActionGroupName', name: AlertProvidedActionVariables.alertActionGroupName,
description: i18n.translate( description: i18n.translate(
'xpack.triggersActionsUI.actionVariables.alertActionGroupNameLabel', 'xpack.triggersActionsUI.actionVariables.alertActionGroupNameLabel',
{ {
defaultMessage: 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; return result;
} }

View file

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

View file

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

View file

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

View file

@ -26,15 +26,14 @@ import {
EuiBadge, EuiBadge,
EuiErrorBoundary, EuiErrorBoundary,
} from '@elastic/eui'; } from '@elastic/eui';
import { pick } from 'lodash'; import { partition, pick } from 'lodash';
import { AlertActionParam } from '../../../../../alerting/common'; import { ActionVariable, AlertActionParam } from '../../../../../alerting/common';
import { import {
IErrorObject, IErrorObject,
AlertAction, AlertAction,
ActionTypeIndex, ActionTypeIndex,
ActionConnector, ActionConnector,
ActionVariables, ActionVariables,
ActionVariable,
ActionTypeRegistryContract, ActionTypeRegistryContract,
REQUIRED_ACTION_VARIABLES, REQUIRED_ACTION_VARIABLES,
} from '../../../types'; } from '../../../types';
@ -382,9 +381,21 @@ function getAvailableActionVariables(
actionVariables: ActionVariables, actionVariables: ActionVariables,
actionGroup?: ActionGroupWithMessageVariables actionGroup?: ActionGroupWithMessageVariables
) { ) {
return transformActionVariables( const transformedActionVariables: ActionVariable[] = transformActionVariables(
actionGroup?.omitOptionalMessageVariables actionGroup?.omitOptionalMessageVariables
? pick(actionVariables, ...REQUIRED_ACTION_VARIABLES) ? pick(actionVariables, ...REQUIRED_ACTION_VARIABLES)
: actionVariables : 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, AlertTypeRegistryContract,
AlertTypeParamsExpressionProps, AlertTypeParamsExpressionProps,
ValidationResult, ValidationResult,
ActionVariable,
ActionVariables, ActionVariables,
ActionConnector, ActionConnector,
IErrorObject, IErrorObject,

View file

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

View file

@ -265,6 +265,59 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon
); );
expect(body).to.be('kibanaBaseUrl: ""'); 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> { 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.setValue('messageTextArea', 'test message ');
await testSubjects.click('messageAddVariableButton'); await testSubjects.click('messageAddVariableButton');
await testSubjects.click('variableMenuButton-alertActionGroup'); await testSubjects.click('variableMenuButton-alert.actionGroup');
expect(await messageTextArea.getAttribute('value')).to.eql( expect(await messageTextArea.getAttribute('value')).to.eql(
'test message {{alertActionGroup}}' 'test message {{alert.actionGroup}}'
); );
await messageTextArea.type(' some additional text '); await messageTextArea.type(' some additional text ');
await testSubjects.click('messageAddVariableButton'); await testSubjects.click('messageAddVariableButton');
await testSubjects.click('variableMenuButton-alertId'); await testSubjects.click('variableMenuButton-rule.id');
expect(await messageTextArea.getAttribute('value')).to.eql( 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'); await testSubjects.click('saveAlertButton');