{"id":21469946,"url":"https://github.com/sensu-plugins/sensu-plugins-telegram","last_synced_at":"2025-07-15T06:32:29.615Z","repository":{"id":52453065,"uuid":"54199727","full_name":"sensu-plugins/sensu-plugins-telegram","owner":"sensu-plugins","description":"Telegram handler for sensu","archived":false,"fork":false,"pushed_at":"2021-04-28T21:40:17.000Z","size":44,"stargazers_count":6,"open_issues_count":6,"forks_count":4,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-18T02:32:46.245Z","etag":null,"topics":["sensu","sensu-handler","sensu-plugins","telegram"],"latest_commit_sha":null,"homepage":"http://sensu-plugins.io","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sensu-plugins.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-18T12:32:30.000Z","updated_at":"2023-03-07T13:46:39.000Z","dependencies_parsed_at":"2022-09-17T17:21:34.997Z","dependency_job_id":null,"html_url":"https://github.com/sensu-plugins/sensu-plugins-telegram","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensu-plugins%2Fsensu-plugins-telegram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensu-plugins%2Fsensu-plugins-telegram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensu-plugins%2Fsensu-plugins-telegram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sensu-plugins%2Fsensu-plugins-telegram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sensu-plugins","download_url":"https://codeload.github.com/sensu-plugins/sensu-plugins-telegram/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226023556,"owners_count":17561484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["sensu","sensu-handler","sensu-plugins","telegram"],"created_at":"2024-11-23T09:19:52.379Z","updated_at":"2024-11-23T09:19:53.078Z","avatar_url":"https://github.com/sensu-plugins.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Sensu-Plugins-telegram\n\n[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-telegram.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-telegram)\n[![Gem Version](https://badge.fury.io/rb/sensu-plugins-telegram.svg)](http://badge.fury.io/rb/sensu-plugins-telegram)\n\n## Functionality\n\nThis plugin provides a handler to send notifications to a Telegram chat.\n\n## Files\n * bin/handler-telegram.rb\n\n## Usage\n\nAfter installation, you have to set up a `pipe` type handler, like so:\n\n```json\n{\n  \"handlers\": {\n    \"telegram\": {\n      \"type\": \"pipe\",\n      \"command\": \"handler-telegram.rb\",\n      \"filter\": \"occurrences\"\n    }\n  }\n}\n```\n\n\u003e Note: You need the `filter` key in there if you use the `occurrences` and/or the `refresh`\nattributes in your [check definitions](https://docs.sensu.io/sensu-core/1.6/reference/checks/).\n\nThis gem also expects a JSON configuration file with the following contents:\n\n```json\n{\n  \"telegram\": {\n    \"bot_token\": \"YOUR_BOT_TOKEN\",\n    \"chat_id\": -123123,\n    \"error_file_location\": \"/tmp/telegram_handler_error\"\n  }\n}\n```\n\n### Parameters:\n- `bot_token`: your bot's token, as provided by\n   [@BotFather](https://telegram.me/botfather).\n- `chat_id`: the chat to which the error message is to be sent.\n  The bot must be a member of this channel or group.\n  You can get the `chat_id` by adding the bot to the corresponding group,\n  sending a message like `/fakecmd @your-bot-username`, and then accessing\n  `https://api.telegram.org/bot\u003cTOKEN\u003e/getUpdates`.\n- `error_file_location` (optional): in case there is a failure sending the\n  message to Telegram (ie. connectivity issues), the exception mesage will\n  be written to a file in this location. You can then monitor this\n  location to detect any errors with the Telegram handler.\n- `message_template` (optional): An ERB template to use to format messages\n  instead of the default. Supports the following variables:\n  - `action_name`\n  - `action_icon`\n  - `client_name`\n  - `check_name`\n  - `status`\n  - `status_icon`\n  - `output`\n- `message_template_file` (optional): A file to read an ERB template from to\n  format messages. Supports the same variables as `message_template`.\n\n### Check configuration\n\nYou can then set up your checks to use the handler like this:\n\n```\n{\n  \"checks\": {\n    \"sensu-website\": {\n      \"command\": \"check-http.rb -u https://sensuapp.org\",\n      \"subscribers\": [\"production\"],\n      \"interval\": 60,\n      \"handler\": \"telegram\"\n    }\n  }\n}\n```\n\nFor more information about configuring checks, see the\n[Sensu documentation](https://docs.sensu.io/sensu-core/1.6/reference/checks).\n\n### Advanced configuration\n\nBy default, the handler assumes that the config parameters are specified in the\n`telegram` top-level key of the JSON, as shown above. You also have the option\nto make the handler fetch the config from a different key. To do this, pass the\n`-j` option to the handler with the name of the desired key You can define\nmultiple handlers, and each handler can send notifications to a different chat\nand from a different bot. You could, for example, have critical and non-critical\nTelegram groups, and send the notifications to one or the other depending on the\ncheck. For example:\n\n```json\n{\n  \"handlers\": {\n    \"critical_telegram\": {\n      \"type\": \"pipe\",\n      \"command\": \"handler-telegram.rb -j critical_telegram_options\"\n    },\n    \"non_critical_telegram\": {\n      \"type\": \"pipe\",\n      \"command\": \"handler-telegram.rb -j non_critical_telegram_options\"\n    }\n  }\n}\n```\n\nThis example will fetch the options from a JSON like this:\n\n```json\n{\n  \"telegram\": {\n    \"bot_token\": \"YOUR_BOT_TOKEN\"\n  },\n  \"critical_telegram_options\": {\n    \"chat_id\": -123123\n  },\n  \"non_critical_telegram_options\": {\n    \"chat_id\": -456456\n  }\n}\n```\n\nAs you can see, you can specify the default config in the `telegram` key, and\nthe rest of the config in their own custom keys.\n\nYou can also directly add the configuration parameters to the event data using a\nmutator. For example:\n\n```ruby\n#!/usr/bin/env ruby\nrequire 'rubygems'\nrequire 'json'\nevent = JSON.parse(STDIN.read, :symbolize_names =\u003e true)\nevent.merge!(chat_id: -456456)\nputs JSON.dump(event)\n```\n\n### Configuration precedence\n\nThe handler will load the config as follows (from least to most priority):\n\n* Default `telegram` key\n* Custom config keys\n* Event data\n\n## Installation\n\n[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)\n\n## Notes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsensu-plugins%2Fsensu-plugins-telegram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsensu-plugins%2Fsensu-plugins-telegram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsensu-plugins%2Fsensu-plugins-telegram/lists"}