Skip to content

Commit

Permalink
Add some documentation and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Svyatoslav Dumchenko committed Sep 25, 2018
1 parent cf8e41c commit d73859e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@ receivers:
- url: 'http://localhost:9876/alert'
```
## Message templating
Sachet supports Alertmanager-like templates for message content. You can do that by simply copying Alertmanager templates to Sachet. Some templates examples can be found in [the Alertmanager documentation](https://prometheus.io/docs/alerting/notification_examples/) as well as [available variables](https://prometheus.io/docs/alerting/notifications/).
sachet.yml:
```yaml
templates:
- /etc/sachet/notifications.tmpl

receivers:
- name: 'team-telegram'
provider: telegram
text: '{{ template "telegram_message" . }}'
```
notifications.tmpl:
```
{{ define "telegram_title" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }} @ {{ .CommonLabels.identifier }} {{ end }}

{{ define "telegram_message" }}
{{ if gt (len .Alerts.Firing) 0 }}
*Alerts Firing:*
{{ range .Alerts.Firing }}• {{ .Labels.instance }}: {{ .Annotations.description }}
{{ end }}{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
*Alerts Resolved:*
{{ range .Alerts.Resolved }}• {{ .Labels.instance }}: {{ .Annotations.description }}
{{ end }}{{ end }}{{ end }}

{{ define "telegram_text" }}{{ template "telegram_title" .}}
{{ template "telegram_message" . }}{{ end }}
```

## License

Sachet is licensed under [The BSD 2-Clause License](http://opensource.org/licenses/BSD-2-Clause). Copyright (c) 2016, MessageBird
4 changes: 4 additions & 0 deletions examples/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ providers:
username: 'username'
password: 'password'

templates:
- telegram.tmpl

receivers:
- name: 'team-sms'
provider: 'messagebird'
Expand All @@ -48,4 +51,5 @@ receivers:
provider: 'telegram'
to:
- '164451814' # the chat id of a user. Get yours at https://telegram.me/userinfobot
text: '{{ .GroupLabels.alertname }} @ {{ .Labels.instance }}: {{ .Status | toUpper }}'

14 changes: 14 additions & 0 deletions examples/telegram.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ define "telegram_title" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }} @ {{ .CommonLabels.identifier }} {{ end }}

{{ define "telegram_message" }}
{{ if gt (len .Alerts.Firing) 0 }}
*Alerts Firing:*
{{ range .Alerts.Firing }}• {{ .Labels.instance }}: {{ .Annotations.description }}
{{ end }}{{ end }}
{{ if gt (len .Alerts.Resolved) 0 }}
*Alerts Resolved:*
{{ range .Alerts.Resolved }}• {{ .Labels.instance }}: {{ .Annotations.description }}
{{ end }}{{ end }}{{ end }}

{{ define "telegram_text" }}{{ template "telegram_title" .}}
{{ template "telegram_message" . }}{{ end }}

0 comments on commit d73859e

Please sign in to comment.