Urime për festën e kaluar. Kjo temë është një version më i mirë i asaj që kam shkruar në vitin 2016 këtu. .
Ngarkoni skriptin në Mikrotik, ndryshoni BotID dhe ChatID me të tuajat dhe krijoni një caktim për të. Vendosni parametrin "Start Time" në startup (Ekzekutimi i skriptit në nisje.)
"Interval": 00:00:00
Për të tjerat, gjithçka është siç ishte.
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 30) do={ :set messageId ([$parse content=$content variable="update_id"] + 1) :local message [$parse content=$content variable="text" quotas=true] :local chat [$parse content=$content variable="chat"] :local chatId [$parse content=$chat variable="id"] :if (($chatId = $myChatID) and ([\/system script find name=$message] != "")) do={ :system script run $message; } else={ :tool fetch url=("https:\/\/api.telegram.org\/$botID\/sendmessage?chat_id=$chatId&text=$mtIdentity: Unknown command: $message") keep-result=no } } } on-error={} };
Pas disa vjetĂ«sh pĂ«rdorimi u zbulua njĂ« gabim, pĂ«r arsye tĂ« paqartĂ«, Mikrotik-e mĂ« tĂ« dobĂ«ta ndalonin skriptin, ndĂ«rsa nĂ« ato mĂ« tĂ« fuqishme funksionon pa ndalesa.PĂ«r kĂ«to qĂ«llime, kam krijuar njĂ« rregullues WatchDog. kĂ«tu ndryshojmĂ« emrin e skriptit nĂ« atĂ« qĂ« theksuam mĂ« lart. dhe vendosim intervalin e rinisjes nĂ« 5 minuta. Ădo 5 minuta "dogu ynĂ« qĂ« mbikĂ«qyr" do tĂ« kontrollojĂ« skriptin dhe nĂ«se ai nuk punon, atĂ«herĂ« do ta fillojĂ« atĂ«.
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
Dhe si një përfundim, skripti është marrë nga forumi i Mikrotik.Dërgon tema të rëndësishme nga logu në Telegramin tonë.
Dërgon temat e rëndësishme nga logu në Telegram.
Shtojmë skenarin në programin e caktuar dhe përcaktojmë intervalin e rimbusit çdo 5 minuta, ndryshojmë BotID dhe ChatID me të tonat.
Notify-log
: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] 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
}
}Do të marrim rezultatin:

Burimi: habr.com
