Mikrotik, a telegram notification about a successful login

Igor Mullin
3 min readAug 21, 2021


A router is a device that not only organizes a home network, but also protects it from the outside world. If someone gets access to your router, you can get into big problems or even lose money or privacy.

Original article here. Also, do not forget to read us in other services: Instagram, telegram (RU, EN, DE). Medium, LiveJournal, YouTube.

A smart home will also be at risk if we are hacked. Let’s protect ourselves a little. We will receive notifications that someone has logged in. There are many different ways, but I always choose #telegram. I got the idea here. For understanding, I recommend reading my article. There are answers to questions about the #id and the token. Let’s start, go to the scripts and create one. Settings → scripts → create a new one

Name: Log2Telega
Policy: read,write, police, test
:local DeviceName [/system identity get name];
:local Time [/system clock get time];
:local Date [/system clock get date];
:local TelegramMessageText;
:global ParseLogAccountEndArrayID;
:local IDsEventsAccount [/log find where topics ~ “account”];
:local LenArrayIDs [:len $IDsEventsAccount];
:local StartArrayID [:find $IDsEventsAccount $ParseLogAccountEndArrayID];
:local EndArrayID ($IDsEventsAccount -> ($LenArrayIDs-1));
:if ($EndArrayID != $ParseLogAccountEndArrayID and [:tobool $ParseLogAccountEndArrayID] ) do={
:local StartArray [:find $IDsEventsAccount $ParseLogAccountLastRunID];
:for KeyArray from=($StartArrayID+1) to=($LenArrayIDs-1) do={
:local IDMessage ($IDsEventsAccount ->$KeyArray );
:set TelegramMessageText “$TelegramMessageText %0D%0A $[/log get number=$IDMessage time] — $[/log get number=$IDMessage message];”;
:local BotToken “here we enter our token for telegram. strictly inside the quotation marks”;
:local ChatID “here we write the chat id. It can be WE or a public group”;
:local ParseMode “html”;
:local DisableWebPagePreview True;
:local SendText “\F0\9F\94\93 <b>$DeviceName: AUTH</b> $TelegramMessageText”;
:local tgUrl “https://api.telegram.org/bot$BotToken/sendMessage?chat_id=$ChatID&text=$SendText&parse_mode=$ParseMode&disable_web_page_preview=$DisableWebPagePreview";
/tool fetch http-method=get url=$tgUrl keep-result=no;
:set ParseLogAccountEndArrayID $EndArrayID;
Comment: We write our comments

I remind you that we take the #token and id according to this instruction (Ru). A screen of the window where we insert the #script is below.

The next step is to add our script to the distribution. Settings → schedule → create a new

Name: log2telega
Policy: read,write, police, test
On Event: /system script run Log2Telega
Comment: log2telega run every 1 min

The main thing here is that the correct name of our script should be after the “run”. We save and log in to the #router and rejoice at the result:

Of course, such actions will only allow us to monitor the situation, but they will not save us completely. However, together with a working #firewall, this is already something

And that’s all, subscribe, likes, repost… And we will soon be a small lottery ☺.



Igor Mullin

I´m a Hardware and Software Engineer and a PhD. In my professional activity I focus on such things like smart home systems and electric development.