项目作者: metalmatze

项目描述 :
Bot for Prometheus' Alertmanager
高级语言: Go
项目地址: git://github.com/metalmatze/alertmanager-bot.git
创建时间: 2016-11-26T00:44:30Z
项目社区:https://github.com/metalmatze/alertmanager-bot

开源协议:MIT License

下载


⚠️ This project is deprecated ⚠️

Alertmanager v0.24+ has Telegram support out of the box. Going forward, please simply use Alertmanager instead of this bot.
This project will be archived at the end of July 2022.

Until then you can ask questions in this GitHub Discussion.

Bot for Prometheus’ Alertmanager

Docker Pulls
Go Report Card

This is the Alertmanager bot for
Prometheus that notifies you on alerts.
Just configure the Alertmanager to send Webhooks to the bot and that’s it.

Additionally you can always send commands to get up-to-date information from the alertmanager.

Why?

Alertmanager already integrates a lot of different messengers as receivers for alerts.
I want to extend this basic functionality.

Previously the Alertmanager could only talk to you via a chat, but now you can talk back via commands.
You can ask about current ongoing alerts and silences.
In the future I plan to also support silencing via the chat, so you can silences after getting an alert from within the chat.
A lot of other things can be added!

Messengers

Right now it supports Telegram, but I’d like to add more in the future.

Commands

/start

Hey, Matthias! I will now keep you up to date!
/help

/stop

Alright, Matthias! I won’t talk to you again.
/help

/alerts

🔥 FIRING 🔥
NodeDown (Node scraper.krautreporter:8080 down)
scraper.krautreporter:8080 has been down for more than 1 minute.
Started: 1 week 2 days 3 hours 50 minutes 42 seconds ago

🔥 FIRING 🔥
monitored_service_down (MONITORED SERVICE DOWN)
The monitoring service ‘digitalocean-exporter’ is down.
Started: 10 seconds ago

/silences

NodeDown 🔕
job="ranch-eye" monitor="exporter-metrics" severity="page"
Started: 1 month 1 week 5 days 8 hours 27 minutes 57 seconds ago
Ends: -11 months 2 weeks 2 days 19 hours 15 minutes 24 seconds

RancherServiceState 🔕
job="rancher" monitor="exporter-metrics" name="scraper" rancherURL="http://rancher.example.com/v1" severity="page" state="inactive"
Started: 1 week 2 days 3 hours 46 minutes 21 seconds ago
Ends: -3 weeks 1 day 13 minutes 24 seconds

/chats

Currently these chat have subscribed:
@MetalMatze

/status

AlertManager
Version: 0.5.1
Uptime: 3 weeks 1 day 6 hours 15 minutes 2 seconds
AlertManager Bot
Version: 0.4.3
Uptime: 3 weeks 1 hour 17 minutes 19 seconds

/help

I’m a Prometheus AlertManager Bot for Telegram. I will notify you about alerts.
You can also ask me about my /status, /alerts & /silences

Available commands:
/start - Subscribe for alerts.
/stop - Unsubscribe for alerts.
/status - Print the current status.
/alerts - List all alerts.
/silences - List all silences.
/chats - List all users and group chats that subscribed.

Installation

Docker

docker pull metalmatze/alertmanager-bot:0.4.3

Start as a command:

Bolt Storage

  1. docker run -d \
  2. -e 'ALERTMANAGER_URL=http://alertmanager:9093' \
  3. -e 'BOLT_PATH=/data/bot.db' \
  4. -e 'STORE=bolt' \
  5. -e 'TELEGRAM_ADMIN=1234567' \
  6. -e 'TELEGRAM_TOKEN=XXX' \
  7. -v '/srv/monitoring/alertmanager-bot:/data' \
  8. --name alertmanager-bot \
  9. metalmatze/alertmanager-bot:0.4.3

