From 5139d65f9cf9d044a648d8c381fd280b5cca910d Mon Sep 17 00:00:00 2001 From: Alex Marston Date: Tue, 10 Jun 2025 14:38:06 +0100 Subject: [PATCH] feat: support Google Chat as an Alert notification provider --- README.md | 4 ++-- docs/Alerting.md | 2 +- internal/pkg/alerts/alert.go | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 84def75..23e4042 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ metadata: Reloader can optionally **send alerts** whenever it triggers a rolling upgrade for a workload (e.g., `Deployment`, `StatefulSet`, etc.). -These alerts are sent to a configured **webhook endpoint**, which can be a generic receiver or services like Slack or Microsoft Teams. +These alerts are sent to a configured **webhook endpoint**, which can be a generic receiver or services like Slack, Microsoft Teams or Google Chat. To enable this feature, update the `reloader.env.secret` section in your `values.yaml` (when installing via Helm): @@ -198,7 +198,7 @@ reloader: env: secret: ALERT_ON_RELOAD: "true" # Enable alerting (default: false) - ALERT_SINK: "slack" # Options: slack, teams, webhook (default: webhook) + ALERT_SINK: "slack" # Options: slack, teams, gchat or webhook (default: webhook) ALERT_WEBHOOK_URL: "" # Required if ALERT_ON_RELOAD is true ALERT_ADDITIONAL_INFO: "Triggered by Reloader in staging environment" ``` diff --git a/docs/Alerting.md b/docs/Alerting.md index 43eefe5..bb4fbbe 100644 --- a/docs/Alerting.md +++ b/docs/Alerting.md @@ -8,7 +8,7 @@ In-order to enable this feature, you need to update the `reloader.env.secret` se ```yaml ALERT_ON_RELOAD: [ true/false ] Default: false - ALERT_SINK: [ slack/teams/webhook ] Default: webhook + ALERT_SINK: [ slack/teams/gchat/webhook ] Default: webhook ALERT_WEBHOOK_URL: Required if ALERT_ON_RELOAD is true ALERT_ADDITIONAL_INFO: Any additional information to be added to alert ``` diff --git a/internal/pkg/alerts/alert.go b/internal/pkg/alerts/alert.go index 43b4c06..5791448 100644 --- a/internal/pkg/alerts/alert.go +++ b/internal/pkg/alerts/alert.go @@ -35,6 +35,8 @@ func SendWebhookAlert(msg string) { sendSlackAlert(webhook_url, webhook_proxy, msg) } else if alert_sink == "teams" { sendTeamsAlert(webhook_url, webhook_proxy, msg) + } else if alert_sink == "gchat" { + sendGoogleChatAlert(webhook_url, webhook_proxy, msg) } else { msg = strings.Replace(msg, "*", "", -1) sendRawWebhookAlert(webhook_url, webhook_proxy, msg) @@ -98,6 +100,29 @@ func sendTeamsAlert(webhookUrl string, proxy string, msg string) []error { return nil } +// function to send alert to Google Chat webhook +func sendGoogleChatAlert(webhookUrl string, proxy string, msg string) []error { + payload := map[string]interface{}{ + "text": msg, + } + + request := gorequest.New().Proxy(proxy) + resp, _, err := request. + Post(webhookUrl). + RedirectPolicy(redirectPolicy). + Send(payload). + End() + + if err != nil { + return err + } + if resp.StatusCode != 200 { + return []error{fmt.Errorf("error sending msg. status: %v", resp.Status)} + } + + return nil +} + // function to send alert to webhook service as text func sendRawWebhookAlert(webhookUrl string, proxy string, msg string) []error { request := gorequest.New().Proxy(proxy)