Skip to content

Commit 2ddec80

Browse files
committed
feat(alerting): Add RESULT_CONDITIONS in custom alert to have more information on an alert while using custom alerting module
1 parent 04692d1 commit 2ddec80

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,8 @@ Furthermore, you may use the following placeholders in the body (`alerting.custo
15551555
- `[ENDPOINT_GROUP]` (resolved from `endpoints[].group`)
15561556
- `[ENDPOINT_URL]` (resolved from `endpoints[].url`)
15571557
- `[RESULT_ERRORS]` (resolved from the health evaluation of a given health check)
1558-
1558+
- `[RESULT_CONDITIONS]` (condition results from the health evaluation of a given health check)
1559+
-
15591560
If you have an alert using the `custom` provider with `send-on-resolved` set to `true`, you can use the
15601561
`[ALERT_TRIGGERED_OR_RESOLVED]` placeholder to differentiate the notifications.
15611562
The aforementioned placeholder will be replaced by `TRIGGERED` or `RESOLVED` accordingly, though it can be modified

alerting/provider/custom/custom.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ func (provider *AlertProvider) buildHTTPRequest(cfg *Config, ep *endpoint.Endpoi
111111
resultErrors := strings.ReplaceAll(strings.Join(result.Errors, ","), "\"", "\\\"")
112112
body = strings.ReplaceAll(body, "[RESULT_ERRORS]", resultErrors)
113113
url = strings.ReplaceAll(url, "[RESULT_ERRORS]", resultErrors)
114+
115+
var formattedConditionResults string
116+
if len(result.ConditionResults) > 0 {
117+
for index, conditionResult := range result.ConditionResults {
118+
var prefix string
119+
if conditionResult.Success {
120+
prefix = "✅"
121+
} else {
122+
prefix = "❌"
123+
}
124+
formattedConditionResults += fmt.Sprintf("%s - `%s`", prefix, conditionResult.Condition)
125+
if index < len(result.ConditionResults)-1 {
126+
formattedConditionResults += ", "
127+
}
128+
}
129+
}
130+
131+
body = strings.ReplaceAll(body, "[RESULT_CONDITIONS]", formattedConditionResults)
132+
url = strings.ReplaceAll(url, "[RESULT_CONDITIONS]", formattedConditionResults)
133+
114134
if resolved {
115135
body = strings.ReplaceAll(body, "[ALERT_TRIGGERED_OR_RESOLVED]", provider.GetAlertStatePlaceholderValue(cfg, true))
116136
url = strings.ReplaceAll(url, "[ALERT_TRIGGERED_OR_RESOLVED]", provider.GetAlertStatePlaceholderValue(cfg, true))

0 commit comments

Comments
 (0)