diff --git a/README.md b/README.md index b367397b..97e76f1b 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Have any feedback or questions? [Create a discussion](https://github.com/TwiN/ga - [Configuring Discord alerts](#configuring-discord-alerts) - [Configuring Email alerts](#configuring-email-alerts) - [Configuring Google Chat alerts](#configuring-google-chat-alerts) + - [Configuring Matrix alerts](#configuring-matrix-alerts) - [Configuring Mattermost alerts](#configuring-mattermost-alerts) - [Configuring Messagebird alerts](#configuring-messagebird-alerts) - [Configuring Opsgenie alerts](#configuring-opsgenie-alerts) @@ -50,7 +51,6 @@ Have any feedback or questions? [Create a discussion](https://github.com/TwiN/ga - [Configuring Teams alerts](#configuring-teams-alerts) - [Configuring Telegram alerts](#configuring-telegram-alerts) - [Configuring Twilio alerts](#configuring-twilio-alerts) - - [Configuring Matrix alerts](#configuring-matrix-alerts) - [Configuring custom alerts](#configuring-custom-alerts) - [Setting a default alert](#setting-a-default-alert) - [Maintenance](#maintenance) @@ -489,6 +489,37 @@ endpoints: send-on-resolved: true ``` +#### Configuring Matrix alerts +| Parameter | Description | Default | +|:-----------------------------------|:-------------------------------------------------------------------------------------------------|:-----------------------------------| +| `alerting.matrix` | Settings for alerts of type `matrix` | `{}` | +| `alerting.matrix.server-url` | Homeserver URL | `https://matrix-client.matrix.org` | +| `alerting.matrix.access-token` | Bot user access token (see https://webapps.stackexchange.com/q/131056) | Required `""` | +| `alerting.matrix.internal-room-id` | Internal room ID of room to send alerts to (can be found in Element in Room Settings > Advanced) | Required `""` | +| `alerting.matrix.default-alert` | Default alert configuration.
See [Setting a default alert](#setting-a-default-alert) | N/A | + +```yaml +alerting: + matrix: + server-url: "..." + access-token: "..." + internal-room-id: "..." + +endpoints: + - name: website + interval: 30s + url: "https://twin.sh/health" + conditions: + - "[STATUS] == 200" + - "[BODY].status == UP" + - "[RESPONSE_TIME] < 300" + alerts: + - type: matrix + enabled: true + send-on-resolved: true + description: "healthcheck failed" +``` + #### Configuring Mattermost alerts | Parameter | Description | Default | |:----------------------------------------------|:--------------------------------------------------------------------------------------------|:--------------| @@ -802,37 +833,6 @@ endpoints: description: "healthcheck failed" ``` -#### Configuring Matrix alerts -| Parameter | Description | Default | -|:-----------------------------------|:-------------------------------------------------------------------------------------------|:-----------------------------------| -| `alerting.matrix` | Settings for alerts of type `matrix` | `{}` | -| `alerting.matrix.homeserver-url` | Custom homeserver URL | `https://matrix-client.matrix.org` | -| `alerting.matrix.access-token` | Bot user access token | Required `""` | -| `alerting.matrix.internal-room-id` | Internal room ID of room that bot user can send messages to | Required `""` | -| `alerting.matrix.default-alert` | Default alert configuration.
See [Setting a default alert](#setting-a-default-alert) | N/A | - -```yaml -alerting: - matrix: - homeserver-url: "..." - access-token: "..." - internal-room-id: "..." - -endpoints: - - name: website - interval: 30s - url: "https://twin.sh/health" - conditions: - - "[STATUS] == 200" - - "[BODY].status == UP" - - "[RESPONSE_TIME] < 300" - alerts: - - type: matrix - enabled: true - send-on-resolved: true - description: "healthcheck failed" -``` - #### Configuring custom alerts | Parameter | Description | Default | |:--------------------------------|:-------------------------------------------------------------------------------------------|:--------------| diff --git a/alerting/config.go b/alerting/config.go index cb2167e2..abac5033 100644 --- a/alerting/config.go +++ b/alerting/config.go @@ -87,6 +87,12 @@ func (config Config) GetAlertingProviderByAlertType(alertType alert.Type) provid return nil } return config.GoogleChat + case alert.TypeMatrix: + if config.Matrix == nil { + // Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil + return nil + } + return config.Matrix case alert.TypeMattermost: if config.Mattermost == nil { // Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil @@ -135,12 +141,6 @@ func (config Config) GetAlertingProviderByAlertType(alertType alert.Type) provid return nil } return config.Twilio - case alert.TypeMatrix: - if config.Matrix == nil { - // Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil - return nil - } - return config.Matrix } return nil } diff --git a/alerting/provider/provider.go b/alerting/provider/provider.go index 51f32da8..1f105648 100644 --- a/alerting/provider/provider.go +++ b/alerting/provider/provider.go @@ -58,6 +58,7 @@ var ( _ AlertProvider = (*discord.AlertProvider)(nil) _ AlertProvider = (*email.AlertProvider)(nil) _ AlertProvider = (*googlechat.AlertProvider)(nil) + _ AlertProvider = (*matrix.AlertProvider)(nil) _ AlertProvider = (*mattermost.AlertProvider)(nil) _ AlertProvider = (*messagebird.AlertProvider)(nil) _ AlertProvider = (*opsgenie.AlertProvider)(nil) @@ -66,5 +67,4 @@ var ( _ AlertProvider = (*teams.AlertProvider)(nil) _ AlertProvider = (*telegram.AlertProvider)(nil) _ AlertProvider = (*twilio.AlertProvider)(nil) - _ AlertProvider = (*matrix.AlertProvider)(nil) ) diff --git a/config/config.go b/config/config.go index 2043ac24..c3280f8d 100644 --- a/config/config.go +++ b/config/config.go @@ -274,6 +274,7 @@ func validateAlertingConfig(alertingConfig *alerting.Config, endpoints []*core.E alert.TypeCustom, alert.TypeDiscord, alert.TypeEmail, + alert.TypeMatrix, alert.TypeMattermost, alert.TypeMessagebird, alert.TypeOpsgenie, @@ -282,7 +283,6 @@ func validateAlertingConfig(alertingConfig *alerting.Config, endpoints []*core.E alert.TypeTeams, alert.TypeTelegram, alert.TypeTwilio, - alert.TypeMatrix, } var validProviders, invalidProviders []alert.Type for _, alertType := range alertTypes {