diff --git a/alerting/provider/awsses/awsses.go b/alerting/provider/awsses/awsses.go
index 96234b5f..17ba05cc 100644
--- a/alerting/provider/awsses/awsses.go
+++ b/alerting/provider/awsses/awsses.go
@@ -50,7 +50,6 @@ func (provider *AlertProvider) IsValid() bool {
registeredGroups[override.Group] = true
}
}
-
// if both AccessKeyID and SecretAccessKey are specified, we'll use these to authenticate,
// otherwise if neither are specified, then we'll fall back on IAM authentication.
return len(provider.From) > 0 && len(provider.To) > 0 &&
@@ -112,7 +111,7 @@ 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 subject, message, results string
+ var subject, message 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)
@@ -120,20 +119,24 @@ func (provider *AlertProvider) buildMessageSubjectAndBody(endpoint *core.Endpoin
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 {
- var prefix string
- if conditionResult.Success {
- prefix = "✅"
- } else {
- prefix = "❌"
+ var formattedConditionResults string
+ if len(result.ConditionResults) > 0 {
+ formattedConditionResults = "\n\nCondition results:\n"
+ for _, conditionResult := range result.ConditionResults {
+ var prefix string
+ if conditionResult.Success {
+ prefix = "✅"
+ } else {
+ prefix = "❌"
+ }
+ formattedConditionResults += fmt.Sprintf("%s %s\n", prefix, conditionResult.Condition)
}
- results += fmt.Sprintf("%s %s\n", prefix, conditionResult.Condition)
}
var description string
if alertDescription := alert.GetDescription(); len(alertDescription) > 0 {
description = "\n\nAlert description: " + alertDescription
}
- return subject, message + description + "\n\nCondition results:\n" + results
+ return subject, message + description + formattedConditionResults
}
// getToForGroup returns the appropriate email integration to for a given group
diff --git a/alerting/provider/discord/discord.go b/alerting/provider/discord/discord.go
index 0696a610..d4ac2c96 100644
--- a/alerting/provider/discord/discord.go
+++ b/alerting/provider/discord/discord.go
@@ -75,7 +75,7 @@ type Embed struct {
Title string `json:"title"`
Description string `json:"description"`
Color int `json:"color"`
- Fields []Field `json:"fields"`
+ Fields []Field `json:"fields,omitempty"`
}
type Field struct {
@@ -86,7 +86,7 @@ type Field struct {
// buildRequestBody builds the request body for the provider
func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *alert.Alert, result *core.Result, resolved bool) []byte {
- var message, results string
+ var message string
var colorCode int
if resolved {
message = fmt.Sprintf("An alert for **%s** has been resolved after passing successfully %d time(s) in a row", endpoint.DisplayName(), alert.SuccessThreshold)
@@ -95,6 +95,7 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
message = fmt.Sprintf("An alert for **%s** has been triggered due to having failed %d time(s) in a row", endpoint.DisplayName(), alert.FailureThreshold)
colorCode = 15158332
}
+ var formattedConditionResults string
for _, conditionResult := range result.ConditionResults {
var prefix string
if conditionResult.Success {
@@ -102,7 +103,7 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
} else {
prefix = ":x:"
}
- results += fmt.Sprintf("%s - `%s`\n", prefix, conditionResult.Condition)
+ formattedConditionResults += fmt.Sprintf("%s - `%s`\n", prefix, conditionResult.Condition)
}
var description string
if alertDescription := alert.GetDescription(); len(alertDescription) > 0 {
@@ -112,24 +113,25 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
if provider.Title != "" {
title = provider.Title
}
- body, _ := json.Marshal(Body{
+ body := Body{
Content: "",
Embeds: []Embed{
{
Title: title,
Description: message + description,
Color: colorCode,
- Fields: []Field{
- {
- Name: "Condition results",
- Value: results,
- Inline: false,
- },
- },
},
},
- })
- return body
+ }
+ if len(formattedConditionResults) > 0 {
+ body.Embeds[0].Fields = append(body.Embeds[0].Fields, Field{
+ Name: "Condition results",
+ Value: formattedConditionResults,
+ Inline: false,
+ })
+ }
+ bodyAsJSON, _ := json.Marshal(body)
+ return bodyAsJSON
}
// getWebhookURLForGroup returns the appropriate Webhook URL integration to for a given group
diff --git a/alerting/provider/discord/discord_test.go b/alerting/provider/discord/discord_test.go
index bb69cd83..2c8f1230 100644
--- a/alerting/provider/discord/discord_test.go
+++ b/alerting/provider/discord/discord_test.go
@@ -155,6 +155,7 @@ func TestAlertProvider_buildRequestBody(t *testing.T) {
Name string
Provider AlertProvider
Alert alert.Alert
+ NoConditions bool
Resolved bool
ExpectedBody string
}{
@@ -179,18 +180,30 @@ func TestAlertProvider_buildRequestBody(t *testing.T) {
Resolved: false,
ExpectedBody: "{\"content\":\"\",\"embeds\":[{\"title\":\"provider-title\",\"description\":\"An alert for **endpoint-name** has been triggered due to having failed 3 time(s) in a row:\\n\\u003e description-1\",\"color\":15158332,\"fields\":[{\"name\":\"Condition results\",\"value\":\":x: - `[CONNECTED] == true`\\n:x: - `[STATUS] == 200`\\n:x: - `[BODY] != \\\"\\\"`\\n\",\"inline\":false}]}]}",
},
+ {
+ Name: "triggered-with-no-conditions",
+ NoConditions: true,
+ Provider: AlertProvider{Title: title},
+ Alert: alert.Alert{Description: &firstDescription, SuccessThreshold: 5, FailureThreshold: 3},
+ Resolved: false,
+ ExpectedBody: "{\"content\":\"\",\"embeds\":[{\"title\":\"provider-title\",\"description\":\"An alert for **endpoint-name** has been triggered due to having failed 3 time(s) in a row:\\n\\u003e description-1\",\"color\":15158332}]}",
+ },
}
for _, scenario := range scenarios {
t.Run(scenario.Name, func(t *testing.T) {
+ var conditionResults []*core.ConditionResult
+ if !scenario.NoConditions {
+ conditionResults = []*core.ConditionResult{
+ {Condition: "[CONNECTED] == true", Success: scenario.Resolved},
+ {Condition: "[STATUS] == 200", Success: scenario.Resolved},
+ {Condition: "[BODY] != \"\"", Success: scenario.Resolved},
+ }
+ }
body := scenario.Provider.buildRequestBody(
&core.Endpoint{Name: "endpoint-name"},
&scenario.Alert,
&core.Result{
- ConditionResults: []*core.ConditionResult{
- {Condition: "[CONNECTED] == true", Success: scenario.Resolved},
- {Condition: "[STATUS] == 200", Success: scenario.Resolved},
- {Condition: "[BODY] != \"\"", Success: scenario.Resolved},
- },
+ ConditionResults: conditionResults,
},
scenario.Resolved,
)
diff --git a/alerting/provider/email/email.go b/alerting/provider/email/email.go
index 67a6dea8..e2fe542b 100644
--- a/alerting/provider/email/email.go
+++ b/alerting/provider/email/email.go
@@ -88,7 +88,7 @@ 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 subject, message, results string
+ var subject, message 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)
@@ -96,20 +96,24 @@ func (provider *AlertProvider) buildMessageSubjectAndBody(endpoint *core.Endpoin
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 {
- var prefix string
- if conditionResult.Success {
- prefix = "✅"
- } else {
- prefix = "❌"
+ var formattedConditionResults string
+ if len(result.ConditionResults) > 0 {
+ formattedConditionResults = "\n\nCondition results:\n"
+ for _, conditionResult := range result.ConditionResults {
+ var prefix string
+ if conditionResult.Success {
+ prefix = "✅"
+ } else {
+ prefix = "❌"
+ }
+ formattedConditionResults += fmt.Sprintf("%s %s\n", prefix, conditionResult.Condition)
}
- results += fmt.Sprintf("%s %s\n", prefix, conditionResult.Condition)
}
var description string
if alertDescription := alert.GetDescription(); len(alertDescription) > 0 {
description = "\n\nAlert description: " + alertDescription
}
- return subject, message + description + "\n\nCondition results:\n" + results
+ return subject, message + description + formattedConditionResults
}
// getToForGroup returns the appropriate email integration to for a given group
diff --git a/alerting/provider/github/github.go b/alerting/provider/github/github.go
index fa25022c..f86b9053 100644
--- a/alerting/provider/github/github.go
+++ b/alerting/provider/github/github.go
@@ -105,22 +105,25 @@ func (provider *AlertProvider) Send(endpoint *core.Endpoint, alert *alert.Alert,
// buildIssueBody builds the body of the issue
func (provider *AlertProvider) buildIssueBody(endpoint *core.Endpoint, alert *alert.Alert, result *core.Result) string {
- var results string
- for _, conditionResult := range result.ConditionResults {
- var prefix string
- if conditionResult.Success {
- prefix = ":white_check_mark:"
- } else {
- prefix = ":x:"
+ var formattedConditionResults string
+ if len(result.ConditionResults) > 0 {
+ formattedConditionResults = "\n\n## Condition results\n"
+ for _, conditionResult := range result.ConditionResults {
+ var prefix string
+ if conditionResult.Success {
+ prefix = ":white_check_mark:"
+ } else {
+ prefix = ":x:"
+ }
+ formattedConditionResults += fmt.Sprintf("- %s - `%s`\n", prefix, conditionResult.Condition)
}
- results += fmt.Sprintf("- %s - `%s`\n", prefix, conditionResult.Condition)
}
var description string
if alertDescription := alert.GetDescription(); len(alertDescription) > 0 {
description = ":\n> " + alertDescription
}
message := fmt.Sprintf("An alert for **%s** has been triggered due to having failed %d time(s) in a row", endpoint.DisplayName(), alert.FailureThreshold)
- return message + description + "\n\n## Condition results\n" + results
+ return message + description + formattedConditionResults
}
// GetDefaultAlert returns the provider's default alert configuration
diff --git a/alerting/provider/github/github_test.go b/alerting/provider/github/github_test.go
index c16e6f62..d1f45e48 100644
--- a/alerting/provider/github/github_test.go
+++ b/alerting/provider/github/github_test.go
@@ -112,6 +112,7 @@ func TestAlertProvider_buildRequestBody(t *testing.T) {
Endpoint core.Endpoint
Provider AlertProvider
Alert alert.Alert
+ NoConditions bool
ExpectedBody string
}{
{
@@ -122,24 +123,34 @@ func TestAlertProvider_buildRequestBody(t *testing.T) {
ExpectedBody: "An alert for **endpoint-name** has been triggered due to having failed 3 time(s) in a row:\n> description-1\n\n## Condition results\n- :white_check_mark: - `[CONNECTED] == true`\n- :x: - `[STATUS] == 200`",
},
{
- Name: "no-description",
+ Name: "triggered-with-no-description",
Endpoint: core.Endpoint{Name: "endpoint-name", URL: "https://example.org"},
Provider: AlertProvider{},
Alert: alert.Alert{FailureThreshold: 10},
ExpectedBody: "An alert for **endpoint-name** has been triggered due to having failed 10 time(s) in a row\n\n## Condition results\n- :white_check_mark: - `[CONNECTED] == true`\n- :x: - `[STATUS] == 200`",
},
+ {
+ Name: "triggered-with-no-conditions",
+ NoConditions: true,
+ Endpoint: core.Endpoint{Name: "endpoint-name", URL: "https://example.org"},
+ Provider: AlertProvider{},
+ Alert: alert.Alert{Description: &firstDescription, FailureThreshold: 10},
+ ExpectedBody: "An alert for **endpoint-name** has been triggered due to having failed 10 time(s) in a row:\n> description-1",
+ },
}
for _, scenario := range scenarios {
t.Run(scenario.Name, func(t *testing.T) {
+ var conditionResults []*core.ConditionResult
+ if !scenario.NoConditions {
+ conditionResults = []*core.ConditionResult{
+ {Condition: "[CONNECTED] == true", Success: true},
+ {Condition: "[STATUS] == 200", Success: false},
+ }
+ }
body := scenario.Provider.buildIssueBody(
&scenario.Endpoint,
&scenario.Alert,
- &core.Result{
- ConditionResults: []*core.ConditionResult{
- {Condition: "[CONNECTED] == true", Success: true},
- {Condition: "[STATUS] == 200", Success: false},
- },
- },
+ &core.Result{ConditionResults: conditionResults},
)
if strings.TrimSpace(body) != strings.TrimSpace(scenario.ExpectedBody) {
t.Errorf("expected:\n%s\ngot:\n%s", scenario.ExpectedBody, body)
diff --git a/alerting/provider/gitlab/gitlab.go b/alerting/provider/gitlab/gitlab.go
index 11d337ff..f87b4c4e 100644
--- a/alerting/provider/gitlab/gitlab.go
+++ b/alerting/provider/gitlab/gitlab.go
@@ -25,10 +25,13 @@ type AlertProvider struct {
// Severity can be one of: critical, high, medium, low, info, unknown. Defaults to critical
Severity string `yaml:"severity,omitempty"`
+
// MonitoringTool overrides the name sent to gitlab. Defaults to gatus
MonitoringTool string `yaml:"monitoring-tool,omitempty"`
+
// EnvironmentName is the name of the associated GitLab environment. Required to display alerts on a dashboard.
EnvironmentName string `yaml:"environment-name,omitempty"`
+
// Service affected. Defaults to endpoint display name
Service string `yaml:"service,omitempty"`
}
@@ -52,7 +55,6 @@ func (provider *AlertProvider) Send(endpoint *core.Endpoint, alert *alert.Alert,
if len(alert.ResolveKey) == 0 {
alert.ResolveKey = uuid.NewString()
}
-
buffer := bytes.NewBuffer(provider.buildAlertBody(endpoint, alert, result, resolved))
request, err := http.NewRequest(http.MethodPost, provider.WebhookURL, buffer)
if err != nil {
@@ -114,16 +116,18 @@ func (provider *AlertProvider) buildAlertBody(endpoint *core.Endpoint, alert *al
if resolved {
body.EndTime = result.Timestamp.Format(time.RFC3339)
}
-
- var results string
- for _, conditionResult := range result.ConditionResults {
- var prefix string
- if conditionResult.Success {
- prefix = ":white_check_mark:"
- } else {
- prefix = ":x:"
+ var formattedConditionResults string
+ if len(result.ConditionResults) > 0 {
+ formattedConditionResults = "\n\n## Condition results\n"
+ for _, conditionResult := range result.ConditionResults {
+ var prefix string
+ if conditionResult.Success {
+ prefix = ":white_check_mark:"
+ } else {
+ prefix = ":x:"
+ }
+ formattedConditionResults += fmt.Sprintf("- %s - `%s`\n", prefix, conditionResult.Condition)
}
- results += fmt.Sprintf("- %s - `%s`\n", prefix, conditionResult.Condition)
}
var description string
if alertDescription := alert.GetDescription(); len(alertDescription) > 0 {
@@ -135,10 +139,9 @@ func (provider *AlertProvider) buildAlertBody(endpoint *core.Endpoint, alert *al
} else {
message = fmt.Sprintf("An alert for *%s* has been triggered due to having failed %d time(s) in a row", endpoint.DisplayName(), alert.FailureThreshold)
}
- body.Description = message + description + "\n\n## Condition results\n" + results
-
- json, _ := json.Marshal(body)
- return json
+ body.Description = message + description + formattedConditionResults
+ bodyAsJSON, _ := json.Marshal(body)
+ return bodyAsJSON
}
// GetDefaultAlert returns the provider's default alert configuration
diff --git a/alerting/provider/googlechat/googlechat.go b/alerting/provider/googlechat/googlechat.go
index ea1b4b8c..19330c92 100644
--- a/alerting/provider/googlechat/googlechat.go
+++ b/alerting/provider/googlechat/googlechat.go
@@ -121,7 +121,7 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
color = "#DD0000"
message = fmt.Sprintf("An alert has been triggered due to having failed %d time(s) in a row", color, alert.FailureThreshold)
}
- var results string
+ var formattedConditionResults string
for _, conditionResult := range result.ConditionResults {
var prefix string
if conditionResult.Success {
@@ -129,7 +129,7 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
} else {
prefix = "❌"
}
- results += fmt.Sprintf("%s %s
", prefix, conditionResult.Condition)
+ formattedConditionResults += fmt.Sprintf("%s %s
", prefix, conditionResult.Condition)
}
var description string
if alertDescription := alert.GetDescription(); len(alertDescription) > 0 {
@@ -150,20 +150,22 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
Icon: "BOOKMARK",
},
},
- {
- KeyValue: &KeyValue{
- TopLabel: "Condition results",
- Content: results,
- ContentMultiline: "true",
- Icon: "DESCRIPTION",
- },
- },
},
},
},
},
},
}
+ if len(formattedConditionResults) > 0 {
+ payload.Cards[0].Sections[0].Widgets = append(payload.Cards[0].Sections[0].Widgets, Widgets{
+ KeyValue: &KeyValue{
+ TopLabel: "Condition results",
+ Content: formattedConditionResults,
+ ContentMultiline: "true",
+ Icon: "DESCRIPTION",
+ },
+ })
+ }
if endpoint.Type() == core.EndpointTypeHTTP {
// We only include a button targeting the URL if the endpoint is an HTTP endpoint
// If the URL isn't prefixed with https://, Google Chat will just display a blank message aynways.
@@ -179,8 +181,8 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
},
})
}
- body, _ := json.Marshal(payload)
- return body
+ bodyAsJSON, _ := json.Marshal(payload)
+ return bodyAsJSON
}
// getWebhookURLForGroup returns the appropriate Webhook URL integration to for a given group
diff --git a/alerting/provider/gotify/gotify.go b/alerting/provider/gotify/gotify.go
index e6e35a7c..7f4bfcf6 100644
--- a/alerting/provider/gotify/gotify.go
+++ b/alerting/provider/gotify/gotify.go
@@ -68,12 +68,13 @@ type Body struct {
// buildRequestBody builds the request body for the provider
func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *alert.Alert, result *core.Result, resolved bool) []byte {
- var message, results string
+ var message string
if resolved {
message = fmt.Sprintf("An alert for `%s` has been resolved after passing successfully %d time(s) in a row", endpoint.DisplayName(), alert.SuccessThreshold)
} else {
message = fmt.Sprintf("An alert for `%s` has been triggered due to having failed %d time(s) in a row", endpoint.DisplayName(), alert.FailureThreshold)
}
+ var formattedConditionResults string
for _, conditionResult := range result.ConditionResults {
var prefix string
if conditionResult.Success {
@@ -81,22 +82,22 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
} else {
prefix = "✕"
}
- results += fmt.Sprintf("\n%s - %s", prefix, conditionResult.Condition)
+ formattedConditionResults += fmt.Sprintf("\n%s - %s", prefix, conditionResult.Condition)
}
if len(alert.GetDescription()) > 0 {
message += " with the following description: " + alert.GetDescription()
}
- message += results
+ message += formattedConditionResults
title := "Gatus: " + endpoint.DisplayName()
if provider.Title != "" {
title = provider.Title
}
- body, _ := json.Marshal(Body{
+ bodyAsJSON, _ := json.Marshal(Body{
Message: message,
Title: title,
Priority: provider.Priority,
})
- return body
+ return bodyAsJSON
}
// GetDefaultAlert returns the provider's default alert configuration
diff --git a/alerting/provider/jetbrainsspace/space.go b/alerting/provider/jetbrainsspace/jetbrainsspace.go
similarity index 96%
rename from alerting/provider/jetbrainsspace/space.go
rename to alerting/provider/jetbrainsspace/jetbrainsspace.go
index 55046450..bf031663 100644
--- a/alerting/provider/jetbrainsspace/space.go
+++ b/alerting/provider/jetbrainsspace/jetbrainsspace.go
@@ -17,8 +17,10 @@ type AlertProvider struct {
Project string `yaml:"project"` // JetBrains Space Project name
ChannelID string `yaml:"channel-id"` // JetBrains Space Chat Channel ID
Token string `yaml:"token"` // JetBrains Space Bearer Token
- // DefaultAlert is the defarlt alert configuration to use for endpoints with an alert of the appropriate type
+
+ // DefaultAlert is the default alert configuration to use for endpoints with an alert of the appropriate type
DefaultAlert *alert.Alert `yaml:"default-alert,omitempty"`
+
// Overrides is a list of Override that may be prioritized over the default configuration
Overrides []Override `yaml:"overrides,omitempty"`
}
@@ -73,7 +75,7 @@ type Body struct {
type Content struct {
ClassName string `json:"className"`
Style string `json:"style"`
- Sections []Section `json:"sections"`
+ Sections []Section `json:"sections,omitempty"`
}
type Section struct {
@@ -112,7 +114,6 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
}},
},
}
-
if resolved {
body.Content.Style = "SUCCESS"
body.Content.Sections[0].Header = fmt.Sprintf("An alert for *%s* has been resolved after passing successfully %d time(s) in a row", endpoint.DisplayName(), alert.SuccessThreshold)
@@ -120,7 +121,6 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
body.Content.Style = "WARNING"
body.Content.Sections[0].Header = 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 {
icon := "warning"
style := "WARNING"
@@ -128,7 +128,6 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
icon = "success"
style = "SUCCESS"
}
-
body.Content.Sections[0].Elements = append(body.Content.Sections[0].Elements, Element{
ClassName: "MessageText",
Accessory: Accessory{
@@ -141,9 +140,8 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
Content: conditionResult.Condition,
})
}
-
- jsonBody, _ := json.Marshal(body)
- return jsonBody
+ bodyAsJSON, _ := json.Marshal(body)
+ return bodyAsJSON
}
// getChannelIDForGroup returns the appropriate channel ID to for a given group override
diff --git a/alerting/provider/jetbrainsspace/space_test.go b/alerting/provider/jetbrainsspace/jetbrainsspace_test.go
similarity index 100%
rename from alerting/provider/jetbrainsspace/space_test.go
rename to alerting/provider/jetbrainsspace/jetbrainsspace_test.go
diff --git a/alerting/provider/matrix/matrix.go b/alerting/provider/matrix/matrix.go
index 7a6ff17c..92907889 100644
--- a/alerting/provider/matrix/matrix.go
+++ b/alerting/provider/matrix/matrix.go
@@ -17,7 +17,7 @@ import (
// AlertProvider is the configuration necessary for sending an alert using Matrix
type AlertProvider struct {
- MatrixProviderConfig `yaml:",inline"`
+ ProviderConfig `yaml:",inline"`
// DefaultAlert is the default alert configuration to use for endpoints with an alert of the appropriate type
DefaultAlert *alert.Alert `yaml:"default-alert,omitempty"`
@@ -30,12 +30,12 @@ type AlertProvider struct {
type Override struct {
Group string `yaml:"group"`
- MatrixProviderConfig `yaml:",inline"`
+ ProviderConfig `yaml:",inline"`
}
-const defaultHomeserverURL = "https://matrix-client.matrix.org"
+const defaultServerURL = "https://matrix-client.matrix.org"
-type MatrixProviderConfig struct {
+type ProviderConfig struct {
// ServerURL is the custom homeserver to use (optional)
ServerURL string `yaml:"server-url"`
@@ -65,7 +65,7 @@ func (provider *AlertProvider) Send(endpoint *core.Endpoint, alert *alert.Alert,
buffer := bytes.NewBuffer(provider.buildRequestBody(endpoint, alert, result, resolved))
config := provider.getConfigForGroup(endpoint.Group)
if config.ServerURL == "" {
- config.ServerURL = defaultHomeserverURL
+ config.ServerURL = defaultServerURL
}
// The Matrix endpoint requires a unique transaction ID for each event sent
txnId := randStringBytes(24)
@@ -115,12 +115,13 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
// buildPlaintextMessageBody builds the message body in plaintext to include in request
func buildPlaintextMessageBody(endpoint *core.Endpoint, alert *alert.Alert, result *core.Result, resolved bool) string {
- var message, results string
+ var message string
if resolved {
message = fmt.Sprintf("An alert for `%s` has been resolved after passing successfully %d time(s) in a row", endpoint.DisplayName(), alert.SuccessThreshold)
} else {
message = fmt.Sprintf("An alert for `%s` has been triggered due to having failed %d time(s) in a row", endpoint.DisplayName(), alert.FailureThreshold)
}
+ var formattedConditionResults string
for _, conditionResult := range result.ConditionResults {
var prefix string
if conditionResult.Success {
@@ -128,49 +129,54 @@ func buildPlaintextMessageBody(endpoint *core.Endpoint, alert *alert.Alert, resu
} else {
prefix = "✕"
}
- results += fmt.Sprintf("\n%s - %s", prefix, conditionResult.Condition)
+ formattedConditionResults += fmt.Sprintf("\n%s - %s", prefix, conditionResult.Condition)
}
var description string
if alertDescription := alert.GetDescription(); len(alertDescription) > 0 {
description = "\n" + alertDescription
}
- return fmt.Sprintf("%s%s\n%s", message, description, results)
+ return fmt.Sprintf("%s%s\n%s", message, description, formattedConditionResults)
}
// buildHTMLMessageBody builds the message body in HTML to include in request
func buildHTMLMessageBody(endpoint *core.Endpoint, alert *alert.Alert, result *core.Result, resolved bool) string {
- var message, results string
+ var message string
if resolved {
message = fmt.Sprintf("An alert for %s
has been resolved after passing successfully %d time(s) in a row", endpoint.DisplayName(), alert.SuccessThreshold)
} else {
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 {
- var prefix string
- if conditionResult.Success {
- prefix = "✅"
- } else {
- prefix = "❌"
+ var formattedConditionResults string
+ if len(result.ConditionResults) > 0 {
+ formattedConditionResults = "\n
%s
%s
%s", alertDescription) } - return fmt.Sprintf("