Todo con las vacaciones pasadas. Este tema es una mejor
versión de lo que escribí en 2016 aquí .
En general, el principio del trabajo no ha cambiado, con la única diferencia de que ahora funciona instantáneamente sin demora.
Cargamos el script en Mikrotik, cambiamos BotID y ChatID al nuestro y creamos un cronograma para ello. Establezca el parámetro "Hora de inicio" en el inicio (Ejecute el script al inicio).
Intervalo: 00:00:00
De lo contrario, todo está como estaba.
Telegram-v2:delay 10 :global mtIdentity [/system identity get name]; :global botID "botXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXX" ; :global myChatID "YYYYYY" ; :local chatId 0; :local messageId 0; :local parse do={ :local startLoc ([:find $content $variable -1] + [:len $variable] + 2); :local commaLoc ([:find $content "," $startLoc] - 1 + 1); :local braceLoc ([:find $content "}" $startLoc] - 1 + 1); :local endLoc $commaLoc; :local startSymbol [:pick $content $startLoc] :if ($braceLoc != 0 and ($commaLoc = 0 or $braceLoc < $commaLoc)) do={ :set endLoc $braceLoc; }; :if ($startSymbol = "{") do={ :set endLoc ($braceLoc + 1); }; :if ($quotas = true) do={ :set startLoc ($startLoc + 1); :set endLoc ($endLoc - 1); } :if ($endLoc < $startLoc) do={ :set endLoc ($startLoc + 1); }; :local message [:pick $content $startLoc $endLoc]
Durante un par de años de uso, se descubrió un error, por alguna razón, Mikrotik débil, por alguna razón, detiene el script, funciona sin detenerse en los más potentes.
Para estos propósitos, tiré una muleta WatchDog. aquí cambiamos el nombre del script al indicado anteriormente. y establezca el intervalo de reinicio en 5 minutos. Cada 5 minutos, nuestro "perro de aspecto" verificará el guión y, si no funciona, se ejecutará.
WatchDogT.me :global scriptname "t.me" :if ([:len [/system script job find script=$"scriptname"]] > 0) do={ :log info "$scriptname Already Running - killing old script before continuing" :foreach counter in=[/system script job find script=$"scriptname"] do={ /system script job remove $counter } } /system script run $scriptname
Bueno, para el postre, el guión está tomado del foro Mikrotik.
Envía temas importantes desde el registro a nuestro carrito.
Colocamos el script en la programación y especificamos el intervalo de reinicio cada 5 minutos, cambiamos BotID y ChatID a los nuestros.
Notificar-registro :global lastTime :global output :global mtIdentity [/system identity get name]; :global botID "botXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXX" ; :global myChatID "YYYYYY" ; :local LogGet [ :toarray [ /log find topics~"critical" || 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 } }
Obtenemos el resultado:
