Skip to main content

Global Apache Airflow task-failure alerting to MAX and Telegram (cluster policy via entry point)

Project description

airflow-failure-alerts

Global Apache Airflow task-failure alerting to the MAX and Telegram messengers. Installed as a pip package, it uses a cluster policy (the airflow.policy entry point) to attach an on_failure_callback to every task in every DAG - the DAGs themselves are not modified.

It works in managed environments where there is no access to $AIRFLOW_HOME/config or the plugins folder: the package is loaded from site-packages.

How it works

pyproject.toml registers the entry point:

[project.entry-points."airflow.policy"]
_ = "airflow_failure_alerts.policy"

On startup (settings.initialize -> policy plugin loading) Airflow imports airflow_failure_alerts.policy and registers its @hookimpl task_policy. During DAG parsing that policy sets on_failure_callback = notify_failure on every task (existing callbacks are preserved). On terminal task failure (after all retries are exhausted) a message is sent to MAX and Telegram.

Installation

Requires Apache Airflow 2.6+ (the airflow.policy entry point).

pip install airflow-failure-alerts

In a managed Airflow service, add airflow-failure-alerts to the cluster pip dependencies and apply the change (this restarts the components and loads the policy).

Airflow Variables

Set these in the Airflow UI -> Admin -> Variables. Each channel is optional; if a channel is not configured, alerts go only to the configured one.

Variable Description
TELEGRAM_BOT_TOKEN Telegram bot token (from @BotFather)
TELEGRAM_CHAT_ID chat/channel id (channels look like -100...)
MAX_BOT_TOKEN MAX bot token (from @MasterBot)
MAX_CHAT_ID MAX chat id
ALERTS_ENV (optional) environment label added to the message, e.g. prod

Getting a chat_id

  • Telegram: add the bot to the chat/channel, post a message, open https://api.telegram.org/bot<TOKEN>/getUpdates and read chat.id. For channels the bot must be an administrator.
  • MAX: create a bot via @MasterBot, add it to the chat; chat_id arrives in webhook events or after the first interaction in the chat.

Verification

Add a DAG with a deliberately failing task (retries=0, raise) and trigger it manually. Both messengers receive a message of the form:

Airflow task failed [prod]
DAG: my_pipeline
Task: my_task
Run: manual__2026-01-01T...
Execution date: 2026-01-01T00:00:00+00:00
Try: 1
Error: <exception text>
Log: https://airflow.../log?...

If no alert arrives, inspect the task log (the "Post task execution logs" section): notify_failure records the reason there (Variables not set, HTTP error) and never fails the task.

MAX Bot API

POST https://platform-api.max.ru/messages?chat_id=<id>, header Authorization: <token> (the raw token, no Bearer prefix), body {"text": "..."}. Text limit is 4000 characters.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airflow_failure_alerts-0.1.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

airflow_failure_alerts-0.1.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file airflow_failure_alerts-0.1.1.tar.gz.

File metadata

  • Download URL: airflow_failure_alerts-0.1.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for airflow_failure_alerts-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f75d7c0f568ced2c6c9548c105e588dc6a2591b44c4a8486bee7d267a7dc5d8a
MD5 51d67e3bab7f139f11887b244ddb53ba
BLAKE2b-256 e6e563b534d84bf62f6f5062ff8b2aaa8df952dfe9450e1095368cc68c3e5d1f

See more details on using hashes here.

File details

Details for the file airflow_failure_alerts-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for airflow_failure_alerts-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aed263026f983951823b0eaa4afb9f81ce0cb69c9be1b73c2bca57a098519d49
MD5 31f535636e2364326fb5ec560ce8861e
BLAKE2b-256 def808ffa499f38228adce3f636dc23644ca087dc7e3ae385390567cb5973dfa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page