அனைவருக்கும் தாமதமான விடுமுறை வாழ்த்துக்கள். இந்த தீம் சிறந்தது
பொதுவாக, செயல்பாட்டின் கொள்கை மாறவில்லை, ஒரே வித்தியாசம் என்னவென்றால், இப்போது அது தாமதமின்றி உடனடியாக வேலை செய்கிறது.
நாங்கள் ஸ்கிரிப்டை Mikrotik இல் பதிவேற்றுகிறோம், BotID மற்றும் ChatID ஐ எங்களுடையதாக மாற்றி, அதற்கான அட்டவணையை உருவாக்குகிறோம். தொடக்கத்தில் "தொடக்க நேரம்" அளவுருவை அமைக்கவும் (தொடக்கத்தில் ஸ்கிரிப்டை இயக்கவும்.)
"இடைவெளி": 00:00:00
மற்றபடி எல்லாம் இருந்தபடியே இருக்கும்.
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]
#:log info $message;
:return $message;
}
:while ( true ) do={
:do {
#:log info "https://api.telegram.org/$botID/getUpdates?offset=$messageId&limit=1&allowed_updates=message&timeout=60";
:tool fetch url=("https://api.telegram.org/$botID/getUpdates?offset=$messageId&limit=1&allowed_updates=message&timeout=60") dst-path="getUpdates";
:local content [/file get [/file find name=getUpdates] contents] ;
#:log info $content;
:if ([:len $content] > 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={}
};
ஓரிரு வருட பயன்பாட்டிற்குப் பிறகு, ஒரு பிழை கண்டுபிடிக்கப்பட்டது: சில அறியப்படாத காரணங்களுக்காக, பலவீனமான Mikrotik ஸ்கிரிப்டை நிறுத்துகிறது, ஆனால் அதிக சக்திவாய்ந்தவற்றில் அது நிறுத்தப்படாமல் வேலை செய்கிறது.
இந்த நோக்கங்களுக்காக, நான் வாட்ச் டாக் ஊன்றுகோலில் வீசினேன். இங்கே நாம் ஸ்கிரிப்ட்டின் பெயரை மேலே சுட்டிக்காட்டப்பட்டதாக மாற்றுகிறோம். மறுதொடக்கம் இடைவெளியை 5 நிமிடங்களாக அமைக்கவும். ஒவ்வொரு 5 நிமிடங்களுக்கும் எங்கள் "வாட்ச்டாக்" ஸ்கிரிப்டைச் சரிபார்த்து, அது வேலை செய்யவில்லை என்றால், அது அதை இயக்கும்.
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
சரி, இனிப்புக்காக, ஸ்கிரிப்ட் மைக்ரோடிக் மன்றத்தில் இருந்து எடுக்கப்பட்டது.
பதிவில் இருந்து முக்கியமான தலைப்புகளை எங்கள் வண்டிக்கு அனுப்புகிறது.
ஒவ்வொரு 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
}
}
நாங்கள் முடிவைப் பெறுகிறோம்:
ஆதாரம்: www.habr.com