Mikrotik script with Telegram bot Notification - Hi every one, we are going to create notification using simple script with scheduler and sent it to telegram chat messaging. With this setup, we can monitor such as real time active pppoe, hotspot and etc.So, my goal is to check whether pppoe and hotspot which is currently running in several router and then sent message it to our telegram bot. For the simple step, make sure that :
- Network time is active
- Router can resolve DNS
- Register telegram bot, make sure you have bot token and chat-id. For further reference you can check this link
- Understand how to using RouterOS
- This setup tested running good at v6.42.7 and v6.42.3
Okay, if all requirements has been fullfiled, here the next step :
Telegram Script
Create single script, go to system>scripts>add
set any name and copy paste this script. Notice that you must change :
- XXXXXXXXXXXXXXXXXXXXX with Telegram Bot Token
- YYYYYYYYYY with chat-id
{
:local sysid [/system identity get name]
:local time [/system clock get time]
:local date [/system clock get date]
:local hsac [:len [/ip hotspot active find radius]]
:local ppac [:len [/ppp active find service=pppoe]]
/tool fetch url="https://api.telegram.org/XXXXXXXXXXXXXXXXXXXXX/sendMessage?chat_id=-YYYYYYYYYY&text=Router_Name= $sysid%0ADate= $date - Time= $time%0AHotspot_Active= $hsac Users%0AActive_PPPoE= $ppac Account" keep-result=no
};
Next, you can try to run the script, if this script giving you message to you telegram bot, then its mean your bot is working.Create Scheduler
This scheduler will run script1 every time depend interval. You can adjust interval for script will be running for example every 1 hours. So, every hours you can get message to your telegram bot chat regarding active PPPoE and Hotspot. Go to system>scheduler>addOf course you can send anything to your Telegram bot,this tutorial only giving you option to monitoring Active user on PPPoE and Hotspot. Thank you.
0 comments:
Post a Comment