Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from Downager/master
Browse files Browse the repository at this point in the history
Add mention all switch in URL parameter
  • Loading branch information
aledegano authored Aug 3, 2020
2 parents 6de67f0 + e957b70 commit 63f958c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ Example alertmanager webhook config:
- url: http://alertmanager2hangoutschat.domain.com/alertmanager?url=https%3A%2F%2Fchat.googleapis.com%2Fv1%2Fspaces%2Fasdfasdf%2Fmessages%3Fkey%3DKEY%26token%3DTOKEN
```

The endpoints takes the google webhook api as urlencoded GET parameter named "url".

If you don't want to mention all folks in the room, add `mention=false` in URL parameter:
```
webhook_configs:
- url: http://alertmanager2hangoutschat.domain.com/alertmanager?mention=false&url=https%3A%2F%2Fchat.googleapis.com%2Fv1%2Fspaces%2Fasdfasdf%2Fmessages%3Fkey%3DKEY%26token%3DTOKEN
```


### build binary

```
Expand Down
18 changes: 15 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ var logLevel = flag.String("log-level", "info", "Can be one of:"+strings.Join(va
var templateString = flag.String("template-string", messageTemplate, "template for the messages sent to hangouts chat")

var messageTemplate = `<users/all>
*{{.QueryParams.Get "env" | toUpper }}: {{ .Labels.alertname }} - {{.Status | toUpper}}*
*{{ .Labels.alertname }} - {{.Status | toUpper}}*
{{ range .Labels.SortedPairs -}}
*{{ .Name }}*: {{ .Value}}
{{ end -}}
{{ range .Annotations.SortedPairs -}}
{{ .Name }}: {{ .Value}}
*{{ .Name }}*: {{ .Value}}
{{ end -}}
Source: <{{ .GeneratorURL }}|Show in prometheus>
Source: <{{ .GeneratorURL }}|Show in Prometheus>
`

func main() {
Expand Down Expand Up @@ -144,6 +147,11 @@ func sendAlert(data alerttemplate.Alert, getParams url.Values) error {
return err
}

mentionAll, err := url.Parse(getParams.Get("mention"))
if err != nil {
return err
}

alert := &alertData{
Alert: data,
QueryParams: getParams,
Expand All @@ -153,6 +161,10 @@ func sendAlert(data alerttemplate.Alert, getParams url.Values) error {
return err
}

if mentionAll.String() == "false" {
tmpl = strings.Replace(tmpl, "<users/all>\n", "", 1)
}

textReq := &textRequest{
Text: tmpl,
}
Expand Down

0 comments on commit 63f958c

Please sign in to comment.