Whakahohenga mamao o nga tuhinga Mikrotik mai i Telegram v 2.0

Nga mihi aroha ki a koutou katoa. He pai ake tenei kaupapa putanga o nga mea i tuhia e au i te tau 2016 i konei.

I te nuinga o te waa, kaore i rereke te kaupapa o te mahi, ko te rereketanga anake ko te mahi tonu inaianei me te kore e whakaroa.

Ka tukuna e matou te tuhinga ki Mikrotik, ka huri i te BotID me te ChatID ki a maatau ake ka hangaia he waarangi mo taua mea. Tautuhia te tawhā "Wā Tīmata" ki te whakaoho (Whakahaerehia te tuhinga i te tiimatanga.)
"Wā": 00:00:00
Ki te kore he rite nga mea katoa.

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={}
};

I muri i nga tau e rua o te whakamahinga, i kitea he pepeke: mo etahi take kaore i mohiotia, ka mutu te ngoikore o Mikrotik i te tuhinga, engari i runga i nga mea kaha ake ka mahi me te kore e mutu.

Mo enei kaupapa, ka whiua e ahau te tootoo WatchDog. I konei ka huri tatou i te ingoa o te tuhinga ki te ingoa o runga ake nei. ka tautuhi i te waahi whakaoho ki te 5 meneti. Ia 5 meneti ka tirotirohia e to tatou "kaitiaki" te tuhinga a ki te kore e mahi, ka whakahaere.

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

Na, mo te kai reka, i tangohia te tuhinga mai i te huinga Mikrotik.
Ka tukuna nga kaupapa nui mai i te raarangi ki to tatou kaata.

Ka taapirihia e matou te tuhinga ki te whakarite me te tautuhi i te waahi whakaoho ia 5 meneti, huri i te BotID me te ChatID ki a maatau ake.

Panui-raupapa

: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
   }
}

Ka whiwhi tatou i te hua:

Whakahohenga mamao o nga tuhinga Mikrotik mai i Telegram v 2.0

Source: will.com

Tāpiri i te kōrero