fix(alerting): Resolve issue with blank GoogleChat messages (#364)

* debug: Print GoogleChat request body

* chore: Update TwiN/whois to v1.1.0

* fix: Add missing client changes

* test: Improve DNS tests

* chore: Remove accidental change

* docs: Add note for future change to default behavior

* fix(alerting): Don't include URL in Google Chat alert if endpoint type isn't HTTP

Fixes #362
This commit is contained in:
TwiN
2022-11-22 20:12:26 -05:00
committed by GitHub
parent 4f569b7a0e
commit f8140e0d96
3 changed files with 39 additions and 15 deletions

View File

@ -37,7 +37,6 @@ func (provider *AlertProvider) IsValid() bool {
if provider.ClientConfig == nil {
provider.ClientConfig = client.GetDefaultConfig()
}
registeredGroups := make(map[string]bool)
if provider.Overrides != nil {
for _, override := range provider.Overrides {
@ -47,7 +46,6 @@ func (provider *AlertProvider) IsValid() bool {
registeredGroups[override.Group] = true
}
}
return len(provider.WebhookURL) > 0
}
@ -137,7 +135,7 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
if alertDescription := alert.GetDescription(); len(alertDescription) > 0 {
description = ":: " + alertDescription
}
body, _ := json.Marshal(Body{
payload := Body{
Cards: []Cards{
{
Sections: []Sections{
@ -160,22 +158,28 @@ func (provider *AlertProvider) buildRequestBody(endpoint *core.Endpoint, alert *
Icon: "DESCRIPTION",
},
},
{
Buttons: []Buttons{
{
TextButton: TextButton{
Text: "URL",
OnClick: OnClick{OpenLink: OpenLink{URL: endpoint.URL}},
},
},
},
},
},
},
},
},
},
})
}
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.
// See https://github.com/TwiN/gatus/issues/362
payload.Cards[0].Sections[0].Widgets = append(payload.Cards[0].Sections[0].Widgets, Widgets{
Buttons: []Buttons{
{
TextButton: TextButton{
Text: "URL",
OnClick: OnClick{OpenLink: OpenLink{URL: endpoint.URL}},
},
},
},
})
}
body, _ := json.Marshal(payload)
return body
}