Server notification on telegram

Monitoring the server is crucial to have uninterrupted services. There are different ways to configure alerts from the server. Here, in this blog, we will explore an interesting way to get the notification from the server right on your Telegram Messenger application.

What is telegram?

Telegram Bot

How do you create the bot?

  • By using Botfather in Telegram, we can create a new bot. Go to the search field in Telegram and type botfather.
  • Now, go to the message field and click on start.
Server notification on telegram
  • Type ‘/newbot’ without quotes in the message field and hit enter
  •  Now bot’s father asks you to name the new bot. Give any name of your choice. In this case, we named it ‘Jarvis’.
Server notification on telegram
  • Bot requires a unique username. Type a username of your choice. If it is already taken, try a different one.
  • Once a username is successfully generated, you’ll get an acknowledgment message from Botfather with the token ID of the bot. This token ID is used in the Telegram API to send messages.
Server notification on telegram
  • Next, we need to get the chat ID. Search for the newly created bot in the search field and start a chat session.
Server notification on telegram
Server notification on telegram

In the screenshot, the highlighted section has the chat ID.

Incase of group chat, the bot has to be invited to the group and then run the getupdates API to get the chat ID. The group chat ID will have a negative sign at the beginning.

Server notification on telegram

Simple bash script to send notification via telegram bot

Bash Script to send report to telegram if high resource usage is found in the server

Here is a bash script that can monitor server load and memory usage at regular intervals. It has been tested on Centos 7. The telegram API is used to send an attachment instead of just a text message. This is because sending text has a character limit. Resource usage statistics can be sent in the attachment instead of the plain message.

Video Tutorial