{"id":19084379,"url":"https://github.com/pawsanie/telegram_grafana_report_bot","last_synced_at":"2026-04-12T08:40:28.004Z","repository":{"id":258946594,"uuid":"823780704","full_name":"Pawsanie/Telegram_Grafana_Report_Bot","owner":"Pawsanie","description":"The repository contains the source code of the Bot that sends users Grafana graphics upon request in channels or private messages in Telegram. The bot can interact with any number of handles from any number of Grafans. All of them are added through the JSON configuration.","archived":false,"fork":false,"pushed_at":"2024-10-21T06:59:12.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-21T09:51:41.008Z","etag":null,"topics":["grafana","grafana-dashboard","pytelegrambotapi","python","telegram","telegram-bot"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Pawsanie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-03T17:45:12.000Z","updated_at":"2024-10-21T06:59:16.000Z","dependencies_parsed_at":"2024-10-23T01:41:39.575Z","dependency_job_id":null,"html_url":"https://github.com/Pawsanie/Telegram_Grafana_Report_Bot","commit_stats":null,"previous_names":["pawsanie/telegram_grafana_report_bot"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Pawsanie/Telegram_Grafana_Report_Bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pawsanie%2FTelegram_Grafana_Report_Bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pawsanie%2FTelegram_Grafana_Report_Bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pawsanie%2FTelegram_Grafana_Report_Bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pawsanie%2FTelegram_Grafana_Report_Bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pawsanie","download_url":"https://codeload.github.com/Pawsanie/Telegram_Grafana_Report_Bot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pawsanie%2FTelegram_Grafana_Report_Bot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31709294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-12T06:22:27.080Z","status":"ssl_error","status_checked_at":"2026-04-12T06:21:52.710Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grafana","grafana-dashboard","pytelegrambotapi","python","telegram","telegram-bot"],"created_at":"2024-11-09T02:51:08.472Z","updated_at":"2026-04-12T08:40:27.990Z","avatar_url":"https://github.com/Pawsanie.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telegram Grafana Report Bot\n\nThe repository contains the source code of the Bot that sends users Grafana graphics upon request in channels or private messages in Telegram.\u003cbr\u003e\nThe bot can interact with any number of handles from any number of Grafans.\u003cbr\u003e\nAll of them are added through the JSON configuration.\u003cbr\u003e\n\nThe repository also contains an example deployment for Docker-Compose.\u003cbr\u003e\nIncluding two test graphics.\n\n## Disclaimer:\n:warning:**Using** some or all of the elements of this code, **You** assume **responsibility for any consequences!**\u003cbr\u003e\n\n:warning:The **licenses** for the technologies on which the code **depends** are subject to **change by their authors**.\u003cbr\u003e\u003cbr\u003e\n\n## Contents:\n### Dependencies:\n* [Required](#Required)\n* [Required Packages](#Required-Packages)\n* [Installing the Required Packages](#Installing-the-Required-Packages)\n\n### Pre-deployment steps:\n* [Telegram Bot registration](#Telegram-Bot-registration)\n* [Telegram channel settings](#Telegram-channel-settings)\n* [Crate Grafana Technical User](#Crate-Grafana-Technical-User)\n* [Add new handlers to Config file](#Add-new-handlers-to-Config-File)\n\n### Deployment:\n* [Deploy with Docker-Compose](#Deploy-with-Docker-Compose)\n* [Run on Bare-Metal or Virtual Machine](#Run-on-Bare-Metal-or-Virtual-Machine)\n* Run on local machine: see th paragraph above.\n\n### Interacting with the Bot:\n* [How to call the Bot](#How-to-call-the-Bot)\n\n___\n\u003cbr\u003e\n\n## Required:\nThe application code is written in python and obviously depends on it.\u003cbr\u003e\n**Python** version 3.10 [Python Software Foundation License / (with) Zero-Clause BSD license]:\n* :octocat:[Python GitHub](https://github.com/python)\n* :bookmark_tabs:[Python internet page](https://www.python.org/)\n\n## Required Packages:\n**aiohttp** [Apache License version 2.0]:\u003cbr\u003e\nUsed to perform asynchronous requests.\n* :octocat:[Aiohttp GitHub](https://github.com/aio-libs/aiohttp)\n* :bookmark_tabs:[Aiohttp pypi internet page](https://pypi.org/project/aiohttp/)\n\n**pyTelegramBotAPI** [GPL-2.0 license]:\u003cbr\u003e\nUsed to interact with the telegram api\n* :octocat:[pyTelegramBotAPI GitHub](https://github.com/eternnoir/pyTelegramBotAPI)\n* :bookmark_tabs:[pyTelegramBotAPI pypi internet page](https://pypi.org/project/pyTelegramBotAPI/)\n\n## Installing the Required Packages:\n```bash\npip install aiohttp\npip install pyTelegramBotAPI\n```\n\n## Pre-deployment steps\n\n### Telegram Bot registration:\nTo start the bot registration process, you must **have** a [Telegram](https://telegram.org/) **account**.\n* **Log in** to Telegram in any way convenient for you and write to the **[@BotFather](https://t.me/BotFather)** bot.\u003cbr\u003e\n* Write to the bot:\n    ```text\n    /start\n    ```\n* Next write him:\n    ```text\n    /newbot\n    ```\n* After that, write what your bot will be called. This name will be **displayed** as its name in the **profile**.\u003cbr\u003e\nThen you will need to write the **unique bot ID**, according to the **instructions**.\u003cbr\u003e\nAs a result, you will receive a unique **token** for your bot. It will be needed for program **configuration** file.\u003cbr\u003e\nMore details about its use can be found in paragraphs «[Deploy-with-Docker-Compose](#Deploy-with-Docker-Compose)» \u003cbr\u003e\nand «[Run on Bare-Metal or Virtual Machine](#Run-on-Bare-Metal-or-Virtual-Machine)».\n\n### Telegram channel settings:\nCreate a channel in Telegram in any way convenient for you.\n* Add your bot to the channel and make him an administrator in it.\u003cbr\u003e\nRemove all unnecessary rights from him: the ability to write messages to the channel is enough.\n* Open Telegram [Web-version](https://web.telegram.org/)\u003cbr\u003e\nFind your chanel and copy **channel id** in web url after **#-** symbols.\u003cbr\u003e\nAs exemple **#-0000000000**.\u003cbr\u003e\nIt will be needed for program **configuration** file.\n* More details about its use can be found in paragraphs «[Deploy with Docker-Compose](#Deploy-with-Docker-Compose)» \u003cbr\u003e\nand «[Run on Bare-Metal or Virtual Machine](#Run-on-Bare-Metal-or-Virtual-Machine)».\n\n### Create Grafana Technical User:\nThe creation process will be described for version **11.2.2**. In other versions the interface may change.\u003cbr\u003e\nBut it most likely will not change in the future.\n* Open your Grafana web interface.\n* On the left side of the page, select **Administration**.\n* Select **Users and access**.\n* Next select **Service accounts**.\n* In the upper right part of the page, click \"**Add service account**\".\n* Enter a descriptive **name** under which you will be able to easily find this service account in the list of others.\u003cbr\u003e\nAnd select **Viewer** rights for him.\n* On the right side, in the token table, click \"**Add service account token**\".\u003cbr\u003e\n* Click \"**Generate token**\"\u003cbr\u003e\nBe sure to **copy the token immediately** after this.\u003cbr\u003e\nIt will only be **shown once**.\u003cbr\u003e\nIt will be needed for program **configuration** file.\u003cbr\u003e\nMore details about its use can be found in paragraphs «[Deploy with Docker-Compose](#Deploy-with-Docker-Compose)» \u003cbr\u003e\nand «[Run on Bare-Metal or Virtual Machine](#Run-on-Bare-Metal-or-Virtual-Machine)».\n\n### Add new handlers to Config file:\nSince the complete filling of the configuration file depends on how you will **deploy** the application, \u003cbr\u003e\nlet's first look at how to add **handlers** for the Bot.\u003cbr\u003e\n**Config file location:**\u003cbr\u003e\n**./**:open_file_folder:Telegram_Grafana_Report_Bot\u003cbr\u003e\n   └── :page_facing_up:config.json\u003cbr\u003e\n**Example of handler in config.json file:**\n```json\n{\n    \"Grafana\": [\n        {\n          \"token\": \"${GRAFANA_TOKEN}\",\n          \"url\": \"${GRAFANA_URL}\",\n          \"handlers\": {\n            \n            \"e1\": {\n              \"dashboard_uid\": \"ee0jj9k1l8zr4d\",\n              \"kiosk_status\": true,\n              \"time_zone\": \"Europe%2FMoscow\",\n              \"panel\": {\n                \"id\": 1,\n                \"width\": 560,\n                \"height\": 480\n              },\n              \"handle_description\": \"Example dashboard 01\"\n            },\n            ...\n            \n          }\n        },\n      {...}\n    ]\n}\n```\n* **token** - the value of this key is a token with which the bot can connect to Grafana.\u003cbr\u003e\nMore details on how to get this token were written above, in paragraph «[Crate Grafana Technical User](#Crate-Grafana-Technical-User)».\u003cbr\u003e\nWhen to replace the default value is described in the «[Deployment](#Deployment)» paragraph.\u003cbr\u003e\nHowever, it is important to mention now that this value is unique for each Grafana you want to use.\n* **url** - it can be either an IP address or a DNS name, depending on your settings.\u003cbr\u003e\nWhen to replace the default value is described in the «[Deployment](#Deployment)» paragraph.\u003cbr\u003e\nSimilar to the previous key, this value will be unique for each Grafana you want to use.\u003cbr\u003e\nBelow is an example of an url link from where you can get this value for configuration if necessary.\n* **Handlers** - the value of this key is a nested dictionary that **lists all handles** settings.\u003cbr\u003e\nThe embedded key is the **handle** itself that the user will need to call.\u003cbr\u003e\nIn this example it is called \"**e1**\".\u003cbr\u003e\nAccordingly, it will be called in the chat with the bot by the command \"**/e1**\".\u003cbr\u003e\nYou need to come up with this value yourself.\n  * **dashboard_uid** - this is a unique identifier of the dashboard in Grafana.\u003cbr\u003e\nThe name of the dashboard and graph, although mentioned in the URL, does not really matter and may not even be added.\u003cbr\u003e\nOnly this parameter and the panel ID have matter.\u003cbr\u003e\nBelow is an example of an **url** link where you can **get** this value from your graph.\n  * **kiosk_status** - is responsible for whether to show the Grafana interface when rendering an image, or not.\u003cbr\u003e\nValue is a **boolean** constant.\n  * **time_zone** - responsible for which time zone to generate graphs.\u003cbr\u003e\nYou can choose any convenient standard time zone.\u003cbr\u003e\nTheir list is in Grafana.\u003cbr\u003e\nTo open it, click on the time settings for which to display graphs in the upper right corner.\u003cbr\u003e\nClick \"**Change time settings**\"\u003cbr\u003e\nNext click \"**Type to search...**\"\u003cbr\u003e\nTime zones are determined by the format **Country/City**.\u003cbr\u003e\nYou need to swap \"**/**\" symbol to \"**%2F**\".\u003cbr\u003e\nYou can also write IANA by analogy. As example **Etc%2FUTC**.\n  * **panel** - the panel is the actual graph that is being drawn.\u003cbr\u003e\nEach dashboard can have multiple panels, each with its own number.\u003cbr\u003e\nThe key value is a nested dictionary describing the panel.\n    * **id** - is responsible for which graph to draw.\u003cbr\u003e\nBelow is an example of an **url** link where you can **get** this value from your graph.\n    * **width** - width of the generated image.\u003cbr\u003e\nYou need to come up with this value yourself.\n    * **height** - height of the generated image.\u003cbr\u003e\nYou need to come up with this value yourself.\n  * **handle_description** - a description of each will be generated in the welcome message \u003cbr\u003e\nand added to each picture in caption, for ease of searching through messages.\u003cbr\u003e\nYou need to come up with this value yourself.\n\nAll the settings described above, except for the token, are responsible for the link that will return the image to us.\u003cbr\u003e\nFor simplicity, they are substituted in the example:\u003cbr\u003e\u003cbr\u003e\n**url**:3000/render/d/**dashboard_uid**/dashboard_name?orgId=1\u0026refresh=10s\u0026from=time\u0026to=time\u0026viewPanel=**id**\u0026width=**with**\u0026height=**height**\u0026tz=**time_zone**\u0026**kiosk_status**\u003cbr\u003e\u003cbr\u003e\nPlease note that organization ID generation is not implemented.\u003cbr\u003e\nIts **value** is hardcoded as **1**.\n\n## Deployment\n\n### Deploy with Docker-Compose:\n\nThe repository contains a test example that will deploy with a sample of Grafana for an example of using the bot,\u003cbr\u003e\na Grafana render container, and 2 graphs.\u003cbr\u003e\nHowever, you will have to customize one or more files.\u003cbr\u003e\nPlease note that the example creates a persistent Docker Volume **grafana_persistent_storage**.\u003cbr\u003e\nAnd since you don't have a Grafana token for the technical user account to begin with,\u003cbr\u003e\nyou'll have to run the build twice, deleting the containers after the first one.\n\n**Files location:**\u003cbr\u003e\n**./**:open_file_folder:Telegram_Grafana_Report_Bot\u003cbr\u003e\n   ├── :file_folder:Docker\u003cbr\u003e\n   │        ├── :page_facing_up:.env\u003cbr\u003e\n   │        └── :page_facing_up:docker-compose.yml\u003cbr\u003e\n   ├── :file_folder:Source_code\u003cbr\u003e\n   │        └── :page_facing_up:entry_point.sh\u003cbr\u003e\n   └── :page_facing_up:config.json\u003cbr\u003e\n\nFirst, you need to create a \"**.env**\"\" file with environment variables to add to the \"**Docker**\" folder.\u003cbr\u003e\n**.env file example:**\u003cbr\u003e\n```text\n# .env\nTELEGRAM_BOT_TOKEN=...\nTELEGRAM_CHANNEL_ID=...,...\nTELEGRAM_BOT_DM_WHITE_LIST=...,...\nTELEGRAM_BOT_CHANNEL_WHITE_LIST=...,...,...\n\nGRAFANA_TOKEN=...\nGRAFANA_URL=http://example_grafana:3000\nGRAFANA_RENDER_SERVER_URL=http://grafana_renderer:8081/render\nGRAFANA_ADMIN_USER=...\nGRAFANA_ADMIN_PASSWORD=...\n```\n* TELEGRAM_BOT_DM_WHITE_LIST - List of names of trusted users in telegram, written separated by commas without spaces.\n* TELEGRAM_BOT_CHANNEL_WHITE_LIST - List of names of trusted users in telegram, written separated by commas without spaces.\n\nIn Telegram usernames start with the \"**@**\" symbol.\u003cbr\u003e\nBut you must specify the username without it.\n\n* TELEGRAM_BOT_TOKEN - the **token** we received by performing the steps in «[Telegram Bot registration](#Telegram-Bot-registration)» paragraph.\n* TELEGRAM_CHANNEL_ID - list of channels where it is permissible to call the bot, written separated by commas without spaces.\u003cbr\u003e\nHow to find out the channel name is described in «[Telegram channel settings](#Telegram-channel-settings)» paragraph.\n* GRAFANA_TOKEN - the **token** we received by performing the steps in «[Crate Grafana Technical User](#Crate-Grafana-Technical-User)» paragraph.\n* GRAFANA_URL - ip address or DNS name of yore Grafana instance.\n* GRAFANA_RENDER_SERVER_URL - ip address or DNS name of yore Grafana-Render instance.\n* GRAFANA_ADMIN_USER - name of Grafana root user.\n* GRAFANA_ADMIN_PASSWORD - Grafana root user password.\nEach instance of your Grafana or render servers needs its own environment variables.\u003cbr\u003e\nAdditional instances will also need to be added in **docker-compose.yaml** and **entry_point.sh**.\u003cbr\u003e\nHow to add new handles, including grafana instances, can be read in the «[Add new handlers to Config file](#Add-new-handlers-to-Config-file)» paragraph.\n\nIf you do not want to use more than one Grafana, you just need to replace the data in the file with your own, according to the rules described above.\u003cbr\u003e\nThere is no point in describing the structure of these files listed at the beginning of the paragraph in more detail, \u003cbr\u003e\nsince you will literally need to make duplicates of these variables for new grafana instances, but under different names.\n\n**Example of using Docker variables in config.json file:**\u003cbr\u003e\n```json\n{\n  \"Telegram_Bot\":\n  {\n    \"token\": \"${TELEGRAM_BOT_TOKEN}\",\n    \"dm_white_list\": [\n      \"${TELEGRAM_BOT_DM_WHITE_LIST}\"\n    ],\n    \"channel_id\": [\n      \"${TELEGRAM_CHANNEL_ID}\"\n    ],\n    \"channel_white_list\": [\n      \"${TELEGRAM_BOT_CHANNEL_WHITE_LIST}\"\n    ],\n    \"block_forwarding_messages\": true\n  },\n\n  \"Grafana\": [\n    {\n      \"token\": \"${GRAFANA_TOKEN}\",\n      \"url\": \"${GRAFANA_URL}\",\n      \"handlers\": {...}\n    }\n  ]\n}\n```\nMore details about the keys and values of the file can be found in the next paragraph «[Run on Bare-Metal or Virtual Machine](#Run-on-Bare-Metal-or-Virtual-Machine)», with example values.\u003cbr\u003e\n\nTo run Docker-compos, open terminal and go to the Docker directory and enter the command.\n```shell\ndocker-compose up -d\n```\n\n### Run on Bare-Metal or Virtual Machine:\n\nFor normal launch primarily you will need to manually configure the **config.json** file.\u003cbr\u003e\nThen you will need to launch the entry point to the program.\n\n**Files location:**\u003cbr\u003e\n**./**:open_file_folder:Telegram_Grafana_Report_Bot\u003cbr\u003e\n   ├── :file_folder:Source_code\u003cbr\u003e\n   │        └── :page_facing_up:Telegram_Grafana_Report_Bot.py\u003cbr\u003e\n   └── :page_facing_up:config.json\u003cbr\u003e\n\n**Example of config.json file:**\n```json\n{\n  \"Telegram_Bot\":\n  {\n    \"token\": \"0000000000:aAaAaAaaAaAaAaAaAaAaaaAAAaAaAaAAaaAa\",\n    \"dm_white_list\": [\n      \"dm_user\",\n      \"dm_user2\"\n    ],\n    \"channel_id\": [\n      \"0000000000\",\n      \"0000000000\"\n    ],\n    \"channel_white_list\": [\n      \"dm_user\",\n      \"channel_user\"\n    ],\n    \"block_forwarding_messages\": true\n  },\n\n  \"Grafana\": [\n    \n    {\n      \"token\": \"glsa_A0A0aA0aAaA0A0aA0aAaA0A0aA0aA_00ffAaaa\",\n      \"url\": \"http://example_grafana:3000\",\n      \"handlers\": {...}\n    }\n    \n  ]\n}\n```\n\n* **Telegram_Bot**:\n    * **token** - the **token** we received by performing the steps in «[Telegram Bot registration](#Telegram-Bot-registration)» paragraph.\n    * **dm_white_list** - usernames who can write private messages to the bot.\u003cbr\u003e\nIn Telegram usernames start with the \"**@**\" symbol.\u003cbr\u003e\nBut you must specify the username without it.\n    * **channel_id** - List of channels where it is permissible to call the bot.\nHow to find out the channel name is described in «[Telegram channel settings](#Telegram-channel-settings)» paragraph.\n    * **channel_white_list** - list of usernames that are allowed to call the bot in channels.\n    * **block_forwarding_messages** - prevents forwarding bot messages if true.\n* **Grafana** - list of nested dictionaries describing Grafana with which the bot can interact.\n    * **token** - the **token** we received by performing the steps in «[Crate Grafana Technical User](#Crate-Grafana-Technical-User)».\n    * **url** - ip address or DNS name of yore Grafana instance.\n    * **handlers** - nested dictionary describing all the handlers that the bot can work with.\u003cbr\u003e\nDetails on how to configure them are written in [Add new handlers to Config file](#Add-new-handlers-to-Config-file) paragraph.\n\nRun **Telegram_Grafana_Report_Bot.py** with command:\n```shell\npython -B Telegram_Grafana_Report_Bot.py\n```\n\n## How to call the Bot:\n\nGo to the channel where your bot is located, or start a private message conversation with it.\u003cbr\u003e\nUse one of the commands:\n* **/star** - generate welcome message with all handles description. \n* **/help** - will do the same.\n* **/all** - get all graphs images from all Grafans related to the handles you added.\n* **Graph handler** - es example **/e1** in example Docker-compose.\n\n***\n\n:hearts: **Thank you** for your interest in my work! :hearts:\u003cbr\u003e\u003cbr\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawsanie%2Ftelegram_grafana_report_bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpawsanie%2Ftelegram_grafana_report_bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawsanie%2Ftelegram_grafana_report_bot/lists"}