项目作者: maxemontio

项目描述 :
Telegram notificator for Alertmanager
高级语言: JavaScript
项目地址: git://github.com/maxemontio/promegram.git
创建时间: 2020-10-29T12:15:28Z
项目社区:https://github.com/maxemontio/promegram

开源协议:

下载


Promegram

Telegram notificator for Alertmanager

Need to set

  1. Bot token
  2. Chat id (one or more)
  3. Alertmanager URL
  4. Time to set silence
  5. Delay between messages
  6. Check alerts interval

Features

  • Sending alerts by one
  • Button, which allows you to set silence (by instance and alertname values) and expire it then
  • No need to type /start or something to launch, it will send messages to until it is alive
  • Use /users to get list of users
  • To get chat id of any user, just forward a message of this user to bot

Alertmanager config

  1. receivers:
  2. - name: 'promegram'
  3. webhook_configs:
  4. - send_resolved: true
  5. url: <url:port>

If you have multiple recievers, do not set ‘group_by’ directive for promegram - bot works faster without that

Prometheus rules

Promegram use summary field, so use it for some kind of message templating.

Example:

  1. - alert: HostIsDown
  2. expr: up == 0
  3. labels:
  4. severity: warning
  5. annotations:
  6. summary:
  7. "Job: {{ $labels.job }}
  8. \nHost: {{ $labels.instance }}
  9. \nMessage: Host is unavailable
  10. \nMetric value: {{ $value }}"

Try with docker

  1. version: '3.1'
  2. services:
  3. promegram:
  4. image: maxemontio/promegram:latest
  5. container_name: promegram
  6. hostname: promegram
  7. restart: always
  8. ports:
  9. - 8088:8088
  10. environment:
  11. - ALERTMANAGERURL=http://<address>:<port> # dont set to disable buttons
  12. - TOKEN=<bot token> # botfather will tell you
  13. - USERS=<chat id> # one or more user or group chat ids, but it is better to use ony user chat ids because of https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this
  14. - SILENCETIME=1 # minimum one hour, set 0 to disable buttons
  15. - MSGDELAYMS=50 # more than 1000 to GROUP chat and LESS than 20 messages per minute; more then 30 to SINGLE USER chat
  16. - CHECKINTERVALS=10 # checkIntervalS * 1000 > msgDelayMs * max count of alerts you are recieving, otherwise 429 errors

SILENCETIME - for how many hours silence will be set. Minimum value is 1.

Testing

Make a POST request to promegram to test alerting:

  1. {
  2. "status":"firing",
  3. "alerts":[
  4. {
  5. "status":"firing",
  6. "labels":{
  7. "alertname":"testPromegram",
  8. "instance":"testPromegram:9100",
  9. "job":"testPromegram",
  10. "severity":"warning"
  11. },
  12. "annotations":{
  13. "summary":"Job: testPromegram \nHost: testPromegram:9100 \nMessage: Test message \nMetric value: 0"
  14. },
  15. "startsAt":"2020-01-01T10:00:00.0Z",
  16. "endsAt":"0001-01-01T00:00:00Z"
  17. }
  18. ]
  19. }
  1. {
  2. "status": "resolved",
  3. "alerts": [
  4. {
  5. "status": "resolved",
  6. "labels": {
  7. "alertname": "testPromegram",
  8. "instance": "testPromegram:9100",
  9. "job": "testPromegram",
  10. "severity": "warning"
  11. },
  12. "annotations": {
  13. "summary": "Job: testPromegram \nHost: testPromegram:9100 \nMessage: Resolved message text \nMetric value: 1"
  14. },
  15. "startsAt": "2020-01-01T10:00:00.0Z",
  16. "endsAt": "2020-01-02T12:15:32.0Z"
  17. }
  18. ]
  19. }