Mikrotik, a telegram notification about a successful login

Name: Log2Telega
Policy: read,write, police, test
Source:
: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];”;
}
# START SEND TELEGRAM 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;
# END SEND TELEGRAM MESSAGE
}
:set ParseLogAccountEndArrayID $EndArrayID;
Comment: We write our comments

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

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store