From ec0ba3ba8c0713522adea0613ef1f3a4d066002b Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Wed, 26 Oct 2016 16:25:36 -0700 Subject: [PATCH] Add Alerta and VictorOps kapacitor configs to UI --- ui/src/kapacitor/components/AlertOutputs.js | 22 ++++- ui/src/kapacitor/components/AlertaConfig.js | 78 ++++++++++++++++++ ui/src/kapacitor/components/SlackConfig.js | 4 +- .../kapacitor/components/VictoropsConfig.js | 81 +++++++++++++++++++ 4 files changed, 180 insertions(+), 5 deletions(-) create mode 100644 ui/src/kapacitor/components/AlertaConfig.js create mode 100644 ui/src/kapacitor/components/VictoropsConfig.js diff --git a/ui/src/kapacitor/components/AlertOutputs.js b/ui/src/kapacitor/components/AlertOutputs.js index a68202c2d..06afbc31b 100644 --- a/ui/src/kapacitor/components/AlertOutputs.js +++ b/ui/src/kapacitor/components/AlertOutputs.js @@ -3,6 +3,8 @@ import _ from 'lodash'; import {getKapacitorConfig, updateKapacitorConfigSection, testAlertOutput} from 'shared/apis'; import SlackConfig from './SlackConfig'; import SMTPConfig from './SMTPConfig'; +import VictoropsConfig from './VictoropsConfig'; +import AlertaConfig from './AlertaConfig'; const AlertOutputs = React.createClass({ propTypes: { @@ -19,9 +21,10 @@ const AlertOutputs = React.createClass({ getInitialState() { return { - selectedEndpoint: 'smtp', + selectedEndpoint: 'alerta', smtpConfig: null, slackConfig: null, + alertaConfig: null, }; }, @@ -32,8 +35,10 @@ const AlertOutputs = React.createClass({ refreshKapacitorConfig() { getKapacitorConfig(this.props.kapacitor).then(({data: {sections}}) => { this.setState({ + alertaConfig: _.get(sections, ['alerta', 'elements', '0'], null), slackConfig: _.get(sections, ['slack', 'elements', '0'], null), smtpConfig: _.get(sections, ['smtp', 'elements', '0'], null), + victoropsConfig: _.get(sections, ['victorops', 'elements', '0'], null), }); }); }, @@ -79,8 +84,10 @@ const AlertOutputs = React.createClass({
@@ -96,13 +103,22 @@ const AlertOutputs = React.createClass({ this.handleSaveConfig(endpoint, properties); }; + if (endpoint === 'alerta' && this.state.alertaConfig) { + return ; + } + if (endpoint === 'smtp' && this.state.smtpConfig) { return ; } + if (endpoint === 'slack' && this.state.slackConfig) { return ; } + if (endpoint === 'victorops' && this.state.victoropsConfig) { + return ; + } + return
This endpoint is not supported yet!
; }, }); diff --git a/ui/src/kapacitor/components/AlertaConfig.js b/ui/src/kapacitor/components/AlertaConfig.js new file mode 100644 index 000000000..35039c112 --- /dev/null +++ b/ui/src/kapacitor/components/AlertaConfig.js @@ -0,0 +1,78 @@ +import React, {PropTypes} from 'react'; + +const AlertaConfig = React.createClass({ + propTypes: { + config: PropTypes.shape({ + options: PropTypes.shape({ + environment: PropTypes.string, + origin: PropTypes.string, + token: PropTypes.bool, + url: PropTypes.string, + }).isRequired, + }).isRequired, + onSave: PropTypes.func.isRequired, + }, + + handleSaveAlert(e) { + e.preventDefault(); + + const properties = { + environment: this.port.value, + origin: this.from.value, + token: this.username.value, + url: this.password.value, + }; + + this.props.onSave(properties); + }, + + render() { + const {environment, origin, token, url} = this.props.config.options; + + return ( +
+

Alerta alerts

+
+
+
+
+

+ Have alerts sent to Alerta +

+ +
+ + this.environment = r} defaultValue={environment || ''}> +
+ +
+ + this.origin = r} defaultValue={origin || ''}> +
+ +
+ + this.token = r} defaultValue={token || ''}> + Note: a value of true indicates the Alerta Token has been set +
+ +
+ + this.url = r} defaultValue={url || ''}> +
+
+
+ +
+
+
+ +
+
+
+
+ ); + }, +}); + +export default AlertaConfig; diff --git a/ui/src/kapacitor/components/SlackConfig.js b/ui/src/kapacitor/components/SlackConfig.js index ae84620d5..b507978ac 100644 --- a/ui/src/kapacitor/components/SlackConfig.js +++ b/ui/src/kapacitor/components/SlackConfig.js @@ -51,8 +51,8 @@ const SlackConfig = React.createClass({
- this.url = r} defaultValue={`${url}`}> - Note: a value of true or false indicates whether or not a slack channel has been set + this.url = r} defaultValue={url || ''}> + Note: a value of true indicates that the Slack channel has been set
diff --git a/ui/src/kapacitor/components/VictoropsConfig.js b/ui/src/kapacitor/components/VictoropsConfig.js new file mode 100644 index 000000000..2267bf8c3 --- /dev/null +++ b/ui/src/kapacitor/components/VictoropsConfig.js @@ -0,0 +1,81 @@ +import React, {PropTypes} from 'react'; + +const VictoropsConfig = React.createClass({ + propTypes: { + config: PropTypes.shape({ + options: PropTypes.shape({ + 'api-key': PropTypes.bool, + 'routing-key': PropTypes.string, + global: PropTypes.bool, + url: PropTypes.string, + }).isRequired, + }).isRequired, + onSave: PropTypes.func.isRequired, + }, + + handleSaveAlert(e) { + e.preventDefault(); + + const properties = { + 'api-key': this.apiKey.value, + 'routing-key': this.routingKey.value, + url: this.url.value, + global: this.global.checked, + }; + + this.props.onSave(properties); + }, + + render() { + const {options} = this.props.config; + const apiKey = options['api-key']; + const routingKey = options['routing-key']; + const {url, global} = options; + + return ( +
+

SMTP Alert

+
+
+
+
+

+ Have alerts sent to VictorOps +

+ +
+ + this.apiKey = r} defaultValue={apiKey || ''}> + Note: a value of true indicates the VictorOps API key has been set +
+ +
+ + this.routingKey = r} defaultValue={routingKey || ''}> +
+ +
+ + this.url = r} defaultValue={url || ''}> +
+ +
+ this.global = r} defaultChecked={global}/> + +
+
+
+ +
+
+
+ +
+
+
+
+ ); + }, +}); + +export default VictoropsConfig;