Get Server Notification On Mobile PDF
Get Server Notification On Mobile PDF
Get Server Notification On Mobile PDF
Monitoring the server is crucial to have uninterrupted services. There are different ways
to configure alerts from the server. Here is an interesting way to get the notification
from the server right on your Telegram Messenger application.
In these notes describes how to create a personal notification bot that can send messages
from the Linux command-line through the Telegram API.
Telegram is a relatively new messaging app that touts security and privacy as its main
features. It has clients for a huge raft of platforms, and best of all it has a very nice bot
API for developers.
Creating Telegram Bot - By using ‘botfather’ in the Telegram, we can create a new bot.
Open Web Browser
https://web.telegram.org/#/login
Now bot father asks you to name the new bot. Give any name of your choice. In this
example, it is named as ‘Ashutosh’.
Bot requires a unique username. Type a username of your choice. If it is already taken,
try a different one.
Next we need to get the chat ID. Search for the newly created bot in the search field and
start a chat session.
Go to message field and type ‘/start’.
https://telegram.org
Note- Replace $token and $chatid with corresponding ids and text_Message.
Now Message Successfully Received.
Bash Script
Here is a bash script that can monitor server alert when any user ssh login is successful.
It has been tested on Centos 6,7. The telegram API is used to send attachment instead of
just text message. Resource usage statistics can be sent in attachment instead of plain
message.
/etc/profile is executed at every login (for bash shell users). The if statement will only
return true if the user has logged in via ssh.
MESS="$(head /logg)"
MESSAGE="$(echo)"
CHATID="**********"
TOKEN="*********************************************************"
if [ -n "$SSH_CLIENT" ]; then
curl -s --max-time 10 -d
"chat_id=$CHATID&disable_web_page_preview=1&text=$MESSAGE$MESS"
https://api.telegram.org/bot$TOKEN/sendMessage >/dev/null
fi
Ashutosh