Update parseHandlersFromConfig to include config sections with multiple configs
parent
dbd32a9952
commit
64f9ec97b7
|
@ -62,6 +62,7 @@ class SlackConfig extends PureComponent<Props, State> {
|
||||||
const workspaceID = workspace || 'default'
|
const workspaceID = workspace || 'default'
|
||||||
|
|
||||||
const isNickNameEnabled = isNewConfig && !testEnabled
|
const isNickNameEnabled = isNewConfig && !testEnabled
|
||||||
|
const isDefaultConfig = workspace === ''
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={this.handleSubmit}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
|
@ -143,10 +144,12 @@ class SlackConfig extends PureComponent<Props, State> {
|
||||||
<span className="icon pulse-c" />
|
<span className="icon pulse-c" />
|
||||||
Send Test Alert
|
Send Test Alert
|
||||||
</button>
|
</button>
|
||||||
|
{!isDefaultConfig && (
|
||||||
<button className="btn btn-danger" onClick={this.handleDelete}>
|
<button className="btn btn-danger" onClick={this.handleDelete}>
|
||||||
<span className="icon trash" />
|
<span className="icon trash" />
|
||||||
Delete
|
Delete
|
||||||
</button>
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -121,7 +121,7 @@ export const ALERTS_FROM_CONFIG = {
|
||||||
pagerDuty2: ['routing-key'], // routing-key = bool
|
pagerDuty2: ['routing-key'], // routing-key = bool
|
||||||
pushover: ['token', 'user-key'], // token = bool, user-key = bool
|
pushover: ['token', 'user-key'], // token = bool, user-key = bool
|
||||||
sensu: ['addr', 'source'],
|
sensu: ['addr', 'source'],
|
||||||
slack: ['url', 'channel'], // url = bool
|
slack: ['url', 'channel', 'workspace'], // url = bool
|
||||||
email: ['from', 'host', 'password', 'port', 'username'], // password = bool
|
email: ['from', 'host', 'password', 'port', 'username'], // password = bool
|
||||||
talk: ['url', 'author_name'], // url = bool
|
talk: ['url', 'author_name'], // url = bool
|
||||||
telegram: [
|
telegram: [
|
||||||
|
|
|
@ -5,19 +5,46 @@ import {
|
||||||
MAP_KEYS_FROM_CONFIG,
|
MAP_KEYS_FROM_CONFIG,
|
||||||
} from 'src/kapacitor/constants'
|
} 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 parseHandlersFromConfig = config => {
|
||||||
const {
|
const {
|
||||||
data: {sections},
|
data: {sections},
|
||||||
} = config
|
} = config
|
||||||
|
|
||||||
const allHandlers = _.map(sections, (v, k) => {
|
const multiConfigSections = {}
|
||||||
const fromConfig = _.get(v, ['elements', '0', 'options'], {})
|
|
||||||
return {
|
const allHandlers = _.reduce(
|
||||||
// fill type with handler names in rule
|
sections,
|
||||||
type: _.get(MAP_KEYS_FROM_CONFIG, k, k),
|
(acc, v, k) => {
|
||||||
...fromConfig,
|
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
|
// map handler names from config to handler names in rule
|
||||||
const mappedHandlers = _.mapKeys(allHandlers, (v, k) => {
|
const mappedHandlers = _.mapKeys(allHandlers, (v, k) => {
|
||||||
|
|
Loading…
Reference in New Issue