Прикрутил telegram бота к mikrotik.
Не понятно почему schedule отрабатывает каждый день ровно в 7 утра.
Код: Выделить всё
:global lastTime
:global output
:global mtIdentity [/system identity get name];
:global botID "bot3126488426:AAGWNo8VcdTlXRPXItShc5dPEEDan0LAkda" ;
:global myChatID "-253131231" ;
:local LogGet [ :toarray [ /log find topics~"critical" || topics~"system" || topics~"error" || message~"filter rule" || message~"login failure" || message~"[Ff]ailure" ] ] ;
:local LogtLineCount [ :len $LogGet ] ;
if ($LogtLineCount > 0) do={
:local currentTime "$[ /log get [ :pick $LogGet ($LogtLineCount -1) ] time ]";
:if ([:len $currentTime] = 10 ) do={
:set currentTime [ :pick $currentTime 0 10 ];
}
:set output "$currentTime - $[/log get [ :pick $LogGet ($LogtLineCount-1) ] message ]";
:if (([:len $lastTime] < 1) || (([:len $lastTime] > 0) && ($lastTime != $currentTime))) do={
:set lastTime $currentTime ;
:tool fetch url=("https://api.telegram.org/$botID/sendmessage\?chat_id=$myChatID&text=\"$mtIdentity\" : $output") keep-result=no
}
}