项目作者: messagebird

项目描述 :
SMS alerts for Prometheus' Alertmanager
高级语言: Go
项目地址: git://github.com/messagebird/sachet.git
创建时间: 2016-06-10T13:08:57Z
项目社区:https://github.com/messagebird/sachet

开源协议:BSD 2-Clause "Simplified" License

下载


Sachet

Sachet (or सचेत) is Hindi for conscious. Sachet is an SMS alerting tool for the Prometheus Alertmanager.

The problem

There are many SMS providers and Alertmanager supporting all of them would make the code noisy. To get around this issue a new service needed to be created dedicated only for SMS.

The solution

An HTTP API that accepts Alertmanager webhook calls and allows an end-user to configure it for the SMS provider of their dreams.

Usage

First get it

  1. $ go get github.com/messagebird/sachet/cmd/sachet

And then running Sachet is as easy as executing sachet on the command line.

  1. $ sachet

Use the -h flag to get help information.

  1. $ sachet -h
  2. Usage of sachet:
  3. -config string
  4. The configuration file (default "config.yaml")
  5. -listen-address string
  6. The address to listen on for HTTP requests. (default ":9876")

Testing

Sachet expects a JSON object from Alertmanager. The format of this JSON is described in the Alertmanager documentation, or, alternatively, in the Alertmanager GoDoc.

To quickly test Sachet is working you can also run:

  1. $ curl -H "Content-type: application/json" -X POST \
  2. -d '{"receiver": "team-sms", "status": "firing", "alerts": [{"status": "firing", "labels": {"alertname": "test-123"} }], "commonLabels": {"key": "value"}}' \
  3. http://localhost:9876/alert

Alertmanager configuration

To enable Sachet you need to configure a webhook in Alertmanager. You can do that by adding a webhook receiver to your Alertmanager configuration.

  1. receivers:
  2. - name: 'team-sms'
  3. webhook_configs:
  4. - 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 as well as available variables.

sachet.yml:

  1. templates:
  2. - /etc/sachet/notifications.tmpl
  3. receivers:
  4. - name: 'team-telegram'
  5. provider: telegram
  6. text: '{{ template "telegram_message" . }}'

notifications.tmpl:

  1. {{ define "telegram_title" }}[{{ .Status | toUpper }}{{ if eq .Status "firing" }}:{{ .Alerts.Firing | len }}{{ end }}] {{ .CommonLabels.alertname }} @ {{ .CommonLabels.identifier }} {{ end }}
  2. {{ define "telegram_message" }}
  3. {{ if gt (len .Alerts.Firing) 0 }}
  4. *Alerts Firing:*
  5. {{ range .Alerts.Firing }}• {{ .Labels.instance }}: {{ .Annotations.description }}
  6. {{ end }}{{ end }}
  7. {{ if gt (len .Alerts.Resolved) 0 }}
  8. *Alerts Resolved:*
  9. {{ range .Alerts.Resolved }}• {{ .Labels.instance }}: {{ .Annotations.description }}
  10. {{ end }}{{ end }}{{ end }}
  11. {{ define "telegram_text" }}{{ template "telegram_title" .}}
  12. {{ template "telegram_message" . }}{{ end }}

License

Sachet is licensed under The BSD 2-Clause License. Copyright (c) 2016, MessageBird