Yet another Prometheus alertmanager's telegram bot
WARNING: this project uses the old Telegraf v3 library, and won't be updated to v4.
A bot that uses some fancy features from telegram as inline keyboards and replies to messages instead of the boring slash commands.
You can setup the bot using those environment variables:
variable | default | description |
---|---|---|
TELEGRAM_ADMINS | undefined |
comma-separated telegram user IDs, which the bot will talk to |
TELEGRAM_TOKEN | undefined |
your bot token |
TEMPLATE_FILE | default.tmpl |
template file path to use for messages |
EXTERNAL_URL | http://127.0.0.1:9093 |
endpoint to register the webhook on Telegram (useful for reversed-proxy deployments) |
INTERNAL_URL | undefined |
alertmanager URL to send API requests (default: uses externalURL provided on the alert) |
ALERTMANAGER_DB_PATH | data/alertmanager |
database path for alertmanager graph storage (LevelGraph) |
ALERTS_DB_PATH | data/alerts |
database path for alert storage (LevelDB) |
If running locally, nodejs and yarn, and install all dependencies:
yarn install
Otherwise you can use docker:
docker build -t wwmoraes/alertmanager-telegram-bot .
For formatting messages the bot uses doT + a
linebreak replacement. You can provide a custom template file by mounting your file
as a volume + setting the path on TEMPLATE_FILE
. All br
HTML tags will be
replaced by line breaks.
The alertmanager logic is also available as a Telegraf module to be used on other bots. You can do so with
import {
AlertManagerContext,
AlertManagerMiddleware,
setupAlertManagerContext,
} from "./AlertManager";
interface YourBotContext extends AlertManagerContext {}
const bot = new Telegraf<YourBotContext>("your-bot-token");
setupAlertManagerContext(bot);
bot.use(AlertManagerMiddleware);
yarn start
OR
docker run --rm -it --env-file=.env -p 8443:8443 wwmoraes/alertmanager-telegram-bot
The bot itself is very straightforward, and does most of the actions using inline
keyboards. You can enroll yourself to receive the AM alerts using /start
😄
The alertmanager middleware uses no slash commands, and instead automatically registers the given user IDs to receive notifications.
If using the full bot from this repository, then you can use:
/start
- registers yourself to receive the alerts/help
- well, halp 😂
It also responds to hi
and stickers as a "health check".