From 8fbfba2163cab9dd57fb2101865eca4b3e6e2174 Mon Sep 17 00:00:00 2001 From: lolgopher <34984529+lolgopher@users.noreply.github.com> Date: Fri, 22 Sep 2023 10:36:42 +0900 Subject: [PATCH] fix(alerting): Set correct email subject to resolved alert (#572) fix(alerting): Set correct email subject to resolved alert (#566) --- alerting/provider/email/email.go | 5 +++-- alerting/provider/email/email_test.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/alerting/provider/email/email.go b/alerting/provider/email/email.go index 5d250a31..e16f8e37 100644 --- a/alerting/provider/email/email.go +++ b/alerting/provider/email/email.go @@ -67,11 +67,12 @@ func (provider *AlertProvider) Send(endpoint *core.Endpoint, alert *alert.Alert, // buildMessageSubjectAndBody builds the message subject and body func (provider *AlertProvider) buildMessageSubjectAndBody(endpoint *core.Endpoint, alert *alert.Alert, result *core.Result, resolved bool) (string, string) { - var message, results string - subject := fmt.Sprintf("[%s] Alert triggered", endpoint.DisplayName()) + var subject, message, results string if resolved { + subject = fmt.Sprintf("[%s] Alert resolved", endpoint.DisplayName()) message = fmt.Sprintf("An alert for %s has been resolved after passing successfully %d time(s) in a row", endpoint.DisplayName(), alert.SuccessThreshold) } else { + subject = fmt.Sprintf("[%s] Alert triggered", endpoint.DisplayName()) message = fmt.Sprintf("An alert for %s has been triggered due to having failed %d time(s) in a row", endpoint.DisplayName(), alert.FailureThreshold) } for _, conditionResult := range result.ConditionResults { diff --git a/alerting/provider/email/email_test.go b/alerting/provider/email/email_test.go index f954f099..e409ca05 100644 --- a/alerting/provider/email/email_test.go +++ b/alerting/provider/email/email_test.go @@ -83,7 +83,7 @@ func TestAlertProvider_buildRequestBody(t *testing.T) { Provider: AlertProvider{}, Alert: alert.Alert{Description: &secondDescription, SuccessThreshold: 5, FailureThreshold: 3}, Resolved: true, - ExpectedSubject: "[endpoint-name] Alert triggered", + ExpectedSubject: "[endpoint-name] Alert resolved", ExpectedBody: "An alert for endpoint-name has been resolved after passing successfully 5 time(s) in a row\n\nAlert description: description-2\n\nCondition results:\n✅ [CONNECTED] == true\n✅ [STATUS] == 200\n", }, }