Consul Storage

  1. docker run -d \
  2. -e 'ALERTMANAGER_URL=http://alertmanager:9093' \
  3. -e 'CONSUL_URL=localhost:8500' \
  4. -e 'STORE=consul' \
  5. -e 'TELEGRAM_ADMIN=1234567' \
  6. -e 'TELEGRAM_TOKEN=XXX' \
  7. --name alertmanager-bot \
  8. metalmatze/alertmanager-bot:0.4.3

ETCD Storage

  1. docker run -d \
  2. -e 'ALERTMANAGER_URL=http://alertmanager:9093' \
  3. -e 'ETCD_URL=localhost:2379' \
  4. -e 'STORE=etcd' \
  5. -e 'ETCD_TLS_INSECURE=true' \
  6. -e 'TELEGRAM_ADMIN=1234567' \
  7. -e 'TELEGRAM_TOKEN=XXX' \
  8. --name alertmanager-bot \
  9. metalmatze/alertmanager-bot:0.4.2

docker-compose:

  1. networks:
  2. alertmanager-bot: {}
  3. services:
  4. alertmanager-bot:
  5. command:
  6. - --alertmanager.url=http://localhost:9093
  7. - --log.level=info
  8. - --store=bolt
  9. - --bolt.path=/data/bot.db
  10. environment:
  11. TELEGRAM_ADMIN: "1234"
  12. TELEGRAM_TOKEN: XXXXXXX
  13. image: metalmatze/alertmanager-bot:0.4.3
  14. networks:
  15. - alertmanager-bot
  16. ports:
  17. - 8080:8080
  18. restart: always
  19. volumes:
  20. - ./data:/data
  21. version: "3"

Kubernetes:

  1. apiVersion: v1
  2. items:
  3. - apiVersion: v1
  4. data:
  5. admin: MTIzNA==
  6. token: WFhYWFhYWA==
  7. kind: Secret
  8. metadata:
  9. labels:
  10. app.kubernetes.io/name: alertmanager-bot
  11. name: alertmanager-bot
  12. namespace: monitoring
  13. type: Opaque
  14. - apiVersion: v1
  15. kind: Service
  16. metadata:
  17. labels:
  18. app.kubernetes.io/name: alertmanager-bot
  19. name: alertmanager-bot
  20. namespace: monitoring
  21. spec:
  22. ports:
  23. - name: http
  24. port: 8080
  25. targetPort: 8080
  26. selector:
  27. app.kubernetes.io/name: alertmanager-bot
  28. - apiVersion: apps/v1
  29. kind: StatefulSet
  30. metadata:
  31. labels:
  32. app.kubernetes.io/name: alertmanager-bot
  33. name: alertmanager-bot
  34. namespace: monitoring
  35. spec:
  36. podManagementPolicy: OrderedReady
  37. replicas: 1
  38. selector:
  39. matchLabels:
  40. app.kubernetes.io/name: alertmanager-bot
  41. serviceName: alertmanager-bot
  42. template:
  43. metadata:
  44. labels:
  45. app.kubernetes.io/name: alertmanager-bot
  46. name: alertmanager-bot
  47. namespace: monitoring
  48. spec:
  49. containers:
  50. - args:
  51. - --alertmanager.url=http://localhost:9093
  52. - --log.level=info
  53. - --store=bolt
  54. - --bolt.path=/data/bot.db
  55. env:
  56. - name: TELEGRAM_ADMIN
  57. valueFrom:
  58. secretKeyRef:
  59. key: admin
  60. name: alertmanager-bot
  61. - name: TELEGRAM_TOKEN
  62. valueFrom:
  63. secretKeyRef:
  64. key: token
  65. name: alertmanager-bot
  66. image: metalmatze/alertmanager-bot:0.4.3
  67. imagePullPolicy: IfNotPresent
  68. name: alertmanager-bot
  69. ports:
  70. - containerPort: 8080
  71. name: http
  72. resources:
  73. limits:
  74. cpu: 100m
  75. memory: 128Mi
  76. requests:
  77. cpu: 25m
  78. memory: 64Mi
  79. volumeMounts:
  80. - mountPath: /data
  81. name: data
  82. restartPolicy: Always
  83. volumes:
  84. - name: data
  85. persistentVolumeClaim:
  86. claimName: alertmanager-bot
  87. volumeClaimTemplates:
  88. - apiVersion: v1
  89. kind: PersistentVolumeClaim
  90. metadata:
  91. labels:
  92. app.kubernetes.io/name: alertmanager-bot
  93. name: alertmanager-bot
  94. namespace: monitoring
  95. spec:
  96. accessModes:
  97. - ReadWriteOnce
  98. resources:
  99. requests:
  100. storage: 1Gi
  101. storageClassName: standard
  102. kind: List

