forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Watcher] Add Index, HipChat, PagerDuty, and Jira Action types on the…
… client (elastic#30043) (elastic#30620)
- Loading branch information
Showing
6 changed files
with
321 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
x-pack/plugins/watcher/public/models/action/hipchat.action.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
import { get } from 'lodash'; | ||
import { BaseAction } from './base_action'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
const requiredFields = ['message']; | ||
const optionalFields = ['account', 'proxy']; | ||
|
||
const allFields = [...requiredFields, ...optionalFields]; | ||
|
||
export class HipchatAction extends BaseAction { | ||
constructor(props = {}) { | ||
super(props); | ||
|
||
this.fields = {}; | ||
allFields.forEach((field) => { | ||
this.fields[field] = get(props, field); | ||
}); | ||
} | ||
|
||
get upstreamJson() { | ||
// Add all required fields to the request body | ||
let result = requiredFields.reduce((acc, field) => { | ||
acc[field] = this.fields[field]; | ||
return acc; | ||
}, super.upstreamJson); | ||
|
||
// If optional fields have been set, add them to the body | ||
result = optionalFields.reduce((acc, field) => { | ||
if (this[field]) { | ||
acc[field] = this.fields[field]; | ||
} | ||
return acc; | ||
}, result); | ||
|
||
return result; | ||
} | ||
|
||
get description() { | ||
return i18n.translate('xpack.watcher.models.hipchatAction.description', { | ||
defaultMessage: '{body} will be sent through Hipchat', | ||
values: { | ||
body: this.fields.message && this.fields.message.body || '' | ||
} | ||
}); | ||
} | ||
|
||
get simulateMessage() { | ||
return i18n.translate('xpack.watcher.models.hipchatAction.simulateMessage', { | ||
defaultMessage: 'Hipchat message has been sent.', | ||
}); | ||
} | ||
|
||
get simulateFailMessage() { | ||
return i18n.translate('xpack.watcher.models.hipchatAction.simulateFailMessage', { | ||
defaultMessage: 'Failed to send Hipchat message.', | ||
}); | ||
} | ||
|
||
static fromUpstreamJson(upstreamAction) { | ||
return new HipchatAction(upstreamAction); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
x-pack/plugins/watcher/public/models/action/index.action.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
import { get } from 'lodash'; | ||
import { BaseAction } from './base_action'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
const requiredFields = ['host', 'port']; | ||
const optionalFields = [ | ||
'scheme', | ||
'path', | ||
'method', | ||
'headers', | ||
'params', | ||
'auth', | ||
'body', | ||
'proxy', | ||
'connection_timeout', | ||
'read_timeout', | ||
'url' | ||
]; | ||
|
||
const allFields = [...requiredFields, ...optionalFields]; | ||
|
||
export class IndexAction extends BaseAction { | ||
constructor(props = {}) { | ||
super(props); | ||
|
||
this.fields = {}; | ||
allFields.forEach((field) => { | ||
this.fields[field] = get(props, field); | ||
}); | ||
} | ||
|
||
get upstreamJson() { | ||
// Add all required fields to the request body | ||
let result = requiredFields.reduce((acc, field) => { | ||
acc[field] = this.fields[field]; | ||
return acc; | ||
}, super.upstreamJson); | ||
|
||
// If optional fields have been set, add them to the body | ||
result = optionalFields.reduce((acc, field) => { | ||
if (this[field]) { | ||
acc[field] = this.fields[field]; | ||
} | ||
return acc; | ||
}, result); | ||
|
||
return result; | ||
} | ||
|
||
get description() { | ||
return i18n.translate('xpack.watcher.models.indexAction.description', { | ||
defaultMessage: 'The {index} will be indexed as {docType}', | ||
values: { | ||
index: this.fields.index, | ||
docType: this.fields.doc_type, | ||
} | ||
}); | ||
} | ||
|
||
get simulateMessage() { | ||
return i18n.translate('xpack.watcher.models.indexAction.simulateMessage', { | ||
defaultMessage: 'Index {index} has been indexed.', | ||
values: { | ||
index: this.index, | ||
} | ||
}); | ||
} | ||
|
||
get simulateFailMessage() { | ||
return i18n.translate('xpack.watcher.models.indexAction.simulateFailMessage', { | ||
defaultMessage: 'Failed to index {index}.', | ||
values: { | ||
index: this.index | ||
} | ||
}); | ||
} | ||
|
||
static fromUpstreamJson(upstreamAction) { | ||
return new IndexAction(upstreamAction); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/watcher/public/models/action/jira.action.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
import { get } from 'lodash'; | ||
import { BaseAction } from './base_action'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
const requiredFields = ['fields']; | ||
const optionalFields = ['account', 'proxy']; | ||
|
||
const allFields = [...requiredFields, ...optionalFields]; | ||
|
||
export class JiraAction extends BaseAction { | ||
constructor(props = {}) { | ||
super(props); | ||
|
||
this.fields = {}; | ||
allFields.forEach((field) => { | ||
this.fields[field] = get(props, field); | ||
}); | ||
} | ||
|
||
get upstreamJson() { | ||
// Add all required fields to the request body | ||
let result = requiredFields.reduce((acc, field) => { | ||
acc[field] = this.fields[field]; | ||
return acc; | ||
}, super.upstreamJson); | ||
|
||
// If optional fields have been set, add them to the body | ||
result = optionalFields.reduce((acc, field) => { | ||
if (this[field]) { | ||
acc[field] = this.fields[field]; | ||
} | ||
return acc; | ||
}, result); | ||
|
||
return result; | ||
} | ||
|
||
get description() { | ||
return i18n.translate('xpack.watcher.models.jiraAction.description', { | ||
defaultMessage: '{issueName} will be created in Jira', | ||
values: { | ||
issueName: get(this.fields, 'fields.issue.issuetype.name', ''), | ||
} | ||
}); | ||
} | ||
|
||
get simulateMessage() { | ||
return i18n.translate('xpack.watcher.models.jiraAction.simulateMessage', { | ||
defaultMessage: 'Jira issue has been created.', | ||
}); | ||
} | ||
|
||
get simulateFailMessage() { | ||
return i18n.translate('xpack.watcher.models.jiraAction.simulateFailMessage', { | ||
defaultMessage: 'Failed to create Jira issue.', | ||
}); | ||
} | ||
|
||
static fromUpstreamJson(upstreamAction) { | ||
return new JiraAction(upstreamAction); | ||
} | ||
} | ||
|
80 changes: 80 additions & 0 deletions
80
x-pack/plugins/watcher/public/models/action/pagerduty.action.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
import { get } from 'lodash'; | ||
import { BaseAction } from './base_action'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
const requiredFields = ['description', 'type']; | ||
const optionalFields = [ | ||
'event_type', | ||
'incident_key', | ||
'client', | ||
'client_url', | ||
'attach_payload', | ||
'contexts', | ||
'proxy', | ||
'href', | ||
'src', | ||
]; | ||
|
||
const allFields = [...requiredFields, ...optionalFields]; | ||
|
||
export class PagerDutyAction extends BaseAction { | ||
constructor(props = {}) { | ||
super(props); | ||
|
||
this.fields = {}; | ||
allFields.forEach((field) => { | ||
this.fields[field] = get(props, field); | ||
}); | ||
} | ||
|
||
get upstreamJson() { | ||
// Add all required fields to the request body | ||
let result = requiredFields.reduce((acc, field) => { | ||
acc[field] = this.fields[field]; | ||
return acc; | ||
}, super.upstreamJson); | ||
|
||
// If optional fields have been set, add them to the body | ||
result = optionalFields.reduce((acc, field) => { | ||
if (this.fields[field]) { | ||
acc[field] = this.fields[field]; | ||
} | ||
return acc; | ||
}, result); | ||
|
||
return result; | ||
} | ||
|
||
get description() { | ||
return i18n.translate('xpack.watcher.models.pagerDutyAction.description', { | ||
defaultMessage: '{description} will be sent to PagerDuty', | ||
values: { | ||
description: this.fields.description, | ||
} | ||
}); | ||
} | ||
|
||
get simulateMessage() { | ||
return i18n.translate('xpack.watcher.models.pagerDutyAction.simulateMessage', { | ||
defaultMessage: 'PagerDuty event has been sent.', | ||
}); | ||
} | ||
|
||
get simulateFailMessage() { | ||
return i18n.translate('xpack.watcher.models.pagerDutyAction.simulateFailMessage', { | ||
defaultMessage: 'Failed to send Hipchat event.', | ||
}); | ||
} | ||
|
||
static fromUpstreamJson(upstreamAction) { | ||
return new PagerDutyAction(upstreamAction); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters