Update parseHandlersFromConfig to include config sections with multiple configs
parent
4226bca0b9
commit
807fc2f1eb
|
@ -62,6 +62,7 @@ class SlackConfig extends PureComponent<Props, State> {
|
|||
const workspaceID = workspace || 'default'
|
||||
|
||||
const isNickNameEnabled = isNewConfig && !testEnabled
|
||||
const isDefaultConfig = workspace === ''
|
||||
|
||||
return (
|
||||
<form onSubmit={this.handleSubmit}>
|
||||
|
@ -143,10 +144,12 @@ class SlackConfig extends PureComponent<Props, State> {
|
|||
<span className="icon pulse-c" />
|
||||
Send Test Alert
|
||||
</button>
|
||||
<button className="btn btn-danger" onClick={this.handleDelete}>
|
||||
<span className="icon trash" />
|
||||
Delete
|
||||
</button>
|
||||
{!isDefaultConfig && (
|
||||
<button className="btn btn-danger" onClick={this.handleDelete}>
|
||||
<span className="icon trash" />
|
||||
Delete
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<br />
|
||||
<br />
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue