项目作者: wwmoraes

项目描述 :
yet another alertmanager telegram bot
高级语言: TypeScript
项目地址: git://github.com/wwmoraes/alertmanager-telegram-bot.git
创建时间: 2020-06-13T16:55:41Z
项目社区:https://github.com/wwmoraes/alertmanager-telegram-bot

开源协议:MIT License

下载


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

WARNING: this project uses the old Telegraf v3 library, and won’t be
updated to v4.

Table of Contents

" class="reference-link">About

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

" class="reference-link">Getting Started

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)

Prerequisites

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

  1. yarn install

Otherwise you can use docker:

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

  1. import {
  2. AlertManagerContext,
  3. AlertManagerMiddleware,
  4. setupAlertManagerContext,
  5. } from "./AlertManager";
  6. interface YourBotContext extends AlertManagerContext {}
  7. const bot = new Telegraf<YourBotContext>("your-bot-token");
  8. setupAlertManagerContext(bot);
  9. bot.use(AlertManagerMiddleware);

" class="reference-link">Usage

  1. yarn start

OR

  1. 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”.