A simple script send alerts using Telegram bot.
This modify from https://github.com/matriphe/monit2telegram/ and custom it for personal needs. So only made for ping and url/http/https checking.
- Bash
- CURL
- jq
- 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.
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
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.
Clone this repo or download the zipped file.
$ git clone https://github.com/princeofgiri/bojongbot.git
$ mv bojongbot /opt/
Put your Telegram Bot ID and Chat ID in /opt/bojongbot/telegramrc
and save it.
Test the sendtelegram
script by running this command.
$ /opt/bojongbot/sendtelegram -c /opt/bojongbot/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.
Edit iplist
in /opt/bojongbot/iplist
and save it (there's example already in this file).
To execute this command to test:
$ /opt/bojongbot/ping
If you need to execute ping script every 5 seconds, you need to put it to crontab. Here the step:
$ crontab -e
Add this */5 * * * * /opt/bojongbot/ping
then save.
Yes, I need several idea or pull request about other implementation. Feel free to create pull request!