From 77a75a2415422ad7580e6d40ba9a7ffcaea0729f Mon Sep 17 00:00:00 2001 From: mmdoogie <24367033+mmdoogie@users.noreply.github.com> Date: Tue, 8 Feb 2022 22:24:59 -0600 Subject: [PATCH] feat(kapacitor): add option to set noRecoveries on alerts --- kapacitor.go | 1 + kapacitor/triggers.go | 6 ++++++ ui/src/kapacitor/actions/view/index.js | 8 +++++++ ui/src/kapacitor/components/RuleHandlers.tsx | 22 ++++++++++++++++++-- ui/src/kapacitor/reducers/rules.js | 9 ++++++++ ui/src/types/kapacitor.ts | 1 + 6 files changed, 45 insertions(+), 2 deletions(-) diff --git a/kapacitor.go b/kapacitor.go index 019a884ee..96707e6a8 100644 --- a/kapacitor.go +++ b/kapacitor.go @@ -5,6 +5,7 @@ import "encoding/json" // AlertNodes defines all possible kapacitor interactions with an alert. type AlertNodes struct { IsStateChangesOnly bool `json:"stateChangesOnly"` // IsStateChangesOnly will only send alerts on state changes. + IsNoRecoveries bool `json:"noRecoveries"` // IsNoRecoveries will not send alerts when returning to OK state from other states. UseFlapping bool `json:"useFlapping"` // UseFlapping enables flapping detection. Flapping occurs when a service or host changes state too frequently, resulting in a storm of problem and recovery notification Posts []*Post `json:"post"` // HTTPPost will post the JSON alert data to the specified URLs. TCPs []*TCP `json:"tcp"` // TCP will send the JSON alert data to the specified endpoint via TCP. diff --git a/kapacitor/triggers.go b/kapacitor/triggers.go index 2c87bf1ff..18a15558c 100644 --- a/kapacitor/triggers.go +++ b/kapacitor/triggers.go @@ -119,6 +119,12 @@ func Trigger(rule chronograf.AlertRule) (string, error) { ` } + if rule.AlertNodes.IsNoRecoveries { + trigger += ` + .noRecoveries() + ` + } + trigger += AllAlerts if rule.Details != "" { diff --git a/ui/src/kapacitor/actions/view/index.js b/ui/src/kapacitor/actions/view/index.js index f3baff69e..05c9da3c8 100644 --- a/ui/src/kapacitor/actions/view/index.js +++ b/ui/src/kapacitor/actions/view/index.js @@ -145,6 +145,14 @@ export const updateRuleValues = (ruleID, trigger, values) => ({ }, }) +export const updateNoRecoveries = (ruleID, noRecoveries) => ({ + type: 'UPDATE_RULE_NORECOVERIES', + payload: { + ruleID, + noRecoveries, + }, +}) + export const updateMessage = (ruleID, message) => ({ type: 'UPDATE_RULE_MESSAGE', payload: { diff --git a/ui/src/kapacitor/components/RuleHandlers.tsx b/ui/src/kapacitor/components/RuleHandlers.tsx index a562e9083..e09b52199 100644 --- a/ui/src/kapacitor/components/RuleHandlers.tsx +++ b/ui/src/kapacitor/components/RuleHandlers.tsx @@ -19,6 +19,7 @@ interface HandlerWithText extends Handler { interface RuleActions { updateAlertNodes: (id: string, handlersOnThisAlert: Handler[]) => void updateMessage: (id: string, e: MouseEvent) => void + updateNoRecoveries: (id: string, noRecoveries: boolean) => void updateDetails: () => void } @@ -121,8 +122,8 @@ class RuleHandlers extends PureComponent { : 'Add a Handler' const ruleSectionClassName = handlersOnThisAlert.length - ? 'rule-section--row rule-section--row-first rule-section--border-bottom' - : 'rule-section--row rule-section--row-first rule-section--row-last' + ? 'rule-section--row rule-section--border-bottom' + : 'rule-section--row rule-section--row-last' const selectedHandlerWithText: HandlerWithText = this.addNicknameText( selectedHandler @@ -132,6 +133,18 @@ class RuleHandlers extends PureComponent {

Alert Handlers

+
+
+ + +
+

Send this Alert to:

{ ) } + private handleNoRecoveries = (e) { + const {ruleActions, rule} = this.props + ruleActions.updateNoRecoveries(rule.id, e.target.checked) + } + private handleChooseHandler = (ep: HandlerWithText): (() => void) => () => { this.setState({selectedHandler: ep}) } diff --git a/ui/src/kapacitor/reducers/rules.js b/ui/src/kapacitor/reducers/rules.js index 15f627f4e..f72b6d7df 100644 --- a/ui/src/kapacitor/reducers/rules.js +++ b/ui/src/kapacitor/reducers/rules.js @@ -76,6 +76,15 @@ export default function rules(state = {}, action) { }) } + case 'UPDATE_RULE_NORECOVERIES': { + const {ruleID, noRecoveries} = action.payload + return Object.assign({}, state, { + [ruleID]: Object.assign({}, state[ruleID], { + alertNodes: {...state[ruleID].alertNodes, noRecoveries: noRecoveries} + }), + }) + } + case 'UPDATE_RULE_ALERT_NODES': { const {ruleID, alerts} = action.payload const alertNodesByType = {} diff --git a/ui/src/types/kapacitor.ts b/ui/src/types/kapacitor.ts index 0acc5855c..48f445991 100644 --- a/ui/src/types/kapacitor.ts +++ b/ui/src/types/kapacitor.ts @@ -122,6 +122,7 @@ type TICKScript = string // AlertNodes defines all possible kapacitor interactions with an alert. interface AlertNodes { stateChangesOnly: boolean + noRecoveries: boolean useFlapping: boolean post: Post[] tcp: TCP[]