Skip to main content

Datadog to Telegram webhook

Provides a basic authenticated webhook to forward alerts from Datadog to Telegram

Requirements

  • A Datadog account
  • A Telegram account

Quickstart

Datadog

  1. Set up a Datadog Webhook integration
  2. Create a new webhook with the following URL:
    https://<your-server-host>:8080/telegram/<telegram_chat_id>
    
  3. Use basic authentication credentials matching the ones configured on the server (see below)
  4. Use the webhook in your Datadog monitors by adding @webhook-<webhook_name> in the notification body

Telegram

  1. Create a Telegram bot via BotFather and note the API token
  2. Get your chat ID by messaging your bot and visiting:
    https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
    
    The chat.id field in the response is your chat ID

Webhook server

  1. Install dependencies:

    uv sync 
    
  2. Configure the following secrets either as environment variables or as Docker secrets in /var/run/secrets/:

    Environment Variable Docker Secret Description
    WEBHOOK_FLASK_SECRET_KEY webhook_flask_secret_key Flask secret key for sessions
    WEBHOOK_BASIC_AUTH_USERNAME webhook_basic_auth_username Basic auth username
    WEBHOOK_BASIC_AUTH_PASSWORD webhook_basic_auth_password Basic auth password
    WEBHOOK_TELEGRAM_BOT_API_TOKEN webhook_telegram_bot_api_token Telegram bot API token
  3. Run the server:

    python app.py
    

    The server starts on 127.0.0.1:8080 by default

Example curl:

curl -X POST -H "Content-Type: application/json"\
 -d '{
    "body": "%%%\n## What happened\n\nLorem ipsum\n\n- - - - - - - - - - - - -\n[[View Security Signal](https://app.datadoghq.eu/security/signals?event=AQAAAZ1Ywej15QMmZwAAAABBWjFZd2VqMUFBQ19SNDg2NGFTSW9BQUE&start=1775308796341&end=1775312396341&utm_source=notification&utm_medium=email,webhook)]\n@webhook-telegram_webhook\n%%%",
    "last_updated": "1775320543",
    "event_type": "api",
    "title": "Alert",
    "date": "1775320543",
    "org": {
        "id": "12345",
        "name": "ORG_NAME"
    },
    "id": "54321"
}' -u "${WEBHOOK_BASIC_AUTH_USERNAME}:${WEBHOOK_BASIC_AUTH_PASSWORD}" http://localhost:8080/telegram/${TELEGRAM_CHATID}

Documentation

publish

uv version VERSION
uv build
uv publish --token=$(op read "op://Private/PyPI/publish_token")

Contribute

Open to any PR/comments/issues

Licence

Copyright 2023 DaisukiXCI

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for webhook_server 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for webhook_server 1.0.3
File Size Uploaded Provenance
webhook_server-1.0.3.tar.gz 4.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for webhook_server 1.0.3
File Interpreter ABI Platform
webhook_server-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / webhook_server-1.0.3.tar.gz

Download URL webhook_server-1.0.3.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
68527bae2a021b6a560fd37d9138601adc0d42a6a32074ba13be4cbdf39a5a91
BLAKE2b-256 checksum
How to use checksums
0f2c933a7907a745d06da1d93d2203a10be6fe5c9f1971155125ff909e422d27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / webhook_server-1.0.3-py3-none-any.whl

Download URL webhook_server-1.0.3-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f35191704a5857540c05db4a2711c95878450a2499c4fb9cba2d9422a39fa89f
BLAKE2b-256 checksum
How to use checksums
dacac96dfd32b86936ad72860450ce438eea34f25e326afa213074f605a2cfc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for webhook_server 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page