From 972debac8b2e64bc49d7190183ce873dd66f6543 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Thu, 27 Oct 2016 14:40:51 -0700 Subject: [PATCH] Add Telegram configuration --- ui/src/kapacitor/components/AlertOutputs.js | 16 ++- ui/src/kapacitor/components/TelegramConfig.js | 133 ++++++++++++++++++ 2 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 ui/src/kapacitor/components/TelegramConfig.js diff --git a/ui/src/kapacitor/components/AlertOutputs.js b/ui/src/kapacitor/components/AlertOutputs.js index e5b9a6acab..00dc83eea1 100644 --- a/ui/src/kapacitor/components/AlertOutputs.js +++ b/ui/src/kapacitor/components/AlertOutputs.js @@ -4,6 +4,7 @@ import {getKapacitorConfig, updateKapacitorConfigSection, testAlertOutput} from import AlertaConfig from './AlertaConfig'; import SlackConfig from './SlackConfig'; import SMTPConfig from './SMTPConfig'; +import TelegramConfig from './TelegramConfig'; import VictoropsConfig from './VictoropsConfig'; const AlertOutputs = React.createClass({ @@ -39,12 +40,16 @@ const AlertOutputs = React.createClass({ alertaConfig: this.getSection(sections, 'alerta'), slackConfig: this.getSection(sections, 'slack'), smtpConfig: this.getSection(sections, 'smtp'), - telegram: this.getSection(sections, 'telegram'), + telegramConfig: this.getSection(sections, 'telegram'), victoropsConfig: this.getSection(sections, 'victorops'), }); }); }, + getSection(sections, section) { + return _.get(sections, [section, 'elements', '0'], null); + }, + handleSaveConfig(section, properties) { if (section !== '') { updateKapacitorConfigSection(this.props.kapacitor, section, Object.assign({}, properties, {enabled: true})).then(() => { @@ -90,6 +95,7 @@ const AlertOutputs = React.createClass({ + @@ -100,10 +106,6 @@ const AlertOutputs = React.createClass({ ); }, - getSection(sections, section) { - return _.get(sections, [section, 'elements', '0'], null); - }, - renderAlertConfig(endpoint) { const save = (properties) => { this.handleSaveConfig(endpoint, properties); @@ -125,6 +127,10 @@ const AlertOutputs = React.createClass({ return ; } + if (endpoint === 'telegram' && this.state.telegramConfig) { + return ; + } + return
This endpoint is not supported yet!
; }, }); diff --git a/ui/src/kapacitor/components/TelegramConfig.js b/ui/src/kapacitor/components/TelegramConfig.js new file mode 100644 index 0000000000..1f72d18b0f --- /dev/null +++ b/ui/src/kapacitor/components/TelegramConfig.js @@ -0,0 +1,133 @@ +import React, {PropTypes} from 'react'; + +const TelegramConfig = React.createClass({ + propTypes: { + config: PropTypes.shape({ + options: PropTypes.shape({ + 'chat-id': PropTypes.string.isRequired, + 'disable-notification': PropTypes.bool.isRequired, + 'disable-web-page-preview': PropTypes.bool.isRequired, + global: PropTypes.bool.isRequired, + 'parse-mode': PropTypes.string.isRequired, + 'state-changes-only': PropTypes.bool.isRequired, + token: PropTypes.bool.isRequired, + url: PropTypes.string.isRequired, + }).isRequired, + }).isRequired, + onSave: PropTypes.func.isRequired, + }, + + handleSaveAlert(e) { + e.preventDefault(); + + const properties = { + chatID: this.chatID.value, + disableNotification: this.disableNotification.checked, + disableWebPagePreview: this.disableWebPagePreview.checked, + global: this.global.checked, + parseMode: this.parseMode.checked, + stateChangesOnly: this.stateChangesOnly.checked, + token: this.token.value, + url: this.url.value, + }; + + this.props.onSave(properties); + }, + + render() { + const {options} = this.props.config; + const {global, url, token} = options; + const chatID = options['chat-id']; + const disableNotification = options['chat-id']; + const disableWebPagePreview = options['disable-web-page-preview']; + const parseMode = options['parse-mode']; + const stateChangesOnly = options['state-changes-only']; + + return ( +
+

Telegram Alert

+
+
+
+
+

+ You can have alerts sent to Telegram by entering info below. +

+ +
+ + this.url = r} defaultValue={url || ''}> +
+ +
+ + this.token = r} defaultValue={token || ''}> + Note: a value of true indicates the Telegram token has been set +
+ +
+ + this.chatID = r} defaultValue={chatID || ''}> +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+
+
+ ); + }, +}); + +export default TelegramConfig;