Community discussions

MikroTik App
 
celeritynetworks
just joined
Topic Author
Posts: 8
Joined: Wed Sep 09, 2015 10:23 pm

Script Contents Run Manually but Not from Run Script Button

Tue Feb 23, 2021 10:03 pm

Hello. I have this script, which runs fine when I copy/paste it into a terminal window, but doesn't seem to run when I click on the Run Script button in Winbox (the variables referenced are manually created global variables for testing).

:if ($RadIncReq>$RadIncReqLast) do={
/tool fetch mode=https url="https://hooks.slack.com/services/real-token-removed" http-method=post http-data="payload={\"attachments\":[{\"color\":\"#f54242\",\"pretext\":\"ALARM\",\"callback_id\":\"dude_alarm\",\"text\": \"ROUTER-BNG - Incoming RADIUS Requests are Incrementing\"}]}";
/log info "**** Incoming RADIUS Requests are Incrementing****";
}

When I copy/past the above in this exact form, I get the log entry and the message in Slack. When I click Run Script button, I get neither.

Here's the actual export:

/system script
add dont-require-permissions=no name=CheckRadIncRequests owner=admin policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":if (\$RadIncReq>\$RadIncReqLast) do={\r\
\n/tool fetch mode=https url=\"https://hooks.slack.com/services/real-token-removed\" http-method\
=post http-data=\"payload={\\\"attachments\\\":[{\\\"color\\\":\\\"#f54242\\\",\\\"pretext\\\":\\\"ALARM\\\",\\\"callback_\
id\\\":\\\"dude_alarm\\\",\\\"text\\\": \\\"ROUTER-BNG - Incoming RADIUS Requests are Incrementing\\\"}]}\";\r\
\n/log info \"**** Incoming RADIUS Requests are Incrementing****\";\r\
\n}"

Here's the actual environment:

/system script environment> print
# NAME VALUE
0 RadIncReq 9
1 RadIncReqLast 8

I'm sure I'm missing something simple, thanks in advanced!
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1922
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Script Contents Run Manually but Not from Run Script Button  [SOLVED]

Tue Feb 23, 2021 10:42 pm

Simple to solve.

You need to declare the global variable before it can be seen by a script, so change to:
:global RadIncReq
:global RadIncReqLast
:if ($RadIncReq>$RadIncReqLast) do={
	/tool fetch mode=https url="https://hooks.slack.com/services/real-token-removed" http-method=post http-data="payload={\"attachments\":[{\"color\":\"#f54242\",\"pretext\":\"ALARM\",\"callback_id\":\"dude_alarm\",\"text\": \"ROUTER-BNG - Incoming RADIUS Requests are Incrementing\"}]}"
	/log info "**** Incoming RADIUS Requests are Incrementing****"
}
PS use code tags </> when posting codes and ; are not needed on end of each line, only between multiple commands on same line.
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 
 
celeritynetworks
just joined
Topic Author
Posts: 8
Joined: Wed Sep 09, 2015 10:23 pm

Re: Script Contents Run Manually but Not from Run Script Button

Tue Feb 23, 2021 11:12 pm

Thanks so much for the quick reply, I appreciate it. I will use code tags next time, too.

Who is online

Users browsing this forum: No registered users and 22 guests