Skip to content

Transfer alerts from Prometheus Alertmanager to Telegram chat and channels using webhook.

License

Notifications You must be signed in to change notification settings

MikeSafonov/prometheus-telegram-alert

Repository files navigation

Prometheus Alertmanager Telegram

This Spring Boot application helps to transfer alerts from Prometheus Alertmanager to Telegram chat and channels using webhooks and spring-boot-starter-prometheus-alerts

codecov Travis-CI Conventional Commits

Quality Gate Status Reliability Rating Maintainability Rating Security Rating

Bugs Code Smells Vulnerabilities

Duplicated Lines (%) Lines of Code Technical Debt

Getting started

Build from source

You can build application using following command:

./gradlew clean build

Testing

You can run unit test using following command:

./gradlew test

Configuration

According to Spring Docs you can override default application properties by put custom application.properties file in one of the following locations:

  • a /config subdirectory of the current directory
  • the current directory

The following properties can be configured in application.properties:

property description
prometheus.alertmanager.endpoint.base base url for POST request mapping for prometheus alert (default /alert)
server.port application port (default 8080)
prometheus.telegram.auth-token telegram bot auth token
prometheus.telegram.chat-id telegram chat id
prometheus.telegram.proxy.enable is use proxy (default false)
prometheus.telegram.proxy.host proxy host
prometheus.telegram.proxy.port proxy port

Running jar

You can run application using following command:

java -jar prometheus-telegram-alert.jar

You can test application by sending POST request with request body from test alerts/simple.json file.

Building and running app with Docker and docker-compose

  • For building the application and creation Docker image run

     docker-compose build
    
  • Customise configs with you preferred editor

    place configs in ./config directory

  • Run the docker image

     docker-compose up -d
    

Alertmanager configuration

route:
  receiver: 'telegram'
receivers:
- name: 'telegram'
  webhook_configs:
    - url: http://<application-host>:<application-port>/alert

Message format

You can create your own message format by implementing MessageConverter.java.

Holding secrets with HashiCorp Vault

Integration with Vault was made using spring-cloud-vault.

By default prometheus-telegram-alert integration with Vault disabled.

To enable integration with Vault pass following arguments to prometheus-telegram-alert run command:

java -jar prometheus-telegram-alert.jar --spring.cloud.vault.enabled=true --spring.cloud.vault.uri=<your vault uri> 
--spring.cloud.vault.token=<your vault token> --spring.cloud.vault.kv.application-name=<vault application name>

Contributing

Feel free to contribute. New feature proposals and bug fixes should be submitted as GitHub pull requests. Fork the repository on GitHub, prepare your change on your forked copy, and submit a pull request.

IMPORTANT!

Before contributing please read about Conventional Commits / Conventional Commits RU