Skip to content

Commit

Permalink
feat(kapacitor): add option to set noRecoveries on alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
mmdoogie authored and sranka committed Mar 15, 2022
1 parent 252f8c4 commit 77a75a2
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions kapacitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions kapacitor/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func Trigger(rule chronograf.AlertRule) (string, error) {
`
}

if rule.AlertNodes.IsNoRecoveries {
trigger += `
.noRecoveries()
`
}

trigger += AllAlerts

if rule.Details != "" {
Expand Down
8 changes: 8 additions & 0 deletions ui/src/kapacitor/actions/view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
22 changes: 20 additions & 2 deletions ui/src/kapacitor/components/RuleHandlers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface HandlerWithText extends Handler {
interface RuleActions {
updateAlertNodes: (id: string, handlersOnThisAlert: Handler[]) => void
updateMessage: (id: string, e: MouseEvent<HTMLInputElement>) => void
updateNoRecoveries: (id: string, noRecoveries: boolean) => void
updateDetails: () => void
}

Expand Down Expand Up @@ -121,8 +122,8 @@ class RuleHandlers extends PureComponent<Props, State> {
: '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
Expand All @@ -132,6 +133,18 @@ class RuleHandlers extends PureComponent<Props, State> {
<div className="rule-section">
<h3 className="rule-section--heading">Alert Handlers</h3>
<div className="rule-section--body">
<div className="rule-section--row rule-section--row-first rule-section--border-bottom">
<div className="form-control-static handler-checkbox">
<input
name="noRecoveries"
id="noRecoveries"
type="checkbox"
defaultChecked={rule.alertNodes.noRecoveries}
onClick={this.handleNoRecoveries}
/>
<label htmlFor="noRecoveries">Don't send alert on condition recovery</label>
</div>
</div>
<div className={ruleSectionClassName}>
<p>Send this Alert to:</p>
<Dropdown
Expand Down Expand Up @@ -166,6 +179,11 @@ class RuleHandlers extends PureComponent<Props, State> {
)
}

private handleNoRecoveries = (e) {
const {ruleActions, rule} = this.props
ruleActions.updateNoRecoveries(rule.id, e.target.checked)
}

private handleChooseHandler = (ep: HandlerWithText): (() => void) => () => {
this.setState({selectedHandler: ep})
}
Expand Down
9 changes: 9 additions & 0 deletions ui/src/kapacitor/reducers/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
1 change: 1 addition & 0 deletions ui/src/types/kapacitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down

0 comments on commit 77a75a2

Please sign in to comment.