From 807fc2f1ebd1e831250912add5a1367c21d1c108 Mon Sep 17 00:00:00 2001 From: Iris Scholten Date: Thu, 10 May 2018 13:54:21 -0700 Subject: [PATCH] Update parseHandlersFromConfig to include config sections with multiple configs --- .../components/config/SlackConfig.tsx | 11 +++-- ui/src/kapacitor/constants/index.js | 2 +- .../shared/parsing/parseHandlersFromConfig.js | 43 +++++++++++++++---- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/ui/src/kapacitor/components/config/SlackConfig.tsx b/ui/src/kapacitor/components/config/SlackConfig.tsx index ab1f3ccd67..d3b33b3f1c 100644 --- a/ui/src/kapacitor/components/config/SlackConfig.tsx +++ b/ui/src/kapacitor/components/config/SlackConfig.tsx @@ -62,6 +62,7 @@ class SlackConfig extends PureComponent { const workspaceID = workspace || 'default' const isNickNameEnabled = isNewConfig && !testEnabled + const isDefaultConfig = workspace === '' return (
@@ -143,10 +144,12 @@ class SlackConfig extends PureComponent { Send Test Alert - + {!isDefaultConfig && ( + + )}

diff --git a/ui/src/kapacitor/constants/index.js b/ui/src/kapacitor/constants/index.js index a90349a51d..2174bacc7d 100644 --- a/ui/src/kapacitor/constants/index.js +++ b/ui/src/kapacitor/constants/index.js @@ -121,7 +121,7 @@ export const ALERTS_FROM_CONFIG = { pagerDuty2: ['routing-key'], // routing-key = bool pushover: ['token', 'user-key'], // token = bool, user-key = bool sensu: ['addr', 'source'], - slack: ['url', 'channel'], // url = bool + slack: ['url', 'channel', 'workspace'], // url = bool email: ['from', 'host', 'password', 'port', 'username'], // password = bool talk: ['url', 'author_name'], // url = bool telegram: [ diff --git a/ui/src/shared/parsing/parseHandlersFromConfig.js b/ui/src/shared/parsing/parseHandlersFromConfig.js index cb72415e46..1e08831530 100644 --- a/ui/src/shared/parsing/parseHandlersFromConfig.js +++ b/ui/src/shared/parsing/parseHandlersFromConfig.js @@ -5,19 +5,46 @@ import { MAP_KEYS_FROM_CONFIG, } from 'src/kapacitor/constants' +const getElementOptions = section => { + const elements = _.get(section, 'elements', []) + + if (elements.length === 0) { + return {} + } + + return _.map(elements, element => _.get(element, 'options', {})) +} + const parseHandlersFromConfig = config => { const { data: {sections}, } = config - const allHandlers = _.map(sections, (v, k) => { - const fromConfig = _.get(v, ['elements', '0', 'options'], {}) - return { - // fill type with handler names in rule - type: _.get(MAP_KEYS_FROM_CONFIG, k, k), - ...fromConfig, - } - }) + const multiConfigSections = {} + + const allHandlers = _.reduce( + sections, + (acc, v, k) => { + const options = getElementOptions(v) + const type = _.get(MAP_KEYS_FROM_CONFIG, k, k) + + // keep track of sections with multiple configs + const numberOfThisConfigType = _.get(options, 'length', 0) + if (numberOfThisConfigType > 1) { + multiConfigSections[type] = true + } + + _.forEach(options, option => { + acc.push({ + // fill type with handler names in rule + type, + ...option, + }) + }) + return acc + }, + [] + ) // map handler names from config to handler names in rule const mappedHandlers = _.mapKeys(allHandlers, (v, k) => {