Use async-await syntax to call test-config
parent
39757d86d3
commit
2c32772387
|
@ -92,20 +92,19 @@ class AlertTabs extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
handleTestConfig = section => () => {
|
||||
testAlertOutput(this.props.kapacitor, section, {})
|
||||
.then(() => {
|
||||
this.props.addFlashMessage({
|
||||
type: 'success',
|
||||
text: `Successfully relayed an alert to ${section}.`,
|
||||
})
|
||||
handleTestConfig = section => async () => {
|
||||
try {
|
||||
await testAlertOutput(this.props.kapacitor, section, {})
|
||||
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}.`,
|
||||
})
|
||||
} catch (error) {
|
||||
this.props.addFlashMessage({
|
||||
type: 'error',
|
||||
text: `There was an error relaying an alert to ${section}.`,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
sanitizeProperties = (section, properties) => {
|
||||
|
|
|
@ -152,15 +152,18 @@ export function updateKapacitorConfigSection(kapacitor, section, properties) {
|
|||
})
|
||||
}
|
||||
|
||||
export function testAlertOutput(kapacitor, outputName, properties) {
|
||||
return kapacitorProxy(
|
||||
kapacitor,
|
||||
'GET',
|
||||
'/kapacitor/v1/service-tests'
|
||||
).then(({data: {services}}) => {
|
||||
export const testAlertOutput = async (kapacitor, outputName) => {
|
||||
try {
|
||||
const {data: {services}} = await kapacitorProxy(
|
||||
kapacitor,
|
||||
'GET',
|
||||
'/kapacitor/v1/service-tests'
|
||||
)
|
||||
const service = services.find(s => s.name === outputName)
|
||||
return kapacitorProxy(kapacitor, 'POST', service.link.href, {})
|
||||
})
|
||||
} catch (error) {
|
||||
// empty
|
||||
}
|
||||
}
|
||||
|
||||
export function createKapacitorTask(kapacitor, id, type, dbrps, script) {
|
||||
|
|
Loading…
Reference in New Issue