The Telegram bot API makes it really easy to use Telegram to send automated messages to yourself (or other people). A while ago I started to use this to send Icinga2 alerts to me.

Several other people implemented Icinga2-Telegram notifications by writing a simple Bash script. Most of the time this works but there are a few things I do not like about the Bash solutions:

  1. They use two scripts with almost the same content.
  2. Bash can screw up really bad when your alert output contains special characters.
  3. The Bash solutions are based on environment variables. This does not work natively with Icinga2 director as it only supports arguments in command definitions.

As a solution I wrote a small Python tool to handle Icinga2 notifications: icinga2telegram.

Screenshot of icinga2telegram

Obviously the Python implementation has a bigger footprint than the Bash solution. It requires a Python interpreter and installs several Python packages as dependencies. This could be a problem for an embedded system with very limited resources but most Icinga2 instances run on powerful machines and the icinga2telegram footprint does not matter there. In return you get a single maintainable and robust script that you can use for host and service notifications.

If you want to learn more about icinga2telegram you can check out the source code and documentation at GitHub.