mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
This commit is contained in:
parent
62aebccedb
commit
bd7732cb1c
6 changed files with 321 additions and 27 deletions
|
@ -10,6 +10,10 @@ import { EmailAction } from './email_action';
|
|||
import { LoggingAction } from './logging_action';
|
||||
import { SlackAction } from './slack_action';
|
||||
import { WebhookAction } from './webhook.action';
|
||||
import { IndexAction } from './index.action';
|
||||
import { HipchatAction } from './hipchat.action';
|
||||
import { PagerDutyAction } from './pagerduty.action';
|
||||
import { JiraAction } from './jira.action';
|
||||
import { UnknownAction } from './unknown_action';
|
||||
|
||||
const ActionTypes = {};
|
||||
|
@ -17,6 +21,10 @@ set(ActionTypes, ACTION_TYPES.EMAIL, EmailAction);
|
|||
set(ActionTypes, ACTION_TYPES.LOGGING, LoggingAction);
|
||||
set(ActionTypes, ACTION_TYPES.SLACK, SlackAction);
|
||||
set(ActionTypes, ACTION_TYPES.WEBHOOK, WebhookAction);
|
||||
set(ActionTypes, ACTION_TYPES.INDEX, IndexAction);
|
||||
set(ActionTypes, ACTION_TYPES.HIPCHAT, HipchatAction);
|
||||
set(ActionTypes, ACTION_TYPES.PAGERDUTY, PagerDutyAction);
|
||||
set(ActionTypes, ACTION_TYPES.JIRA, JiraAction);
|
||||
|
||||
export class Action {
|
||||
static getActionTypes = () => {
|
||||
|
|
|
@ -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
x-pack/plugins/watcher/public/models/action/index.action.js
Normal file
88
x-pack/plugins/watcher/public/models/action/index.action.js
Normal file
|
@ -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
x-pack/plugins/watcher/public/models/action/jira.action.js
Normal file
70
x-pack/plugins/watcher/public/models/action/jira.action.js
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -30,24 +30,26 @@ export class WebhookAction extends BaseAction {
|
|||
constructor(props = {}) {
|
||||
super(props);
|
||||
|
||||
this.fields = {};
|
||||
allFields.forEach((field) => {
|
||||
this[field] = get(props, field);
|
||||
this.fields[field] = get(props, field);
|
||||
});
|
||||
|
||||
this.fullPath = this.url ? this.url : this.host + this.port + this.path;
|
||||
const { url, host, port, path } = this.fields;
|
||||
this.fullPath = url ? url : host + port + path;
|
||||
}
|
||||
|
||||
get upstreamJson() {
|
||||
// Add all required fields to the request body
|
||||
let result = requiredFields.reduce((acc, field) => {
|
||||
acc[field] = this[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[field];
|
||||
acc[field] = this.fields[field];
|
||||
}
|
||||
return acc;
|
||||
}, result);
|
||||
|
@ -86,27 +88,4 @@ export class WebhookAction extends BaseAction {
|
|||
static fromUpstreamJson(upstreamAction) {
|
||||
return new WebhookAction(upstreamAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE:
|
||||
*
|
||||
* I don't seem to find in the UI where those static properties are actuall used.
|
||||
* It looks like we used to have a UI to create an action and that currently we only have
|
||||
* the "advanced watcher" creation through the JSON editor.
|
||||
*
|
||||
* ---> ./components/watch_actions/components/watch_action/watch_actions.html
|
||||
* is where it seems that this is read. But I can't access that component navigatint the UI
|
||||
*
|
||||
*/
|
||||
// static typeName = i18n.translate('xpack.watcher.models.webhookAction.typeName', {
|
||||
// defaultMessage: 'E-mail',
|
||||
// });
|
||||
// static iconClass = 'kuiIcon fa-envelope-o';
|
||||
// static template = '<watch-email-action></watch-email-action>';
|
||||
// static selectMessage = i18n.translate('xpack.watcher.models.webhookAction.selectMessageText', {
|
||||
// defaultMessage: 'Send out an e-mail from your server.',
|
||||
// });
|
||||
// static simulatePrompt = i18n.translate('xpack.watcher.models.webhookAction.simulateButtonLabel', {
|
||||
// defaultMessage: 'Test fire an e-mail now'
|
||||
// });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue