Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for all event fields in the Pagerduty action plugin #64120

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions x-pack/plugins/actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:<action id>`. 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 <action id>`. | 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:<action id>`. 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 <action id>`. | 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)_ |
Comment on lines +458 to +460
Copy link
Contributor

Choose a reason for hiding this comment

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

We're working on this but we currently have duplication between this file and docs/user/alerting/action-types/pagerduty.asciidoc for now. Would you be able to copy these lines to the user docs as well?

I'll make sure we have an issue to cleanup the README.md file so it doesn't repeat what's in the docs.


For more details see [PagerDuty v2 event parameters](https://v2.developer.pagerduty.com/v2/docs/send-an-event-events-api-v2).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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",
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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 = {};
Expand Down
21 changes: 21 additions & 0 deletions x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Copy link
Member

Choose a reason for hiding this comment

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

This will need to be a schema.nullable() vs schema.maybe(), to prevent "partial updates" of this field when it's updated in ES. Without it, it's impossible to delete fields in the record.

Copy link
Member

Choose a reason for hiding this comment

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

same is true for links and images as well, ^^^

},
{ validate: validateParams }
);
Expand Down Expand Up @@ -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;
}