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

[Watcher] Support for adding actions to threshold watch #35175

Merged
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
b107924
initial support for adding actions via threshold watch
alisonelizabeth Apr 16, 2019
38e3d55
added validation; support for email and slack action types
alisonelizabeth Apr 17, 2019
ab7f44e
added support for index action
alisonelizabeth Apr 18, 2019
ac0b569
added support for webhook action
alisonelizabeth Apr 19, 2019
f3ce9ca
added support for pagerduty action
alisonelizabeth Apr 22, 2019
419c349
Merge remote-tracking branch 'upstream/watcher-port' into threshold-w…
alisonelizabeth Apr 22, 2019
b25f6ee
added support for jira action
alisonelizabeth Apr 22, 2019
7d85488
cleanup
alisonelizabeth Apr 23, 2019
7c4d032
Merge remote-tracking branch 'upstream/watcher-port' into threshold-w…
alisonelizabeth Apr 24, 2019
e858f66
remove extra spacers
alisonelizabeth Apr 24, 2019
4ad38cb
Add SCSS file and tweak actions dropdown position.
cjcenizal Apr 24, 2019
721b20a
Merge pull request #1 from cjcenizal/watcher/actions-dropdown-tweaks
alisonelizabeth Apr 25, 2019
03b58c0
address review comments
alisonelizabeth Apr 25, 2019
85fc8df
adjust logic that determines if actions are enabled/disabled
alisonelizabeth Apr 26, 2019
762eb44
Merge remote-tracking branch 'upstream/watcher-port' into threshold-w…
alisonelizabeth Apr 26, 2019
884335c
addressing pr feedback
alisonelizabeth Apr 29, 2019
514149b
Merge remote-tracking branch 'upstream/watcher-port' into threshold-w…
alisonelizabeth May 1, 2019
3aca320
fix linting error
alisonelizabeth May 1, 2019
3896071
Merge remote-tracking branch 'upstream/watcher-port' into threshold-w…
alisonelizabeth May 3, 2019
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
3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -7847,7 +7847,6 @@
"xpack.watcher.models.baseWatch.watchStatusJsonPropertyMissingBadRequestMessage": "json 参数必须包含 {watchStatusJson} 属性",
"xpack.watcher.models.emailAction.actionJsonEmailPropertyMissingBadRequestMessage": "json 参数必须包含 {actionJsonEmail} 属性",
"xpack.watcher.models.emailAction.actionJsonEmailToPropertyMissingBadRequestMessage": "json 参数必须包含 {actionJsonEmailTo} 属性",
"xpack.watcher.models.emailAction.description": "“{subject}” 将发送至 {toList}",
"xpack.watcher.models.emailAction.selectMessageText": "从您的服务器发送电子邮件。",
"xpack.watcher.models.emailAction.simulateButtonLabel": "立即试发电子邮件",
"xpack.watcher.models.emailAction.simulateFailMessage": "无法将电子邮件发至 {toList}。",
Expand All @@ -7858,7 +7857,6 @@
"xpack.watcher.models.jsonWatch.typeName": "高级监视",
"xpack.watcher.models.loggingAction.actionJsonLoggingPropertyMissingBadRequestMessage": "json 参数必须包含 {actionJsonLogging} 属性",
"xpack.watcher.models.loggingAction.actionJsonLoggingTextPropertyMissingBadRequestMessage": "json 参数必须包含 {actionJsonLoggingText} 属性",
"xpack.watcher.models.loggingAction.description": "记录消息“{text}”",
"xpack.watcher.models.loggingAction.selectMessageText": "向日志添加新项。",
"xpack.watcher.models.loggingAction.simulateButtonLabel": "立即记录示例消息",
"xpack.watcher.models.loggingAction.simulateFailMessage": "无法记录示例消息。",
Expand All @@ -7870,7 +7868,6 @@
"xpack.watcher.models.monitoringWatch.upstreamJsonCalledBadRequestMessage": "为监测监视而调用的 {upstreamJson}",
"xpack.watcher.models.slackAction.actionJsonSlackMessagePropertyMissingBadRequestMessage": "json 参数必须包含 {actionJsonSlackMessage} 属性",
"xpack.watcher.models.slackAction.actionJsonSlackPropertyMissingBadRequestMessage": "json 参数必须包含 {actionJsonSlack} 属性",
"xpack.watcher.models.slackAction.description": "Slack 消息将发至 {toList}",
"xpack.watcher.models.slackAction.selectMessageText": "向 slack 用户或渠道发送消息。",
"xpack.watcher.models.slackAction.simulateButtonLabel": "立即发送示例消息",
"xpack.watcher.models.slackAction.simulateFailMessage": "无法将示例 Slack 消息发至 {toList}。",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/watcher/common/constants/action_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export const ACTION_TYPES: { [key: string]: string } = {

LOGGING: 'logging',

HIPCHAT: 'hipchat',

SLACK: 'slack',

JIRA: 'jira',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ describe('get_action_type', () => {
expect(type).to.be(ACTION_TYPES.LOGGING);
});

it(`correctly calculates ACTION_TYPES.HIPCHAT`, () => {
const actionJson = {
hipchat: {
'foo': 'bar'
}
};
const type = getActionType(actionJson);

expect(type).to.be(ACTION_TYPES.HIPCHAT);
});

it(`correctly calculates ACTION_TYPES.SLACK`, () => {
const actionJson = {
slack: {
Expand Down
84 changes: 84 additions & 0 deletions x-pack/plugins/watcher/common/types/action_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* 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.
*/

type EmailActionType = 'email';
type LoggingActionType = 'logging';
type WebhookActionType = 'webhook';
type IndexActionType = 'index';
type SlackActionType = 'slack';
type JiraActionType = 'jira';
type PagerDutyActionType = 'pagerduty';

export interface BaseAction {
id: string;
typeName: string;
simulateMessage: string;
simulateFailMessage: string;
simulatePrompt: string;
selectMessage: string;
validate: () => { [key: string]: string[] };
isEnabled: boolean;
}

export interface EmailAction extends BaseAction {
type: EmailActionType;
iconClass: 'email';
to: [];
subject?: string;
body: string;
}

export interface LoggingAction extends BaseAction {
type: LoggingActionType;
iconClass: 'loggingApp';
text: string;
}

export interface IndexAction extends BaseAction {
type: IndexActionType;
iconClass: 'indexOpen';
index: string;
}

export interface PagerDutyAction extends BaseAction {
type: PagerDutyActionType;
iconClass: 'apps';
description: string;
}

export interface WebhookAction extends BaseAction {
type: WebhookActionType;
iconClass: 'logoWebhook';
method?: 'head' | 'get' | 'post' | 'put' | 'delete';
host: string;
port: number;
path?: string;
body: string;
}

export interface SlackAction extends BaseAction {
type: SlackActionType;
iconClass: 'logoSlack';
text: string;
to: string[];
}

export interface JiraAction extends BaseAction {
type: JiraActionType;
iconClass: 'apps';
account?: string;
projectKey: string;
issueType: string;
summary: string;
}

export type ActionType =
| EmailAction
| LoggingAction
| IndexAction
| SlackAction
| JiraAction
| PagerDutyAction;
1 change: 1 addition & 0 deletions x-pack/plugins/watcher/plugin_definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const pluginDefinition = {
publicDir: resolve(__dirname, 'public'),
require: ['kibana', 'elasticsearch', 'xpack_main'],
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
managementSections: ['plugins/watcher'],
home: ['plugins/watcher/register_feature'],
},
Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/watcher/public/_hacks.scss

This file was deleted.

16 changes: 16 additions & 0 deletions x-pack/plugins/watcher/public/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Import the EUI global scope so we can use EUI constants
@import 'src/legacy/ui/public/styles/_styling_constants';

// Watcher plugin styles

// Prefix all styles with "watcher" to avoid conflicts.
// Examples
// watcherChart
// watcherChart__legend
// watcherChart__legend--small
// watcherChart__legend-isLoading

.watcherThresholdWatchActionDropdownContainer {
justify-content: flex-end;
flex-direction: row;
}
7 changes: 7 additions & 0 deletions x-pack/plugins/watcher/public/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { Settings } from 'plugins/watcher/models/settings';
import { Watch } from 'plugins/watcher/models/watch';
import { WatchHistoryItem } from 'plugins/watcher/models/watch_history_item';
import { WatchStatus } from 'plugins/watcher/models/watch_status';
Expand Down Expand Up @@ -157,10 +158,16 @@ export const loadIndexPatterns = async () => {
});
return savedObjects;
};

export const getWatchVisualizationData = async (watchModel: BaseWatch, visualizeOptions: any) => {
const response = await getHttpClient().post(`${basePath}/watch/visualize`, {
watch: watchModel.upstreamJson,
options: visualizeOptions.upstreamJson,
});
return response.data;
};

export const fetchSettings = async () => {
const { data } = await getHttpClient().get(`${basePath}/settings`);
return Settings.fromUpstreamJson(data);
};
10 changes: 4 additions & 6 deletions x-pack/plugins/watcher/public/models/action/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import { ACTION_TYPES } from 'plugins/watcher/../common/constants';
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 { WebhookAction } from './webhook_action';
import { IndexAction } from './index_action';
import { PagerDutyAction } from './pagerduty_action';
import { JiraAction } from './jira_action';
import { UnknownAction } from './unknown_action';

const ActionTypes = {};
Expand All @@ -22,7 +21,6 @@ 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);

Expand Down
7 changes: 1 addition & 6 deletions x-pack/plugins/watcher/public/models/action/base_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,10 @@ export class BaseAction {
return this.constructor.simulatePrompt;
}

get template() {
return this.constructor.template;
}

static typeName = i18n.translate('xpack.watcher.models.baseAction.typeName', {
defaultMessage: 'Action',
});
static iconClass = 'fa-cog';
static template = '';
static iconClass = 'apps';
static selectMessage = i18n.translate('xpack.watcher.models.baseAction.selectMessageText', {
defaultMessage: 'Perform an action.',
});
Expand Down
60 changes: 36 additions & 24 deletions x-pack/plugins/watcher/public/models/action/email_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,32 @@ export class EmailAction extends BaseAction {
constructor(props = {}) {
super(props);

const toArray = get(props, 'to', []);
this.to = isArray(toArray) ? toArray : [ toArray ];
this.subject = get(props, 'subject', '');
this.body = get(props, 'body', '');
const toArray = get(props, 'to');
this.to = isArray(toArray) ? toArray : toArray && [ toArray ];
this.subject = get(props, 'subject');
this.body = get(props, 'body');
}

validate() {
const errors = {
to: [],
body: [],
};
if (!this.to || this.to.length === 0) {
errors.to.push(
i18n.translate('xpack.watcher.watchActions.email.emailRecipientIsRequiredValidationMessage', {
defaultMessage: 'To email address is required.',
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not native speaker, but shouldn't we quote the "to"? "To" email property is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Updated, but also plan on doing a copy review with gail.

})
);
}
if (!this.body) {
errors.body.push(
i18n.translate('xpack.watcher.watchActions.email.emailBodyIsRequiredValidationMessage', {
defaultMessage: 'Email body is required.',
})
);
}
return errors;
}

get upstreamJson() {
Expand All @@ -26,29 +48,17 @@ export class EmailAction extends BaseAction {
subject: this.subject,
body: this.body,
email: {
to: this.to.length ? this.to : undefined,
to: this.to && this.to.length ? this.to : undefined,
}
});

return result;
}

get description() {
const toList = this.to.join(', ');
const subject = this.subject || '';
return i18n.translate('xpack.watcher.models.emailAction.description', {
defaultMessage: '"{subject}" will be sent to {toList}',
values: {
subject,
toList
}
});
}

get simulateMessage() {
const toList = this.to.join(', ');
return i18n.translate('xpack.watcher.models.emailAction.simulateMessage', {
defaultMessage: 'Sample e-mail sent to {toList}',
defaultMessage: 'Sample email sent to {toList}',
values: {
toList
}
Expand All @@ -58,7 +68,7 @@ export class EmailAction extends BaseAction {
get simulateFailMessage() {
const toList = this.to.join(', ');
return i18n.translate('xpack.watcher.models.emailAction.simulateFailMessage', {
defaultMessage: 'Failed to send e-mail to {toList}.',
defaultMessage: 'Failed to send email to {toList}.',
values: {
toList
}
Expand All @@ -70,14 +80,16 @@ export class EmailAction extends BaseAction {
}

static typeName = i18n.translate('xpack.watcher.models.emailAction.typeName', {
defaultMessage: 'E-mail',
defaultMessage: 'Email',
});
static iconClass = 'kuiIcon fa-envelope-o';
static template = '<watch-email-action></watch-email-action>';
static iconClass = 'email';
static selectMessage = i18n.translate('xpack.watcher.models.emailAction.selectMessageText', {
defaultMessage: 'Send out an e-mail from your server.',
defaultMessage: 'Send out an email from your server.',
});
static simulatePrompt = i18n.translate('xpack.watcher.models.emailAction.simulateButtonLabel', {
defaultMessage: 'Test fire an e-mail now'
defaultMessage: 'Test fire an email now'
});
static defaults = {
subject: 'Watch [{{ctx.metadata.name}}] has exceeded the threshold'
};
}
Loading