Skip to content

Commit 516f9e8

Browse files
authored
Merge pull request #934 from alexandermarston/support-gchat
feat: support Google Chat as an Alert notification provider
2 parents c2107cc + e69ea41 commit 516f9e8

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ metadata:
189189
190190
Reloader can optionally **send alerts** whenever it triggers a rolling upgrade for a workload (e.g., `Deployment`, `StatefulSet`, etc.).
191191

192-
These alerts are sent to a configured **webhook endpoint**, which can be a generic receiver or services like Slack or Microsoft Teams.
192+
These alerts are sent to a configured **webhook endpoint**, which can be a generic receiver or services like Slack, Microsoft Teams or Google Chat.
193193

194194
To enable this feature, update the `reloader.env.secret` section in your `values.yaml` (when installing via Helm):
195195

@@ -198,7 +198,7 @@ reloader:
198198
env:
199199
secret:
200200
ALERT_ON_RELOAD: "true" # Enable alerting (default: false)
201-
ALERT_SINK: "slack" # Options: slack, teams, webhook (default: webhook)
201+
ALERT_SINK: "slack" # Options: slack, teams, gchat or webhook (default: webhook)
202202
ALERT_WEBHOOK_URL: "<your-webhook-url>" # Required if ALERT_ON_RELOAD is true
203203
ALERT_ADDITIONAL_INFO: "Triggered by Reloader in staging environment"
204204
```

docs/Alerting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In-order to enable this feature, you need to update the `reloader.env.secret` se
88

99
```yaml
1010
ALERT_ON_RELOAD: [ true/false ] Default: false
11-
ALERT_SINK: [ slack/teams/webhook ] Default: webhook
11+
ALERT_SINK: [ slack/teams/gchat/webhook ] Default: webhook
1212
ALERT_WEBHOOK_URL: Required if ALERT_ON_RELOAD is true
1313
ALERT_ADDITIONAL_INFO: Any additional information to be added to alert
1414
```

internal/pkg/alerts/alert.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ func SendWebhookAlert(msg string) {
3535
sendSlackAlert(webhook_url, webhook_proxy, msg)
3636
} else if alert_sink == "teams" {
3737
sendTeamsAlert(webhook_url, webhook_proxy, msg)
38+
} else if alert_sink == "gchat" {
39+
sendGoogleChatAlert(webhook_url, webhook_proxy, msg)
3840
} else {
3941
msg = strings.Replace(msg, "*", "", -1)
4042
sendRawWebhookAlert(webhook_url, webhook_proxy, msg)
@@ -98,6 +100,29 @@ func sendTeamsAlert(webhookUrl string, proxy string, msg string) []error {
98100
return nil
99101
}
100102

103+
// function to send alert to Google Chat webhook
104+
func sendGoogleChatAlert(webhookUrl string, proxy string, msg string) []error {
105+
payload := map[string]interface{}{
106+
"text": msg,
107+
}
108+
109+
request := gorequest.New().Proxy(proxy)
110+
resp, _, err := request.
111+
Post(webhookUrl).
112+
RedirectPolicy(redirectPolicy).
113+
Send(payload).
114+
End()
115+
116+
if err != nil {
117+
return err
118+
}
119+
if resp.StatusCode != 200 {
120+
return []error{fmt.Errorf("error sending msg. status: %v", resp.Status)}
121+
}
122+
123+
return nil
124+
}
125+
101126
// function to send alert to webhook service as text
102127
func sendRawWebhookAlert(webhookUrl string, proxy string, msg string) []error {
103128
request := gorequest.New().Proxy(proxy)

0 commit comments

Comments
 (0)