P
P
Pasha Ignatiev2018-04-16 20:23:56
Mikrotik
Pasha Ignatiev, 2018-04-16 20:23:56

Why doesn't mikrotik script send messages to slack?

Crawling into slack from a telegram (well, you know why), I ran into the fact that slack categorically does not want to change to Cyrillic
. Here is the script itself:

:global SlackMessage "%0ATime:  [Time]%0AAddress: [Device.CustomField2]%0AIP: [Device.FirstAddress]%0APing: [Service.Status]%0A";
:global SlackChannel "channel-id";
:local messageencoded "";
:local botname "DUDE-server"
:local token "slack-token"
:local iconurl https://wiki.mikrotik.com/images/5/54/Dude-icon3.png
#replace ASCII characters with URL encoded characters
:for i from=0 to=([:len $SlackMessage] - 1) do={
  :local char [:pick $SlackMessage $i]
  :if ($char = " ") do={
   :set $char "%20"
  }
  :if ($char = "-") do={
    :set $char "%2D"
  }
  :if ($char = "#") do={
    :set $char "%23"
  }
  :if ($char = "+") do={
    :set $char "%2B"
  }
  :if ($char = "  ") do={
    :set $char "%09"
  }
  :if ($char = ":") do={
    :set $char "%3a"
  }
  :set messageencoded ($messageencoded . $char)
}
/tool fetch url="https://slack.com/api/chat.postMessage?token=$token&channel=$SlackChannel&text=$messageencoded&icon_url=$iconurl&as_user=false&username=$botname";

And God forbid, there will be at least one Russian letter in the message, that's it, the messages do not go. Tried :if ($char = "ё") do={:set $char "%D1%91"}for every letter of our alphabet, both lowercase and uppercase. Zero sense.
I ask for your help, O great collective mind!
PS
The option of offering another messenger / service is also acceptable, but with existing / working solutions to this issue (do not offer e-mail).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pasha Ignatiev, 2018-04-19
@pafflootiy

I'll answer myself. RouterOS >= 6.39 learned in POST. Therefore, it is possible to send notifications of interest to me through slack webhooks with the content type "application/json".
Thanks to all!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question