From 89d55b5ff6a2ae31f9264acaeaf0a6433794746e Mon Sep 17 00:00:00 2001 From: Pavel Zavora Date: Wed, 12 May 2021 08:04:46 +0200 Subject: [PATCH] feat(ui): add Zenoss configuration --- ui/src/kapacitor/components/AlertTabs.tsx | 10 + .../components/config/ZenossConfig.tsx | 280 ++++++++++++++++++ ui/src/kapacitor/components/config/index.js | 2 + ui/src/kapacitor/constants/index.ts | 3 + ui/src/types/kapacitor.ts | 18 ++ 5 files changed, 313 insertions(+) create mode 100644 ui/src/kapacitor/components/config/ZenossConfig.tsx diff --git a/ui/src/kapacitor/components/AlertTabs.tsx b/ui/src/kapacitor/components/AlertTabs.tsx index 46ff5a9c8..fe1c8d625 100644 --- a/ui/src/kapacitor/components/AlertTabs.tsx +++ b/ui/src/kapacitor/components/AlertTabs.tsx @@ -35,6 +35,7 @@ import { ServiceNowConfig, BigPandaConfig, TeamsConfig, + ZenossConfig, } from './config' import { @@ -417,6 +418,15 @@ class AlertTabs extends PureComponent { enabled={this.getConfigEnabled(configSections, AlertTypes.teams)} /> ) + case AlertTypes.zenoss: + return ( + + ) } } diff --git a/ui/src/kapacitor/components/config/ZenossConfig.tsx b/ui/src/kapacitor/components/config/ZenossConfig.tsx new file mode 100644 index 000000000..c8f46b4d5 --- /dev/null +++ b/ui/src/kapacitor/components/config/ZenossConfig.tsx @@ -0,0 +1,280 @@ +import _ from 'lodash' +import React, {PureComponent, ChangeEvent} from 'react' +import {ErrorHandling} from 'src/shared/decorators/errors' +import {ZenossProperties} from 'src/types/kapacitor' +import RedactedInput from './RedactedInput' + +interface Config { + options: { + url: string + username: string + password: boolean + action: string + method: string + type: string + tid: number + 'severity-map': { + ok: string + info: string + warning: string + critical: string + } + enabled: boolean + } +} + +interface Props { + config: Config + onSave: (properties: ZenossProperties) => Promise + onTest: (event: React.MouseEvent) => void + enabled: boolean +} + +interface State { + testEnabled: boolean + enabled: boolean +} + +@ErrorHandling +class ZenossConfig extends PureComponent { + private url: HTMLInputElement + private username: HTMLInputElement + private password: HTMLInputElement + private action: HTMLInputElement + private method: HTMLInputElement + private type: HTMLInputElement + private tid: HTMLInputElement + private ok: HTMLInputElement + private info: HTMLInputElement + private warning: HTMLInputElement + private critical: HTMLInputElement + + constructor(props) { + super(props) + this.state = { + testEnabled: this.props.enabled, + enabled: _.get(this.props, 'config.options.enabled', false), + } + } + + public render() { + const { + url, + username, + password, + action, + method, + type, + tid, + 'severity-map': {ok, info, warning, critical}, + } = this.props.config.options + const {testEnabled, enabled} = this.state + + return ( +
+
+ + (this.url = r)} + defaultValue={url || ''} + onChange={this.disableTest} + /> +
+
+ + (this.username = r)} + defaultValue={username || ''} + onChange={this.disableTest} + /> +
+
+ + +
+
+ + (this.action = r)} + defaultValue={action || ''} + onChange={this.disableTest} + /> +
+
+ + (this.method = r)} + defaultValue={method || ''} + onChange={this.disableTest} + /> +
+
+ + (this.type = r)} + defaultValue={type || ''} + onChange={this.disableTest} + /> +
+
+ + (this.tid = r)} + defaultValue={tid || ''} + onChange={this.disableTest} + /> +
+
+ +
+
+ + (this.ok = r)} + defaultValue={ok || ''} + onChange={this.disableTest} + /> +
+
+ + (this.info = r)} + defaultValue={info || ''} + onChange={this.disableTest} + /> +
+
+ + (this.warning = r)} + defaultValue={warning || ''} + onChange={this.disableTest} + /> +
+
+ + (this.critical = r)} + defaultValue={critical || ''} + onChange={this.disableTest} + /> +
+
+
+ +
+
+ + +
+
+ +
+ + +
+
+ ) + } + + private handlePasswordRef = (r: HTMLInputElement) => (this.password = r) + + private handleEnabledChange = (e: ChangeEvent) => { + this.setState({enabled: e.target.checked}) + this.disableTest() + } + + private handleSubmit = async e => { + e.preventDefault() + let tid: number + try { + tid = parseInt(this.tid.value, 10) + } catch (nfe) { + console.error(nfe) + tid = 1 + } + + const properties: ZenossProperties = { + url: this.url.value, + username: this.username.value, + password: this.password.value, + action: this.action.value, + method: this.method.value, + type: this.type.value, + tid, + 'severity-map': { + ok: this.ok.value, + info: this.info.value, + warning: this.warning.value, + critical: this.critical.value, + }, + enabled: this.state.enabled, + } + + const success = await this.props.onSave(properties) + if (success) { + this.setState({testEnabled: true}) + } + } + + private disableTest = () => { + this.setState({testEnabled: false}) + } +} + +export default ZenossConfig diff --git a/ui/src/kapacitor/components/config/index.js b/ui/src/kapacitor/components/config/index.js index f551c0b37..17e62292b 100644 --- a/ui/src/kapacitor/components/config/index.js +++ b/ui/src/kapacitor/components/config/index.js @@ -15,6 +15,7 @@ import KafkaConfigs from './KafkaConfigs' import ServiceNowConfig from './ServiceNowConfig' import BigPandaConfig from './BigPandaConfig' import TeamsConfig from './TeamsConfig' +import ZenossConfig from './ZenossConfig' export { AlertaConfig, @@ -34,4 +35,5 @@ export { ServiceNowConfig, BigPandaConfig, TeamsConfig, + ZenossConfig, } diff --git a/ui/src/kapacitor/constants/index.ts b/ui/src/kapacitor/constants/index.ts index c4469a13e..739115085 100644 --- a/ui/src/kapacitor/constants/index.ts +++ b/ui/src/kapacitor/constants/index.ts @@ -34,6 +34,7 @@ export enum AlertTypes { servicenow = 'servicenow', bigpanda = 'bigpanda', teams = 'teams', + zenoss = 'zenoss', } export enum AlertDisplayText { @@ -53,6 +54,7 @@ export enum AlertDisplayText { servicenow = 'ServiceNow', bigpanda = 'BigPanda', teams = 'Teams', + zenoss = 'Zenoss', } export const SupportedServices: string[] = [ @@ -72,6 +74,7 @@ export const SupportedServices: string[] = [ 'teams', 'telegram', 'victorops', + 'zenoss', ] export const defaultRuleConfigs = { diff --git a/ui/src/types/kapacitor.ts b/ui/src/types/kapacitor.ts index d4b9c7956..30546b934 100644 --- a/ui/src/types/kapacitor.ts +++ b/ui/src/types/kapacitor.ts @@ -455,6 +455,23 @@ export interface TeamsProperties { enabled: boolean } +export interface ZenossProperties { + url: string + username: string + password: string + action: string + method: string + type: string + tid: number + 'severity-map': { + ok: string + info: string + warning: string + critical: string + } + enabled: boolean +} + export type ServiceProperties = | AlertaProperties | KafkaProperties @@ -471,6 +488,7 @@ export type ServiceProperties = | ServiceNowProperties | BigPandaProperties | TeamsProperties + | ZenossProperties export type SpecificConfigOptions = Partial