Page 1 of 1

define array with several strings

Posted: Fri Dec 13, 2024 2:54 am
by Matthiastik
Hi,

Trying to defina an array to loop trafic type with kid-control feature in MKT 7.16
but get confued with how to define array this is my code and know that Forum guru halped me a lot to get to this point
and i am really happy for his help again.

This is my code:
{
:global abc [:toarray "youtube, google, amazon"]
:foreach abuserid in=[/ip/kid-control/device/find activity ~"$abc" ] do={
:do {
:log info "Websites are $abc"
/ip/firewall/address-list/add list=ABUSERSIP address=[/ip/kid-control/device/get $abuserid ip-address] timeout=1h
#:log info "Abuser ID is $abuserid"
} on-error { :log info "IP already added"}
}
}

This example work to get type of traffic from kind-control "without the line : global abc [:toarray] and replacing $abc with "youtube"

this way:
:global my_array [:to array "youtube, google, amazon"]
other say
:global abc {"youtube", "google","amazon"}

there are many way suposedly but none work as expected:

The intention is 1st loop check for activity youtube and save ip address to address list
2nd loop check for activity google and add ip found to the address list
3rd loop check for activity amazon and add to address list

and so on ...

the code above :global abc [:toarray "...} gives no error nor does the :log info ""Websites are ..." does not appear
so the definition is wrong or i am doing something wrong.

Running ROS 7.16

Thank you

Re: define array with several strings  [SOLVED]

Posted: Fri Dec 13, 2024 3:16 am
by Amm0
~ is for a regular expression, not an array...

So you can use a string with a valid regex like:
:global abc "youtube|google|amazon"

Re: define array with several strings

Posted: Sat Dec 14, 2024 12:47 am
by Matthiastik
~ is for a regular expression, not an array...

So you can use a string with a valid regex like:
:global abc "youtube|google|amazon"
You solve everything with such an ease.

Thank you