WIP add test buttons to alert handler config sections

pull/2409/head
deniz kusefoglu 2018-01-02 17:33:11 -08:00
parent 98b3deb8fa
commit b9a14979e3
3 changed files with 39 additions and 7 deletions

View File

@ -2,7 +2,11 @@ import React, {Component, PropTypes} from 'react'
import _ from 'lodash' import _ from 'lodash'
import {Tab, Tabs, TabPanel, TabPanels, TabList} from 'shared/components/Tabs' import {Tab, Tabs, TabPanel, TabPanels, TabList} from 'shared/components/Tabs'
import {getKapacitorConfig, updateKapacitorConfigSection} from 'shared/apis' import {
getKapacitorConfig,
updateKapacitorConfigSection,
testAlertOutput,
} from 'shared/apis'
import { import {
AlertaConfig, AlertaConfig,
@ -88,6 +92,22 @@ class AlertTabs extends Component {
} }
} }
handleTestConfig = section => () => {
testAlertOutput(this.props.kapacitor, section, {})
.then(() => {
this.props.addFlashMessage({
type: 'success',
text: `Successfully relayed an alert to ${section}.`,
})
})
.catch(() => {
this.props.addFlashMessage({
type: 'error',
text: `There was an error relaying an alert to ${section}.`,
})
})
}
sanitizeProperties = (section, properties) => { sanitizeProperties = (section, properties) => {
const cleanProps = {...properties, enabled: true} const cleanProps = {...properties, enabled: true}
const {redacted} = this.getSection(this.state.configSections, section) const {redacted} = this.getSection(this.state.configSections, section)
@ -116,6 +136,7 @@ class AlertTabs extends Component {
<AlertaConfig <AlertaConfig
onSave={this.handleSaveConfig('alerta')} onSave={this.handleSaveConfig('alerta')}
config={this.getSection(configSections, 'alerta')} config={this.getSection(configSections, 'alerta')}
onTest={this.handleTestConfig('alerta')}
/>, />,
}, },
hipchat: { hipchat: {
@ -125,6 +146,7 @@ class AlertTabs extends Component {
<HipChatConfig <HipChatConfig
onSave={this.handleSaveConfig('hipchat')} onSave={this.handleSaveConfig('hipchat')}
config={this.getSection(configSections, 'hipchat')} config={this.getSection(configSections, 'hipchat')}
onTest={this.handleTestConfig('hipchat')}
/>, />,
}, },
opsgenie: { opsgenie: {
@ -134,6 +156,7 @@ class AlertTabs extends Component {
<OpsGenieConfig <OpsGenieConfig
onSave={this.handleSaveConfig('opsgenie')} onSave={this.handleSaveConfig('opsgenie')}
config={this.getSection(configSections, 'opsgenie')} config={this.getSection(configSections, 'opsgenie')}
onTest={this.handleTestConfig('opsgenie')}
/>, />,
}, },
pagerduty: { pagerduty: {
@ -143,6 +166,7 @@ class AlertTabs extends Component {
<PagerDutyConfig <PagerDutyConfig
onSave={this.handleSaveConfig('pagerduty')} onSave={this.handleSaveConfig('pagerduty')}
config={this.getSection(configSections, 'pagerduty')} config={this.getSection(configSections, 'pagerduty')}
onTest={this.handleTestConfig('pagerduty')}
/>, />,
}, },
pushover: { pushover: {
@ -152,6 +176,7 @@ class AlertTabs extends Component {
<PushoverConfig <PushoverConfig
onSave={this.handleSaveConfig('pushover')} onSave={this.handleSaveConfig('pushover')}
config={this.getSection(configSections, 'pushover')} config={this.getSection(configSections, 'pushover')}
onTest={this.handleTestConfig('pushover')}
/>, />,
}, },
sensu: { sensu: {
@ -161,6 +186,7 @@ class AlertTabs extends Component {
<SensuConfig <SensuConfig
onSave={this.handleSaveConfig('sensu')} onSave={this.handleSaveConfig('sensu')}
config={this.getSection(configSections, 'sensu')} config={this.getSection(configSections, 'sensu')}
onTest={this.handleTestConfig('sensu')}
/>, />,
}, },
slack: { slack: {
@ -170,6 +196,7 @@ class AlertTabs extends Component {
<SlackConfig <SlackConfig
onSave={this.handleSaveConfig('slack')} onSave={this.handleSaveConfig('slack')}
config={this.getSection(configSections, 'slack')} config={this.getSection(configSections, 'slack')}
onTest={this.handleTestConfig('slack')}
/>, />,
}, },
smtp: { smtp: {
@ -179,6 +206,7 @@ class AlertTabs extends Component {
<SMTPConfig <SMTPConfig
onSave={this.handleSaveConfig('smtp')} onSave={this.handleSaveConfig('smtp')}
config={this.getSection(configSections, 'smtp')} config={this.getSection(configSections, 'smtp')}
onTest={this.handleTestConfig('smtp')}
/>, />,
}, },
talk: { talk: {
@ -188,6 +216,7 @@ class AlertTabs extends Component {
<TalkConfig <TalkConfig
onSave={this.handleSaveConfig('talk')} onSave={this.handleSaveConfig('talk')}
config={this.getSection(configSections, 'talk')} config={this.getSection(configSections, 'talk')}
onTest={this.handleTestConfig('talk')}
/>, />,
}, },
telegram: { telegram: {
@ -197,6 +226,7 @@ class AlertTabs extends Component {
<TelegramConfig <TelegramConfig
onSave={this.handleSaveConfig('telegram')} onSave={this.handleSaveConfig('telegram')}
config={this.getSection(configSections, 'telegram')} config={this.getSection(configSections, 'telegram')}
onTest={this.handleTestConfig('telegram')}
/>, />,
}, },
victorops: { victorops: {
@ -206,6 +236,7 @@ class AlertTabs extends Component {
<VictorOpsConfig <VictorOpsConfig
onSave={this.handleSaveConfig('victorops')} onSave={this.handleSaveConfig('victorops')}
config={this.getSection(configSections, 'victorops')} config={this.getSection(configSections, 'victorops')}
onTest={this.handleTestConfig('victorops')}
/>, />,
}, },
} }

View File

@ -66,6 +66,11 @@ class SlackConfig extends Component {
Update Slack Config Update Slack Config
</button> </button>
</div> </div>
<br />
<br />
<div className="col-xs-12 text-center" onClick={this.props.onTest}>
Test Slack Config
</div>
</form> </form>
) )
} }
@ -81,6 +86,7 @@ SlackConfig.propTypes = {
}).isRequired, }).isRequired,
}).isRequired, }).isRequired,
onSave: func.isRequired, onSave: func.isRequired,
onTest: func,
} }
export default SlackConfig export default SlackConfig

View File

@ -159,12 +159,7 @@ export function testAlertOutput(kapacitor, outputName, properties) {
'/kapacitor/v1/service-tests' '/kapacitor/v1/service-tests'
).then(({data: {services}}) => { ).then(({data: {services}}) => {
const service = services.find(s => s.name === outputName) const service = services.find(s => s.name === outputName)
return kapacitorProxy( return kapacitorProxy(kapacitor, 'POST', service.link.href, {})
kapacitor,
'POST',
service.link.href,
Object.assign({}, service.options, properties)
)
}) })
} }