Prometheus Alertmanager send alerts via Telegram

DPBD90
1 min readFeb 24, 2021

--

Crerate Telegrambot

  1. Create Telegrambot

Follow the guilde in Telegram docs: https://core.telegram.org/bots#creating-a-new-bot

You will recieve telegram token id. We will store it and use later.

2. Create new group to receive alerts then add bot into group.

Alter bot join to group, you will recieve chat id of group

Chat id is ‘-4xxxxxxxx’

Create and build telegrambot docker image

  1. Clone Telegram bot source code from github
git clone github.com/inCaller/prometheus_bot

2. Move into source code

cd prometheus_bot/

3. Edit Dockerfile

4. Build docker image

docker build -t tienbm90/prometheus-bot:0.0.1

Configure telegrambot

  1. Create folder to store telegrambot configuration
mkdir telegrambot

2. Create telegrambot configuration file telegrambot/config.yaml:

3. Define alert format with telegrambot/template.tmpl:

Configure Alertmanager

Alert manager configuration file:

Replace telegram-chat-id with the number you got from your bot, with -. To use multiple chats just add more receivers.

Create docker-compose.yml file

Configure prometheus to use alertmanager:

alerting:
alertmanagers:
— static_configs:
— targets:
# Alertmanager’s default port is 9093
— 10.240.183.8:9093

Start alertmanager and telegrambot

docker-compose up -d

Verify and check result

You will recieve message like this:

Type: Host out of memory
Summary: Host out of memory (instance x.x.x.x:y)
Alertname: HostOutOfMemory
Instance: x.x.x.x:y
Serverity: information
Status: firing

--

--

DPBD90
DPBD90

Written by DPBD90

I'm an engineer. I love to work on data and open-source systems.

Responses (7)