All Projects → matriphe → Monit2telegram

matriphe / Monit2telegram

Licence: mit
A simple script to send Monit alerts using Telegram bot.

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Monit2telegram

Bot Telegram
Exemplo de como criar um BOT para o melhor app de mensagens do mundo: Telegram.
Stars: ✭ 53 (-45.36%)
Mutual labels:  bot, telegram
Telegram Bot
Telegram Bot using AWS API Gateway and AWS Lambda
Stars: ✭ 96 (-1.03%)
Mutual labels:  bot, telegram
Pockebot
Read It Later for Telegram
Stars: ✭ 56 (-42.27%)
Mutual labels:  bot, telegram
Nikoro
A plugin-based, all-in-one, Telegram Bot written in Node.js
Stars: ✭ 51 (-47.42%)
Mutual labels:  bot, telegram
Turibot
TuriBot is a simple way to communicate with Telegram APIs in PHP
Stars: ✭ 68 (-29.9%)
Mutual labels:  bot, telegram
Telegram Bot Groupagree
An advanced poll bot for Telegram
Stars: ✭ 52 (-46.39%)
Mutual labels:  bot, telegram
Zabbix Telegram Notification
Zabbix notifications on Telegram
Stars: ✭ 59 (-39.18%)
Mutual labels:  bot, telegram
Gpt2 Telegram Chatbot
GPT-2 Telegram Chat bot
Stars: ✭ 41 (-57.73%)
Mutual labels:  bot, telegram
Telebot.nim
Async client for Telegram Bot API in pure Nim [Bot API 5.1]
Stars: ✭ 93 (-4.12%)
Mutual labels:  bot, telegram
Github Releases Notify Bot
Allows you to receive notifications of new releases of software on GitHub in Telegram
Stars: ✭ 65 (-32.99%)
Mutual labels:  bot, telegram
Marvin
The paranoid bot (framework)
Stars: ✭ 51 (-47.42%)
Mutual labels:  bot, telegram
Go Tgbot
Golang telegram bot API wrapper, session-based router and middleware
Stars: ✭ 90 (-7.22%)
Mutual labels:  bot, telegram
Enterprisealrobot
An anime themed telegram group management bot
Stars: ✭ 49 (-49.48%)
Mutual labels:  bot, telegram
Telepyth
Telegram notification with IPython magics.
Stars: ✭ 54 (-44.33%)
Mutual labels:  bot, telegram
Telegram Test Api
Simple implimentation of telegram API which can be used for testing telegram bots
Stars: ✭ 42 (-56.7%)
Mutual labels:  bot, telegram
Telebot
The easy way to write Telegram bots in Node.js
Stars: ✭ 1,096 (+1029.9%)
Mutual labels:  bot, telegram
Rocketgram
Modern and powerful asynchronous telegram bot framework.
Stars: ✭ 37 (-61.86%)
Mutual labels:  bot, telegram
Moviemagnetbot
🤖 telegram bot for movies
Stars: ✭ 39 (-59.79%)
Mutual labels:  bot, telegram
Syntax Highlighter Bot
Syntax highlighter bot for telegram.
Stars: ✭ 60 (-38.14%)
Mutual labels:  bot, telegram
Telegram Pm Chat Bot
Telegram Private Message Chat Bot
Stars: ✭ 69 (-28.87%)
Mutual labels:  bot, telegram

monit2telegram

A simple script to send Monit alerts using Telegram bot.

By default, Monit only sends alert notifications via email. But we can also set a hook to execute a script. When executing the script, Monit sets a few environment variables about the alert.

This tiny script transforms those variables into a text message and pipes them to Telegram using a bash script for delivery.

This script is inspired by Monit2Twilio.

Requirements

  • Bash
  • CURL
  • jq
  • Telegram Bot
  • Monit

Create Telegram Bot

If you don't have a Telegram Bot, just create one. By using a Telegram bot you don’t have to use a real Telegram client or reuse your Telegram account.

Getting Bot Token

You will get a Telegram Bot Token after bot created. Keep this token, we will use it later. The bot token is looked like this.

123456789:aBcDeFgHiJkLmN-OpQrStUvWXyZ12345678

Getting Chat ID

To send messages to a Telegram chat, you must first needs to start a chat with the bot. Clicking on the bot link after creation should be enough, it will automatically send a message of /start to the bot.

To get the Chat ID from Telegram bot, execute this command using getUpdates function of Telegram API.

$ curl --silent "https://api.telegram.org/bot{TOKEN}/getUpdates" | jq
{
  "ok": true,
  "result": [
    {
      "update_id": 17082016,
      "message": {
        "message_id": 17,
        "from": {
          "id": 22031984,
          "first_name": "User"
        },
        "chat": {
          "id": 22031984,
          "first_name": "User",
          "type": "private"
        },
        "date": 1471402800,
        "text": "Hello from the other side~"
      }
    }
  ]
}

In this example the Chat ID to look out for is 22031984. Replace {TOKEN} with your Telegram bot token.

Usage

Clone this repo or download the zipped file.

# git clone https://github.com/matriphe/monit2telegram.git 
# cd monit2telegram

Put your Telegram Bot ID and Chat ID in telegramrc and save it to the /etc directory (/etc/telegramrc).

# cp telegramrc /etc/telegramrc

Put sendtelegram.sh and monit2telegram.sh to /usr/local/bin and make them executable.

# cp sendtelegram.sh /usr/local/bin/sendtelegram
# chmod +x /usr/local/bin/sendtelegram
# cp monit2telegram.sh /usr/local/bin/monit2telegram
# chmod +x /usr/local/bin/monit2telegram

Test the sendtelegram script by running this command.

# sendtelegram -c /etc/telegramrc -m "Hello from the other side!"
Sending message 'Hello from the other side!' to 22031984
Done!
#

You should see Telegram message sent by your Telegram bot.

Set Up Monit

Now you can add Monit alert by adding this line to Monit configuration file.

check file nginx.pid with path /var/run/nginx.pid
    if changed pid then exec "/usr/local/bin/monit2telegram"
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].