From 2c591085ff1d9b0bba2c69501d16b714db9949a8 Mon Sep 17 00:00:00 2001 From: Toby Brain Date: Tue, 21 Apr 2020 13:42:27 +1000 Subject: [PATCH] Add support for all event fields in the Pagerduty action plugin --- x-pack/plugins/actions/README.md | 21 +++-- .../builtin_action_types/pagerduty.test.ts | 88 ++++++++++++++++++- .../server/builtin_action_types/pagerduty.ts | 21 +++++ 3 files changed, 117 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/actions/README.md b/x-pack/plugins/actions/README.md index 82cc09f5e9eca..722c17781d926 100644 --- a/x-pack/plugins/actions/README.md +++ b/x-pack/plugins/actions/README.md @@ -446,15 +446,18 @@ The PagerDuty action uses the [V2 Events API](https://v2.developer.pagerduty.com | Property | Description | Type | | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | -| eventAction | One of `trigger` _(default)_, `resolve`, or `acknowlege`. See [event action](https://v2.developer.pagerduty.com/docs/events-api-v2#event-action) for more details. | string _(optional)_ | -| dedupKey | All actions sharing this key will be associated with the same PagerDuty alert. Used to correlate trigger and resolution. Defaults to `action:`. The maximum length is **255** characters. See [alert deduplication](https://v2.developer.pagerduty.com/docs/events-api-v2#alert-de-duplication) for details. | string _(optional)_ | -| summary | A text summary of the event, defaults to `No summary provided`. The maximum length is **1024** characters. | string _(optional)_ | -| source | The affected system, preferably a hostname or fully qualified domain name. Defaults to `Kibana Action `. | string _(optional)_ | -| severity | The perceived severity of on the affected system. This can be one of `critical`, `error`, `warning` or `info`_(default)_. | string _(optional)_ | -| timestamp | An [ISO-8601 format date-time](https://v2.developer.pagerduty.com/v2/docs/types#datetime), indicating the time the event was detected or generated. | string _(optional)_ | -| component | The component of the source machine that is responsible for the event, for example `mysql` or `eth0`. | string _(optional)_ | -| group | Logical grouping of components of a service, for example `app-stack`. | string _(optional)_ | -| class | The class/type of the event, for example `ping failure` or `cpu load`. | string _(optional)_ | +| eventAction | One of `trigger` _(default)_, `resolve`, or `acknowlege`. See [event action](https://v2.developer.pagerduty.com/docs/events-api-v2#event-action) for more details. | string _(optional)_ | +| dedupKey | All actions sharing this key will be associated with the same PagerDuty alert. Used to correlate trigger and resolution. Defaults to `action:`. The maximum length is **255** characters. See [alert deduplication](https://v2.developer.pagerduty.com/docs/events-api-v2#alert-de-duplication) for details. | string _(optional)_ | +| summary | A text summary of the event, defaults to `No summary provided`. The maximum length is **1024** characters. | string _(optional)_ | +| source | The affected system, preferably a hostname or fully qualified domain name. Defaults to `Kibana Action `. | string _(optional)_ | +| severity | The perceived severity of on the affected system. This can be one of `critical`, `error`, `warning` or `info`_(default)_. | string _(optional)_ | +| timestamp | An [ISO-8601 format date-time](https://v2.developer.pagerduty.com/v2/docs/types#datetime), indicating the time the event was detected or generated. | string _(optional)_ | +| component | The component of the source machine that is responsible for the event, for example `mysql` or `eth0`. | string _(optional)_ | +| group | Logical grouping of components of a service, for example `app-stack`. | string _(optional)_ | +| class | The class/type of the event, for example `ping failure` or `cpu load`. | string _(optional)_ | +| links | An array of links to attach to the event | {href,text}[] _(optional)_ | +| images | An array of images to attach to the event | {src,href,alt}[] _(optional)_ | +| customDetails | A map of custom properties to attach to the event | Map[string,string] _(optional)_ | For more details see [PagerDuty v2 event parameters](https://v2.developer.pagerduty.com/v2/docs/send-an-event-events-api-v2). diff --git a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts index 514c9759d7b56..2ab033835c46c 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts @@ -128,6 +128,22 @@ describe('validateParams()', () => { component: 'a component', group: 'a group', class: 'a class', + customDetails: { + 'a key': 'a value', + }, + links: [ + { + href: 'http://example.com/pagerduty', + text: 'a link', + }, + ], + images: [ + { + src: 'http://example.com/pagerduty.png', + href: 'http://example.com/pagerduty', + alt: 'an alternate', + }, + ], }; expect(validateParams(actionType, params)).toEqual(params); }); @@ -213,6 +229,22 @@ describe('execute()', () => { component: 'the-component', group: 'the-group', class: 'the-class', + customDetails: { + 'the-key': 'the-value', + }, + links: [ + { + href: 'http://example.com/pagerduty', + text: 'the link', + }, + ], + images: [ + { + src: 'http://example.com/pagerduty.png', + href: 'http://example.com/pagerduty', + alt: 'the alternate', + }, + ], }; postPagerdutyMock.mockImplementation(() => { @@ -235,9 +267,25 @@ describe('execute()', () => { "data": Object { "dedup_key": "a-dedup-key", "event_action": "trigger", + "images": Array [ + Object { + "alt": "the alternate", + "href": "http://example.com/pagerduty", + "src": "http://example.com/pagerduty.png", + }, + ], + "links": Array [ + Object { + "href": "http://example.com/pagerduty", + "text": "the link", + }, + ], "payload": Object { "class": "the-class", "component": "the-component", + "custom_details": Object { + "the-key": "the-value", + }, "group": "the-group", "severity": "critical", "source": "the-source", @@ -278,6 +326,22 @@ describe('execute()', () => { component: 'the-component', group: 'the-group', class: 'the-class', + customDetails: { + 'the-key': 'the-value', + }, + links: [ + { + href: 'http://example.com/pagerduty', + text: 'the link', + }, + ], + images: [ + { + src: 'http://example.com/pagerduty.png', + href: 'http://example.com/pagerduty', + alt: 'the alternate', + }, + ], }; postPagerdutyMock.mockImplementation(() => { @@ -334,6 +398,22 @@ describe('execute()', () => { component: 'the-component', group: 'the-group', class: 'the-class', + customDetails: { + 'the-key': 'the-value', + }, + links: [ + { + href: 'http://example.com/pagerduty', + text: 'the link', + }, + ], + images: [ + { + src: 'http://example.com/pagerduty.png', + href: 'http://example.com/pagerduty', + alt: 'the alternate', + }, + ], }; postPagerdutyMock.mockImplementation(() => { @@ -372,7 +452,7 @@ describe('execute()', () => { `); }); - test('should fail when sendPagerdury throws', async () => { + test('should fail when sendPagerduty throws', async () => { const secrets = { routingKey: 'super-secret' }; const config = {}; const params = {}; @@ -400,7 +480,7 @@ describe('execute()', () => { `); }); - test('should fail when sendPagerdury returns 429', async () => { + test('should fail when sendPagerduty returns 429', async () => { const secrets = { routingKey: 'super-secret' }; const config = {}; const params = {}; @@ -428,7 +508,7 @@ describe('execute()', () => { `); }); - test('should fail when sendPagerdury returns 501', async () => { + test('should fail when sendPagerduty returns 501', async () => { const secrets = { routingKey: 'super-secret' }; const config = {}; const params = {}; @@ -456,7 +536,7 @@ describe('execute()', () => { `); }); - test('should fail when sendPagerdury returns 418', async () => { + test('should fail when sendPagerduty returns 418', async () => { const secrets = { routingKey: 'super-secret' }; const config = {}; const params = {}; diff --git a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts index 2b607d0dd41ba..074ab8af0ca10 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts @@ -64,6 +64,24 @@ const ParamsSchema = schema.object( component: schema.maybe(schema.string()), group: schema.maybe(schema.string()), class: schema.maybe(schema.string()), + links: schema.maybe( + schema.arrayOf( + schema.object({ + href: schema.uri(), + text: schema.maybe(schema.string()), + }) + ) + ), + images: schema.maybe( + schema.arrayOf( + schema.object({ + src: schema.uri(), + href: schema.maybe(schema.uri()), + alt: schema.maybe(schema.string()), + }) + ) + ), + customDetails: schema.maybe(schema.recordOf(schema.string(), schema.string())), }, { validate: validateParams } ); @@ -234,6 +252,9 @@ function getBodyForEventAction(actionId: string, params: ActionParamsType): any if (params.component != null) data.payload.component = params.component; if (params.group != null) data.payload.group = params.group; if (params.class != null) data.payload.class = params.class; + if (params.customDetails != null) data.payload.custom_details = params.customDetails; + if (params.links != null) data.links = params.links; + if (params.images != null) data.images = params.images; return data; }