Sign inSign up

wwmoraes/alertmanager-telegram-bot

By wwmoraes

Updated almost 6 years ago

yet another alertmanager telegram bot

Image
0

100K+

wwmoraes/alertmanager-telegram-bot repository overview

Alertmanager telegram bot

Yet another Prometheus alertmanager's telegram bot

GitHub license GitHub top language GitHub repo size Docker Image Size (latest by date)

CII Best Practices GitHub last commit Build

Quality Gate Status Maintainability Rating Security Rating Reliability Rating

Coverage Vulnerabilities Bugs Code Smells Technical Debt

This is a work in progress, so take all functionalities with a grain of salt.

You can also jump directly to the docs.

Table of Contents

About

A bot that uses some fancy features from telegram as inline keyboards and replies to messages instead of the boring slash commands.

Getting Started

You can setup the bot using those environment variables:

variabledefaultdescription
TELEGRAM_ADMINSundefinedcomma-separated telegram user IDs, which the bot will talk to
TELEGRAM_TOKENundefinedyour bot token
TEMPLATE_FILEdefault.tmpltemplate file path to use for messages
EXTERNAL_URLhttp://127.0.0.1:9093endpoint to register the webhook on Telegram (useful for reversed-proxy deployments)
INTERNAL_URLundefinedalertmanager URL to send API requests (default: uses externalURL provided on the alert)
ALERTMANAGER_DB_PATHdata/alertmanagerdatabase path for alertmanager graph storage (LevelGraph)
ALERTS_DB_PATHdata/alertsdatabase path for alert storage (LevelDB)
Prerequisites

If running locally, nodejs and yarn, and install all dependencies:

yarn install

Otherwise you can use docker:

docker build -t wwmoraes/alertmanager-telegram-bot .
message template

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.

using it as a module on another bot

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);

Usage

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 😄

Slash commands

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".

Tag summary

Content type

Image

Digest

Size

63.1 MB

Last updated

almost 6 years ago

docker pull wwmoraes/alertmanager-telegram-bot