mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-25 09:24:04 +01:00
Improve alerting tests
This commit is contained in:
parent
2ce02b0d7f
commit
2074697efa
84
README.md
84
README.md
@ -332,6 +332,10 @@ services:
|
|||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
interval: 30s
|
interval: 30s
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
- "[RESPONSE_TIME] < 300"
|
||||||
alerts:
|
alerts:
|
||||||
- type: slack
|
- type: slack
|
||||||
enabled: true
|
enabled: true
|
||||||
@ -342,10 +346,6 @@ services:
|
|||||||
failure-threshold: 5
|
failure-threshold: 5
|
||||||
description: "healthcheck failed 5 times in a row"
|
description: "healthcheck failed 5 times in a row"
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
- "[BODY].status == UP"
|
|
||||||
- "[RESPONSE_TIME] < 300"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Here's an example of what the notifications look like:
|
Here's an example of what the notifications look like:
|
||||||
@ -363,15 +363,15 @@ services:
|
|||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
interval: 30s
|
interval: 30s
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
- "[RESPONSE_TIME] < 300"
|
||||||
alerts:
|
alerts:
|
||||||
- type: discord
|
- type: discord
|
||||||
enabled: true
|
enabled: true
|
||||||
description: "healthcheck failed"
|
description: "healthcheck failed"
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
- "[BODY].status == UP"
|
|
||||||
- "[RESPONSE_TIME] < 300"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -390,6 +390,10 @@ services:
|
|||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
interval: 30s
|
interval: 30s
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
- "[RESPONSE_TIME] < 300"
|
||||||
alerts:
|
alerts:
|
||||||
- type: pagerduty
|
- type: pagerduty
|
||||||
enabled: true
|
enabled: true
|
||||||
@ -397,10 +401,6 @@ services:
|
|||||||
success-threshold: 5
|
success-threshold: 5
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
description: "healthcheck failed"
|
description: "healthcheck failed"
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
- "[BODY].status == UP"
|
|
||||||
- "[RESPONSE_TIME] < 300"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -417,16 +417,16 @@ services:
|
|||||||
- name: twinnation
|
- name: twinnation
|
||||||
interval: 30s
|
interval: 30s
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
- "[RESPONSE_TIME] < 300"
|
||||||
alerts:
|
alerts:
|
||||||
- type: twilio
|
- type: twilio
|
||||||
enabled: true
|
enabled: true
|
||||||
failure-threshold: 5
|
failure-threshold: 5
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
description: "healthcheck failed"
|
description: "healthcheck failed"
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
- "[BODY].status == UP"
|
|
||||||
- "[RESPONSE_TIME] < 300"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -442,15 +442,15 @@ services:
|
|||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
interval: 30s
|
interval: 30s
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
- "[RESPONSE_TIME] < 300"
|
||||||
alerts:
|
alerts:
|
||||||
- type: mattermost
|
- type: mattermost
|
||||||
enabled: true
|
enabled: true
|
||||||
description: "healthcheck failed"
|
description: "healthcheck failed"
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
- "[BODY].status == UP"
|
|
||||||
- "[RESPONSE_TIME] < 300"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Here's an example of what the notifications look like:
|
Here's an example of what the notifications look like:
|
||||||
@ -459,9 +459,7 @@ Here's an example of what the notifications look like:
|
|||||||
|
|
||||||
|
|
||||||
#### Configuring Messagebird alerts
|
#### Configuring Messagebird alerts
|
||||||
|
|
||||||
Example of sending **SMS** text message alert using Messagebird:
|
Example of sending **SMS** text message alert using Messagebird:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
alerting:
|
alerting:
|
||||||
messagebird:
|
messagebird:
|
||||||
@ -472,16 +470,16 @@ services:
|
|||||||
- name: twinnation
|
- name: twinnation
|
||||||
interval: 30s
|
interval: 30s
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
- "[RESPONSE_TIME] < 300"
|
||||||
alerts:
|
alerts:
|
||||||
- type: messagebird
|
- type: messagebird
|
||||||
enabled: true
|
enabled: true
|
||||||
failure-threshold: 3
|
failure-threshold: 3
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
description: "healthcheck failed"
|
description: "healthcheck failed"
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
- "[BODY].status == UP"
|
|
||||||
- "[RESPONSE_TIME] < 300"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Configuring Teams alerts
|
#### Configuring Teams alerts
|
||||||
@ -494,15 +492,15 @@ services:
|
|||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
interval: 30s
|
interval: 30s
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
- "[RESPONSE_TIME] < 300"
|
||||||
alerts:
|
alerts:
|
||||||
- type: teams
|
- type: teams
|
||||||
enabled: true
|
enabled: true
|
||||||
description: "healthcheck failed"
|
description: "healthcheck failed"
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
- "[BODY].status == UP"
|
|
||||||
- "[RESPONSE_TIME] < 300"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Here's an example of what the notifications look like:
|
Here's an example of what the notifications look like:
|
||||||
@ -520,13 +518,13 @@ services:
|
|||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
interval: 30s
|
interval: 30s
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
alerts:
|
alerts:
|
||||||
- type: telegram
|
- type: telegram
|
||||||
enabled: true
|
enabled: true
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
- "[BODY].status == UP"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Here's an example of what the notifications look like:
|
Here's an example of what the notifications look like:
|
||||||
@ -564,6 +562,10 @@ services:
|
|||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
interval: 30s
|
interval: 30s
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
- "[RESPONSE_TIME] < 300"
|
||||||
alerts:
|
alerts:
|
||||||
- type: custom
|
- type: custom
|
||||||
enabled: true
|
enabled: true
|
||||||
@ -571,10 +573,6 @@ services:
|
|||||||
success-threshold: 3
|
success-threshold: 3
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
description: "healthcheck failed"
|
description: "healthcheck failed"
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
- "[BODY].status == UP"
|
|
||||||
- "[RESPONSE_TIME] < 300"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that you can customize the resolved values for the `[ALERT_TRIGGERED_OR_RESOLVED]` placeholder like so:
|
Note that you can customize the resolved values for the `[ALERT_TRIGGERED_OR_RESOLVED]` placeholder like so:
|
||||||
@ -612,17 +610,17 @@ As a result, your service configuration looks a lot tidier:
|
|||||||
services:
|
services:
|
||||||
- name: example
|
- name: example
|
||||||
url: "https://example.org"
|
url: "https://example.org"
|
||||||
alerts:
|
|
||||||
- type: slack
|
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
|
alerts:
|
||||||
|
- type: slack
|
||||||
|
|
||||||
- name: other-example
|
- name: other-example
|
||||||
url: "https://example.com"
|
url: "https://example.com"
|
||||||
alerts:
|
|
||||||
- type: slack
|
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
|
alerts:
|
||||||
|
- type: slack
|
||||||
```
|
```
|
||||||
|
|
||||||
It also allows you to do things like this:
|
It also allows you to do things like this:
|
||||||
@ -630,6 +628,8 @@ It also allows you to do things like this:
|
|||||||
services:
|
services:
|
||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
alerts:
|
alerts:
|
||||||
- type: slack
|
- type: slack
|
||||||
failure-threshold: 5
|
failure-threshold: 5
|
||||||
@ -637,8 +637,6 @@ services:
|
|||||||
failure-threshold: 10
|
failure-threshold: 10
|
||||||
- type: slack
|
- type: slack
|
||||||
failure-threshold: 15
|
failure-threshold: 15
|
||||||
conditions:
|
|
||||||
- "[STATUS] == 200"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,12 +23,12 @@ const (
|
|||||||
// TypeSlack is the Type for the slack alerting provider
|
// TypeSlack is the Type for the slack alerting provider
|
||||||
TypeSlack Type = "slack"
|
TypeSlack Type = "slack"
|
||||||
|
|
||||||
|
// TypeTeams is the Type for the teams alerting provider
|
||||||
|
TypeTeams Type = "teams"
|
||||||
|
|
||||||
// TypeTelegram is the Type for the telegram alerting provider
|
// TypeTelegram is the Type for the telegram alerting provider
|
||||||
TypeTelegram Type = "telegram"
|
TypeTelegram Type = "telegram"
|
||||||
|
|
||||||
// TypeTwilio is the Type for the twilio alerting provider
|
// TypeTwilio is the Type for the twilio alerting provider
|
||||||
TypeTwilio Type = "twilio"
|
TypeTwilio Type = "twilio"
|
||||||
|
|
||||||
// Teams is the Type for the teams alerting provider
|
|
||||||
TypeTeams Type = "teams"
|
|
||||||
)
|
)
|
||||||
|
@ -9,9 +9,9 @@ import (
|
|||||||
"github.com/TwinProduction/gatus/alerting/provider/messagebird"
|
"github.com/TwinProduction/gatus/alerting/provider/messagebird"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/pagerduty"
|
"github.com/TwinProduction/gatus/alerting/provider/pagerduty"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/slack"
|
"github.com/TwinProduction/gatus/alerting/provider/slack"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/teams"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/telegram"
|
"github.com/TwinProduction/gatus/alerting/provider/telegram"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/twilio"
|
"github.com/TwinProduction/gatus/alerting/provider/twilio"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/teams"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is the configuration for alerting providers
|
// Config is the configuration for alerting providers
|
||||||
@ -34,14 +34,14 @@ type Config struct {
|
|||||||
// Slack is the configuration for the slack alerting provider
|
// Slack is the configuration for the slack alerting provider
|
||||||
Slack *slack.AlertProvider `yaml:"slack"`
|
Slack *slack.AlertProvider `yaml:"slack"`
|
||||||
|
|
||||||
|
// Teams is the configuration for the teams alerting provider
|
||||||
|
Teams *teams.AlertProvider `yaml:"teams"`
|
||||||
|
|
||||||
// Telegram is the configuration for the telegram alerting provider
|
// Telegram is the configuration for the telegram alerting provider
|
||||||
Telegram *telegram.AlertProvider `yaml:"telegram"`
|
Telegram *telegram.AlertProvider `yaml:"telegram"`
|
||||||
|
|
||||||
// Twilio is the configuration for the twilio alerting provider
|
// Twilio is the configuration for the twilio alerting provider
|
||||||
Twilio *twilio.AlertProvider `yaml:"twilio"`
|
Twilio *twilio.AlertProvider `yaml:"twilio"`
|
||||||
|
|
||||||
// Teams is the configuration for the teams alerting provider
|
|
||||||
Teams *teams.AlertProvider `yaml:"teams"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAlertingProviderByAlertType returns an provider.AlertProvider by its corresponding alert.Type
|
// GetAlertingProviderByAlertType returns an provider.AlertProvider by its corresponding alert.Type
|
||||||
@ -83,6 +83,12 @@ func (config Config) GetAlertingProviderByAlertType(alertType alert.Type) provid
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return config.Slack
|
return config.Slack
|
||||||
|
case alert.TypeTeams:
|
||||||
|
if config.Teams == nil {
|
||||||
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return config.Teams
|
||||||
case alert.TypeTelegram:
|
case alert.TypeTelegram:
|
||||||
if config.Telegram == nil {
|
if config.Telegram == nil {
|
||||||
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
||||||
@ -95,12 +101,6 @@ func (config Config) GetAlertingProviderByAlertType(alertType alert.Type) provid
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return config.Twilio
|
return config.Twilio
|
||||||
case alert.TypeTeams:
|
|
||||||
if config.Teams == nil {
|
|
||||||
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return config.Teams
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,10 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
}
|
}
|
||||||
results += 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
|
||||||
|
}
|
||||||
return &custom.AlertProvider{
|
return &custom.AlertProvider{
|
||||||
URL: provider.WebhookURL,
|
URL: provider.WebhookURL,
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
@ -50,7 +54,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
"embeds": [
|
"embeds": [
|
||||||
{
|
{
|
||||||
"title": ":helmet_with_white_cross: Gatus",
|
"title": ":helmet_with_white_cross: Gatus",
|
||||||
"description": "%s:\n> %s",
|
"description": "%s%s",
|
||||||
"color": %d,
|
"color": %d,
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@ -61,7 +65,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}`, message, alert.GetDescription(), colorCode, results),
|
}`, message, description, colorCode, results),
|
||||||
Headers: map[string]string{"Content-Type": "application/json"},
|
Headers: map[string]string{"Content-Type": "application/json"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,8 @@ func TestAlertProvider_IsValid(t *testing.T) {
|
|||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
||||||
provider := AlertProvider{WebhookURL: "http://example.com"}
|
provider := AlertProvider{WebhookURL: "http://example.com"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
alertDescription := "test"
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{Name: "svc"}, &alert.Alert{Description: &alertDescription}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Fatal("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
@ -41,6 +42,9 @@ func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("expected body to be valid JSON, got error:", err.Error())
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
}
|
}
|
||||||
|
if expected := "An alert for **svc** has been resolved after passing successfully 0 time(s) in a row:\n> test"; expected != body["embeds"].([]interface{})[0].(map[string]interface{})["description"] {
|
||||||
|
t.Errorf("expected $.embeds[0].description to be %s, got %s", expected, body["embeds"].([]interface{})[0].(map[string]interface{})["description"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
|
@ -57,6 +57,10 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
}
|
}
|
||||||
results += 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
|
||||||
|
}
|
||||||
return &custom.AlertProvider{
|
return &custom.AlertProvider{
|
||||||
URL: provider.WebhookURL,
|
URL: provider.WebhookURL,
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
@ -69,7 +73,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
{
|
{
|
||||||
"title": ":rescue_worker_helmet: Gatus",
|
"title": ":rescue_worker_helmet: Gatus",
|
||||||
"fallback": "Gatus - %s",
|
"fallback": "Gatus - %s",
|
||||||
"text": "%s:\n> %s",
|
"text": "%s%s",
|
||||||
"short": false,
|
"short": false,
|
||||||
"color": "%s",
|
"color": "%s",
|
||||||
"fields": [
|
"fields": [
|
||||||
@ -86,7 +90,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}`, message, message, alert.GetDescription(), color, service.URL, results),
|
}`, message, message, description, color, service.URL, results),
|
||||||
Headers: map[string]string{"Content-Type": "application/json"},
|
Headers: map[string]string{"Content-Type": "application/json"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,8 @@ func TestAlertProvider_IsValid(t *testing.T) {
|
|||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
||||||
provider := AlertProvider{WebhookURL: "http://example.org"}
|
provider := AlertProvider{WebhookURL: "http://example.org"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
alertDescription := "test"
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{Name: "svc"}, &alert.Alert{Description: &alertDescription}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Fatal("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
@ -41,6 +42,9 @@ func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("expected body to be valid JSON, got error:", err.Error())
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
}
|
}
|
||||||
|
if expected := "An alert for *svc* has been resolved after passing successfully 0 time(s) in a row:\n> test"; expected != body["attachments"].([]interface{})[0].(map[string]interface{})["text"] {
|
||||||
|
t.Errorf("expected $.attachments[0].description to be %s, got %s", expected, body["attachments"].([]interface{})[0].(map[string]interface{})["text"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
|
@ -8,9 +8,9 @@ import (
|
|||||||
"github.com/TwinProduction/gatus/alerting/provider/messagebird"
|
"github.com/TwinProduction/gatus/alerting/provider/messagebird"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/pagerduty"
|
"github.com/TwinProduction/gatus/alerting/provider/pagerduty"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/slack"
|
"github.com/TwinProduction/gatus/alerting/provider/slack"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/teams"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/telegram"
|
"github.com/TwinProduction/gatus/alerting/provider/telegram"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/twilio"
|
"github.com/TwinProduction/gatus/alerting/provider/twilio"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/teams"
|
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ var (
|
|||||||
_ AlertProvider = (*messagebird.AlertProvider)(nil)
|
_ AlertProvider = (*messagebird.AlertProvider)(nil)
|
||||||
_ AlertProvider = (*pagerduty.AlertProvider)(nil)
|
_ AlertProvider = (*pagerduty.AlertProvider)(nil)
|
||||||
_ AlertProvider = (*slack.AlertProvider)(nil)
|
_ AlertProvider = (*slack.AlertProvider)(nil)
|
||||||
|
_ AlertProvider = (*teams.AlertProvider)(nil)
|
||||||
_ AlertProvider = (*telegram.AlertProvider)(nil)
|
_ AlertProvider = (*telegram.AlertProvider)(nil)
|
||||||
_ AlertProvider = (*twilio.AlertProvider)(nil)
|
_ AlertProvider = (*twilio.AlertProvider)(nil)
|
||||||
_ AlertProvider = (*teams.AlertProvider)(nil)
|
|
||||||
)
|
)
|
||||||
|
@ -41,6 +41,10 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
}
|
}
|
||||||
results += 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
|
||||||
|
}
|
||||||
return &custom.AlertProvider{
|
return &custom.AlertProvider{
|
||||||
URL: provider.WebhookURL,
|
URL: provider.WebhookURL,
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
@ -49,7 +53,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
"attachments": [
|
"attachments": [
|
||||||
{
|
{
|
||||||
"title": ":helmet_with_white_cross: Gatus",
|
"title": ":helmet_with_white_cross: Gatus",
|
||||||
"text": "%s:\n> %s",
|
"text": "%s%s",
|
||||||
"short": false,
|
"short": false,
|
||||||
"color": "%s",
|
"color": "%s",
|
||||||
"fields": [
|
"fields": [
|
||||||
@ -61,7 +65,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}`, message, alert.GetDescription(), color, results),
|
}`, message, description, color, results),
|
||||||
Headers: map[string]string{"Content-Type": "application/json"},
|
Headers: map[string]string{"Content-Type": "application/json"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,8 @@ func TestAlertProvider_IsValid(t *testing.T) {
|
|||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
||||||
provider := AlertProvider{WebhookURL: "http://example.com"}
|
provider := AlertProvider{WebhookURL: "http://example.com"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
alertDescription := "test"
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{Name: "svc"}, &alert.Alert{Description: &alertDescription}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Fatal("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
@ -41,6 +42,9 @@ func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("expected body to be valid JSON, got error:", err.Error())
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
}
|
}
|
||||||
|
if expected := "An alert for *svc* has been resolved after passing successfully 0 time(s) in a row:\n> test"; expected != body["attachments"].([]interface{})[0].(map[string]interface{})["text"] {
|
||||||
|
t.Errorf("expected $.attachments[0].description to be %s, got %s", expected, body["attachments"].([]interface{})[0].(map[string]interface{})["text"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
|
@ -37,21 +37,25 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
for _, conditionResult := range result.ConditionResults {
|
for _, conditionResult := range result.ConditionResults {
|
||||||
var prefix string
|
var prefix string
|
||||||
if conditionResult.Success {
|
if conditionResult.Success {
|
||||||
prefix = "✅"
|
prefix = "✅"
|
||||||
} else {
|
} else {
|
||||||
prefix = "❌"
|
prefix = "❌"
|
||||||
}
|
}
|
||||||
results += fmt.Sprintf("%s - `%s`<br/>", prefix, conditionResult.Condition)
|
results += fmt.Sprintf("%s - `%s`<br/>", prefix, conditionResult.Condition)
|
||||||
}
|
}
|
||||||
|
var description string
|
||||||
|
if alertDescription := alert.GetDescription(); len(alertDescription) > 0 {
|
||||||
|
description = ":\\n> " + alertDescription
|
||||||
|
}
|
||||||
return &custom.AlertProvider{
|
return &custom.AlertProvider{
|
||||||
URL: provider.WebhookURL,
|
URL: provider.WebhookURL,
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Body: fmt.Sprintf(`{
|
Body: fmt.Sprintf(`{
|
||||||
"@type": "MessageCard",
|
"@type": "MessageCard",
|
||||||
"@context": "http://schema.org/extensions",
|
"@context": "http://schema.org/extensions",
|
||||||
"themeColor": "%s",
|
"themeColor": "%s",
|
||||||
"title": "🚨 Gatus",
|
"title": "🚨 Gatus",
|
||||||
"text": "%s:\n> %s",
|
"text": "%s%s",
|
||||||
"sections": [
|
"sections": [
|
||||||
{
|
{
|
||||||
"activityTitle": "URL",
|
"activityTitle": "URL",
|
||||||
@ -62,7 +66,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
"text": "%s"
|
"text": "%s"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}`, color, message, alert.GetDescription(), service.URL, results),
|
}`, color, message, description, service.URL, results),
|
||||||
Headers: map[string]string{"Content-Type": "application/json"},
|
Headers: map[string]string{"Content-Type": "application/json"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,8 @@ func TestAlertProvider_IsValid(t *testing.T) {
|
|||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
||||||
provider := AlertProvider{WebhookURL: "http://example.org"}
|
provider := AlertProvider{WebhookURL: "http://example.org"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
alertDescription := "test"
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{Name: "svc"}, &alert.Alert{Description: &alertDescription}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Fatal("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
@ -41,6 +42,9 @@ func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("expected body to be valid JSON, got error:", err.Error())
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
}
|
}
|
||||||
|
if expected := "An alert for *svc* has been resolved after passing successfully 0 time(s) in a row:\n> test"; expected != body["text"] {
|
||||||
|
t.Errorf("expected $.text to be %s, got %s", expected, body["text"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
|
@ -270,9 +270,9 @@ func validateAlertingConfig(alertingConfig *alerting.Config, services []*core.Se
|
|||||||
alert.TypeMessagebird,
|
alert.TypeMessagebird,
|
||||||
alert.TypePagerDuty,
|
alert.TypePagerDuty,
|
||||||
alert.TypeSlack,
|
alert.TypeSlack,
|
||||||
|
alert.TypeTeams,
|
||||||
alert.TypeTelegram,
|
alert.TypeTelegram,
|
||||||
alert.TypeTwilio,
|
alert.TypeTwilio,
|
||||||
alert.TypeTeams,
|
|
||||||
}
|
}
|
||||||
var validProviders, invalidProviders []alert.Type
|
var validProviders, invalidProviders []alert.Type
|
||||||
for _, alertType := range alertTypes {
|
for _, alertType := range alertTypes {
|
||||||
|
Loading…
Reference in New Issue
Block a user