Skip to content

Download Grafana panel as image, add watermark and send to telegram chat or channel.

License

Notifications You must be signed in to change notification settings

EIDiamond/grafana_image_downloader

Repository files navigation

Description

Download Grafana panel image by using Grafana Image Renderer plugin and send it to Telegram chat or channel.

Features

  • Request to render image for specified Grafana panel
  • Download the requested image
  • (Optional) Add watermark to image
  • (Optional) Send image to Telegram chat or channel

Dependencies

$ pip install requests
$ pip install pillow
$ pip install python-telegram-bot==13.15

Grafana requirements

Grafana Image Renderer must be installed before using the tool. Please read Plugin installation instruction carefully, especially if you are going to use Grafana Docker image.

Grafana Docker image

Please use the following instruction to run Grafana Docker image with the plugin installed. The instruction is working pretty well with Grafana 9.3.2 and latest Dockerfile

Grafana API Key

Please generate API Key for the tool.

Navigate: Configuration -> API Keys menu

HOW TO: Grafana installation

Here

Tested environment

  • Python 3.10
  • Grafana 9.3.2

Configuration

Configuration can be specified via settings.ini file.

Section GRAFANA

Specify Grafana host, port and api key

Section PANEL_IMAGE

Specify settings and panel to render:

  • DASHBOARD_UID - copy from dashboard url or dashboard json.
  • PANEL_ID - copy from panel view url or panel json.
  • FROM_DATE - recommendation is using quick ranges (example: now-1d etc.) or convert datetime to milliseconds
  • TO_DATE - recommendation is using quick ranges (example: now etc.) or convert datetime to milliseconds
  • ORG_ID - copy from panel view url
  • WIDTH, HEIGHT, TZ - as you wish

Section TEMP_STORAGE

Specify file path to save rendered image. Note: Directory must be created.

Section WATERMARK

Specify settings to add watermark on panel image:

  • TEXT - watermark text. Keep empty to disable functionality.
  • FONT and FONT_SIZE - text font settings.
  • MARGIN - margin size for watermark

Section TELEGRAM

Specify settings to send image to Telegram chat or channel:

  • BOT_TOKEN - telegram bot token.
  • CHAT_ID - id of chat or channel.
  • IMAGE_DESCRIPTION - optional description for image

Command line arguments

  • --dashboard - dashboard uid
  • --panel - panel id
  • --f - from date
  • --t - to date
  • --file - path to file

Watermark

Watermark is optional and can be disabled if TEXT (watermark text) is empty.

Watermark is drawing in the bottom right corner.

Telegram

Telegram is optional and can be disabled if BOT_TOKEN and\or CHAT_ID are empty.

Telegram bot can be easily created in a few seconds via @BotFather.
Please note the easiest way to find chat_id.

Logging

All logs are written in logs/downloader.log. Any kind of settings can be changed in main.py code

Project change log

Here

Disclaimer

The author is not responsible for any errors or omissions obtained from the use of this tool.

About

Download Grafana panel as image, add watermark and send to telegram chat or channel.

Topics

Resources

License

Stars

Watchers

Forks

Languages