From b0c2f1eba9d830ba6ac082f0f6f7262297b3285b Mon Sep 17 00:00:00 2001 From: Gerrit Date: Wed, 18 Sep 2024 03:02:31 +0200 Subject: [PATCH] feat(alerting): Add optional field alerting.mattermost.channel (#823) * Add optional field alerting.mattermost.channel * Added omitempty to channel in Body for Mattermost * Update README.md * Update alerting/provider/mattermost/mattermost.go * Expose channel configuration parameter through alerting.mattermost.channel --------- Co-authored-by: Gerrit Co-authored-by: TwiN --- README.md | 1 + alerting/provider/mattermost/mattermost.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 4d547f2f..6e9de23a 100644 --- a/README.md +++ b/README.md @@ -915,6 +915,7 @@ endpoints: |:----------------------------------------------|:--------------------------------------------------------------------------------------------|:--------------| | `alerting.mattermost` | Configuration for alerts of type `mattermost` | `{}` | | `alerting.mattermost.webhook-url` | Mattermost Webhook URL | Required `""` | +| `alerting.mattermost.channel` | Mattermost channel name override (optional) | `""` | | `alerting.mattermost.client` | Client configuration.
See [Client configuration](#client-configuration). | `{}` | | `alerting.mattermost.default-alert` | Default alert configuration.
See [Setting a default alert](#setting-a-default-alert). | N/A | | `alerting.mattermost.overrides` | List of overrides that may be prioritized over the default configuration | `[]` | diff --git a/alerting/provider/mattermost/mattermost.go b/alerting/provider/mattermost/mattermost.go index 830dd044..23899e28 100644 --- a/alerting/provider/mattermost/mattermost.go +++ b/alerting/provider/mattermost/mattermost.go @@ -16,6 +16,9 @@ import ( type AlertProvider struct { WebhookURL string `yaml:"webhook-url"` + // Channel is the optional setting to override the default webhook's channel + Channel string `yaml:"channel,omitempty"` + // ClientConfig is the configuration of the client used to communicate with the provider's target ClientConfig *client.Config `yaml:"client,omitempty"` @@ -70,6 +73,7 @@ func (provider *AlertProvider) Send(ep *endpoint.Endpoint, alert *alert.Alert, r } type Body struct { + Channel string `json:"channel,omitempty"` // Optional channel override Text string `json:"text"` Username string `json:"username"` IconURL string `json:"icon_url"` @@ -118,6 +122,7 @@ func (provider *AlertProvider) buildRequestBody(ep *endpoint.Endpoint, alert *al description = ":\n> " + alertDescription } body := Body{ + Channel: provider.Channel, Text: "", Username: "gatus", IconURL: "https://raw.githubusercontent.com/TwiN/gatus/master/.github/assets/logo.png",