Ansible

If you prefer using configuration management systems (like Ansible) you might be interested in the following role: mbaran0v.alertmanager-bot

Build from source

GO111MODULE=on go get github.com/metalmatze/alertmanager-bot/cmd/alertmanager-bot

Configuration

ENV Variable CLI flag Required Default Description
ALERTMANAGER_URL alertmanager.url http://localhost:9093 Address of the alertmanager
BOLT_PATH bolt.path /tmp/bot.db Path on disk to the file where the boltdb is stored
CONSUL_URL consul.url localhost:8500 The URL to use to connect with Consul
LISTEN_ADDR listen.addr 0.0.0.0:8080 Address that the bot listens for webhooks
STORE store The type of the store to use, choose from bolt (local), consul or etcd (distributed)
STORE_KEY_PREFIX storeKeyPrefix telegram/chats Key prefix for the store
ETCD_URL etcd.url localhost:2379 The URL that’s used to connect to the ETCD store
ETCD_TLS_INSECURE etcd.tls.insecure false Use TLS connection to ETCD store or not
ETCD_TLS_INSECURE_SKIP_VERIFY etcd.tls.insecureSkipVerify Skip server certificates verification
ETCD_TLS_CERT etcd.tls.cert Path to the TLS cert file
ETCD_TLS_KEY etcd.tls.key Path to the TLS key file
ETCD_TLS_CACERT etcd.tls.ca Path to the TLS trusted CA cert file
LOG_JSON log.json Tell the application to log json and not key value pairs
LOG_LEVEL log.level info The log level to use for filtering logs. Possible values: debug, info, warn, error
TELEGRAM_ADMIN telegram.admin The Telegram user id for the admin (not the bot itself, you, the user). The bot will only reply to messages sent from an admin. All other messages are dropped and logged on the bot’s console. Your user id you can get from @userinfobot.
TELEGRAM_TOKEN telegram.token Token you get from @botfather
TEMPLATE_PATHS template.paths /templates/default.tmpl Path to custom message templates

Authentication

Additional users may be allowed to command the bot by giving multiple instances
of the --telegram.admin command line option or by specifying a
newline-separated list of telegram user IDs in the TELEGRAM_ADMIN environment
variable.

  1. - TELEGRAM_ADMIN="**********\n************"
  2. --telegram.admin=1 --telegram.admin=2

Alertmanager Configuration

Now you need to connect the Alertmanager to send alerts to the bot.
A webhook is used for that, so make sure your LISTEN_ADDR is reachable for the Alertmanager.

For example add this to your alertmanager.yml configuration:

  1. receivers:
  2. - name: 'alertmanager-bot'
  3. webhook_configs:
  4. - send_resolved: true
  5. url: 'http://alertmanager-bot:8080'

Development

Build the binary using make:

  1. make

In case you have $GOPATH/bin in your $PATH you can now simply start the bot by running:

  1. alertmanager-bot

Missing

Commands
  • /silence - show a specific silence
  • /silence_del - delete a silence by command
  • /silence_add - add a silence for a alert by command
More Messengers

At the moment I only implemented Telegram, because it’s so freakin’ easy to do.

Messengers considered to add in the future:

If one is missing for you just open an issue.