162. Mikrotik How to Config Alert by Telegram


You can contact me: plus.google.com/+PhallaCCMT; youtube.com/phallaccmt; facebook.com/Phalla.CCMT; twitter.com/PhallaCCMT and Phalla.CCMT@gmail.com


Steps:

1. Go to Telegram App/Web: search for "BotFather"
2. Enter "/newbot"
3. Enter our Bot Account name that must end with "Bot or _bot" then you will get token to access HTTPS API.
Ex: 674410326:AAHdIexPzAkY-Qygj7SZ-pJKwb3HGzjt9fo

4. Open Browser with this link by replace with our bot ID to make sure it work or not:
Ex: 
     https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-  zyx57W2v1u123ew11/getMe 
     to 
     https://api.telegram.org/bot674410326:AAHdIexPzAkY-Qygj7SZ-pJKwb3HGzjt9fo/getMe

5. Go to Telegram then Create a group.
6. Enter "/jion @[botname]"
Ex: /jion @phallaccmtBot

7. Find Account ID:
https://api.telegram.org/bot674410326:AAHdIexPzAkY-Qygj7SZ-pJKwb3HGzjt9fo/getupdates
-------------------------------------------------------------
"{"ok":true,"result":[{"update_id":421982068,
"message":{"message_id":1,"from":{"id":292302472,"is_bot":false,"first_name":"\u17a0\u17bb\u1784","last_name":"\u1795\u179b\u17d2\u179b\u17b6","username":"Phalla27O"},"chat":{"id":-265243874,"title":"Netwatch_Mikrotik","type":"group","all_members_are_administrators":true},"date":1538022867,"group_chat_created":true}},{"update_id":421982069,
"message":{"message_id":2,"from":{"id":292302472,"is_bot":false,"first_name":"\u17a0\u17bb\u1784","last_name":"\u1795\u179b\u17d2\u179b\u17b6","username":"Phalla27O"},"chat":{"id":-265243874,"title":"Netwatch_Mikrotik","type":"group","all_members_are_administrators":true},"date":1538022915,"text":"/jion @phallaccmtBot","entities":[{"offset":0,"length":5,"type":"bot_command"},{"offset":6,"length":14,"type":"mention"}]}}]}"
-------------------------------------------------------------
8. Replace BotID and Account ID to below script for Netwatch.
NetWatch Script:

:local CurDate [/system clock get date] 
:local CurTime [/system clock get time] 

:local CHID "-265243874"; 
:local BotID "674410326:AAHdIexPzAkY-Qygj7SZ-pJKwb3HGzjt9fo";
:local HostStatus "UP";

:local Message "Host $host is $HostStatus at $CurTime $CurDate";

/tool fetch url="https://api.telegram.org/bot$BotID/sendmessage\?chat_id=$CHID&text=$Message";

Ref: https://wiki.mikrotik.com/wiki/Manual:The_Dude_v6/Dude_Telegram_Example
Previous
Next Post »

3 comments

Write comments
sl67
AUTHOR
September 30, 2018 at 8:00 AM delete

original (on error not keep-result=no)
/tool fetch url="https://api.telegram.org/bot$BotID/sendmessage\?chat_id=$CHID&text=$Message" ;
=====================================
modify no error add keep-result=no
/tool fetch url="https://api.telegram.org/bot$BotID/sendmessage\?chat_id=$CHID&text=$Message" keep-result=no;

Reply
avatar
Kake
AUTHOR
March 29, 2019 at 1:46 AM delete

Script Working perfect but microtik send Notifications in every 6 minutes. What can i do for get notifications only when host getting up or down?

Reply
avatar
Jp Gutierrez
AUTHOR
May 26, 2019 at 8:45 PM delete

Do you have script for login notification of user using telegram?

Reply
avatar