Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Apr 24, 2019
1 parent b25f6ee commit 7d85488
Show file tree
Hide file tree
Showing 37 changed files with 371 additions and 629 deletions.
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
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;
12 changes: 0 additions & 12 deletions x-pack/plugins/watcher/common/types/watch_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,3 @@ export interface BaseWatch {
};
};
}

export interface WatchAction {
id: string;
type: 'email' | 'webhook' | 'index' | 'logging' | 'slack' | 'jira' | 'pagerduty';
typeName: string;
iconClass: 'loggingApp' | 'logoWebhook' | 'logoSlack' | 'apps' | 'email' | 'indexOpen';
simulateMessage: string;
simulateFailMessage: string;
simulatePrompt: string;
selectMessage: string;
text?: string;
}
26 changes: 3 additions & 23 deletions x-pack/plugins/watcher/public/models/action/email_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ export class EmailAction extends BaseAction {
this.body = get(props, 'body');
}

validateAction() {
validate() {
const errors = {
to: [],
subject: [],
body: [],
};
if (!this.to || this.to.length === 0) {
Expand All @@ -31,17 +30,10 @@ export class EmailAction extends BaseAction {
})
);
}
if (!this.subject) {
errors.subject.push(
i18n.translate('xpack.watcher.watchActions.email.emailSubjectIsRequiredValidationMessage', {
defaultMessage: 'Subject is required.',
})
);
}
if (!this.body) {
errors.body.push(
i18n.translate('xpack.watcher.watchActions.email.emailBodyIsRequiredValidationMessage', {
defaultMessage: 'Body is required.',
defaultMessage: 'Email body is required.',
})
);
}
Expand All @@ -56,25 +48,13 @@ 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', {
Expand Down
14 changes: 2 additions & 12 deletions x-pack/plugins/watcher/public/models/action/index_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export class IndexAction extends BaseAction {
this.index = get(props, 'index');
}

validateAction() {
validate() {
const errors = {
index: [],
};
if (!this.index) {
errors.index.push(
i18n.translate('xpack.watcher.watchActions.index.indexIsRequiredValidationMessage', {
defaultMessage: 'Index is required.',
defaultMessage: 'Index name is required.',
})
);
}
Expand All @@ -43,16 +43,6 @@ export class IndexAction extends BaseAction {
return result;
}

get description() {
const index = this.index || '';
return i18n.translate('xpack.watcher.models.indexAction.description', {
defaultMessage: 'The {index} will be indexed',
values: {
index,
}
});
}

get simulateMessage() {
const index = this.index || '';
return i18n.translate('xpack.watcher.models.indexAction.simulateMessage', {
Expand Down
17 changes: 4 additions & 13 deletions x-pack/plugins/watcher/public/models/action/jira_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class JiraAction extends BaseAction {
this.summary = get(props, 'summary');
}

validateAction() {
validate() {
const errors = {
projectKey: [],
issueType: [],
Expand All @@ -26,21 +26,21 @@ export class JiraAction extends BaseAction {
if (!this.projectKey) {
errors.projectKey.push(
i18n.translate('xpack.watcher.watchActions.jira.projectKeyIsRequiredValidationMessage', {
defaultMessage: 'Project key is required.',
defaultMessage: 'Jira project key is required.',
})
);
}
if (!this.issueType) {
errors.issueType.push(
i18n.translate('xpack.watcher.watchActions.jira.issueTypeNameIsRequiredValidationMessage', {
defaultMessage: 'Issue type is required.',
defaultMessage: 'Jira issue type is required.',
})
);
}
if (!this.summary) {
errors.summary.push(
i18n.translate('xpack.watcher.watchActions.jira.summaryIsRequiredValidationMessage', {
defaultMessage: 'Summary is required.',
defaultMessage: 'Jira summary is required.',
})
);
}
Expand Down Expand Up @@ -72,15 +72,6 @@ export class JiraAction extends BaseAction {
return result;
}

get description() {
return i18n.translate('xpack.watcher.models.jiraAction.description', {
defaultMessage: '{issueType} will be created in Jira',
values: {
issueType: this.issueType,
}
});
}

get simulateMessage() {
return i18n.translate('xpack.watcher.models.jiraAction.simulateMessage', {
defaultMessage: 'Jira issue has been created.',
Expand Down
12 changes: 1 addition & 11 deletions x-pack/plugins/watcher/public/models/action/logging_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class LoggingAction extends BaseAction {
this.text = get(props, 'text');
}

validateAction() {
validate() {
const errors = {
text: [],
};
Expand Down Expand Up @@ -43,16 +43,6 @@ export class LoggingAction extends BaseAction {
return result;
}

get description() {
const text = this.text || '';
return i18n.translate('xpack.watcher.models.loggingAction.description', {
defaultMessage: 'Log message \'{text}\'',
values: {
text
}
});
}

get simulateMessage() {
return i18n.translate('xpack.watcher.models.loggingAction.simulateMessage', {
defaultMessage: 'Sample message logged',
Expand Down
24 changes: 9 additions & 15 deletions x-pack/plugins/watcher/public/models/action/pagerduty_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import { i18n } from '@kbn/i18n';
export class PagerDutyAction extends BaseAction {
constructor(props = {}) {
super(props);
this.message = get(props, 'message');
this.description = get(props, 'description');
}

validateAction() {
validate() {
const errors = {
message: [],
description: [],
};

if (!this.message) {
errors.message.push(
if (!this.description) {
errors.description.push(
i18n.translate('xpack.watcher.watchActions.pagerduty.descriptionIsRequiredValidationMessage', {
defaultMessage: 'Description is required.',
defaultMessage: 'PagerDuty description is required.',
})
);
}
Expand All @@ -34,21 +34,15 @@ export class PagerDutyAction extends BaseAction {
const result = super.upstreamJson;

Object.assign(result, {
description: this.message,
description: this.description,
pagerduty: {
description: this.message,
description: this.description,
}
});

return result;
}

get description() {
return i18n.translate('xpack.watcher.models.pagerDutyAction.description', {
defaultMessage: 'A message will be sent to PagerDuty',
});
}

get simulateMessage() {
return i18n.translate('xpack.watcher.models.pagerDutyAction.simulateMessage', {
defaultMessage: 'PagerDuty event has been sent.',
Expand Down Expand Up @@ -76,7 +70,7 @@ export class PagerDutyAction extends BaseAction {
defaultMessage: 'Test fire a PagerDuty event'
});
static defaults = {
message: 'Watch [{{ctx.metadata.name}}] has exceeded the threshold'
description: 'Watch [{{ctx.metadata.name}}] has exceeded the threshold'
};
}

Loading

0 comments on commit 7d85488

Please sign in to comment.