所有过去的假期。 这个主题是
我2016年在这里写的更好的
版本 。
总的来说,工作原理没有改变,唯一的区别是它现在可以立即工作而不会延迟。
我们将脚本上传到Mikrotik中,将BotID和ChatID更改为我们的脚本,并为其创建时间表。 将“开始时间”参数设置为启动(在启动时运行脚本。)
间隔:00:00:00
否则,一切都保持原样。
电报-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]
在使用了几年后,由于某种原因,发现了一个错误,由于某些原因,弱Mikrotik停止了该脚本,但它的工作原理并未停止在更强大的脚本上。
为此,我扔了一个WatchDog拐杖。 在这里,我们将脚本的名称更改为上述名称。 并将重新启动间隔设置为5分钟。 每隔5分钟,我们的“看门狗”将检查脚本,如果该脚本不起作用,它将运行。
看门狗 :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
好吧,关于甜点,该脚本取自Mikrotik论坛。
将重要主题从日志发送到我们的购物车。
我们将脚本放入时间表中,并指定每5分钟重新启动一次,然后将BotID和ChatID更改为我们的时间间隔。
通知日志 :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 } }
我们得到结果:
