Page 1 of 1
:if do=[ help ????
Posted: Wed Oct 07, 2009 10:12 pm
by mohamed
im use mikrotik v 3.13 on pc hotspot lan network
i need scrept to like that
:if ([:len [//queue simple %nmber-of-red-colour%]] >=5) do={/ip proxy access enable [/ip proxy access find comment=1]}
and i use user profile to limet the speed
Re: :if do=[ help ????
Posted: Wed Oct 07, 2009 11:14 pm
by fewi
While you can't directly retrieve the number of queues shown red in the GUI, here a quick snippet that should work for counting up the number of Hotspot queues that are over 90% utilization at that point in time:
:local count 0;
# cycle through all Hotspot queues
:foreach queue in=[/queue simple find name~"^<hotspot"] do={
# retrieve max-limit for queue
:local limit [/queue simple get $queue max-limit];
# take out the upload limit, since we only care about downstream traffic
:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];
# convert k and m abbreviations into numerical values
:if ([:pick $limit ([:len $limit] - 1)] = "k") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000)
};
:if ([:pick $limit ([:len $limit] - 1)] = "m") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000000)
};
# get the current rate in the queue
:local rate [/queue simple get $queue rate];
# again parse out the downstream portion
:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];
# calculate the delta between the two
:local delta ($limit - $rate);
# increase high utilization queue count if delta is within 10% of queue size of filling up the queue (75% utilization)
:if ($delta < ($limit / 4)) do={
:set count ($count + 1)
}
};
:put $local;
Though I'm not sure why you wouldn't want the proxy to be enabled at all times. Also, I'm not sure at all how well that code would scale for lots of Hotspot users. It does quite a bit of work to get to the count. There may be much better solutions to what you actually want to achieve, I was mostly curious how you could script out calculating queue utilization.
Re: :if do=[ help ????
Posted: Wed Oct 07, 2009 11:28 pm
by Chupaka
p.s. red is >= 75%
Re: :if do=[ help ????
Posted: Wed Oct 07, 2009 11:38 pm
by fewi
Edited script to reflect that.
Re: :if do=[ help ????
Posted: Thu Oct 08, 2009 12:32 am
by mohamed
While you can't directly retrieve the number of queues shown red in the GUI, here a quick snippet that should work for counting up the number of Hotspot queues that are over 90% utilization at that point in time:
:local count 0;
# cycle through all Hotspot queues
:foreach queue in=[/queue simple find name~"^<hotspot"] do={
# retrieve max-limit for queue
:local limit [/queue simple get $queue max-limit];
# take out the upload limit, since we only care about downstream traffic
:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];
# convert k and m abbreviations into numerical values
:if ([:pick $limit ([:len $limit] - 1)] = "k") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000)
};
:if ([:pick $limit ([:len $limit] - 1)] = "m") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000000)
};
# get the current rate in the queue
:local rate [/queue simple get $queue rate];
# again parse out the downstream portion
:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];
# calculate the delta between the two
:local delta ($limit - $rate);
# increase high utilization queue count if delta is within 10% of queue size of filling up the queue (75% utilization)
:if ($delta < ($limit / 4)) do={
:set count ($count + 1)
}
};
:put $local;
Though I'm not sure why you wouldn't want the proxy to be enabled at all times. Also, I'm not sure at all how well that code would scale for lots of Hotspot users. It does quite a bit of work to get to the count. There may be much better solutions to what you actually want to achieve, I was mostly curious how you could script out calculating queue utilization.
Initially thanks for your replay
and this is wat i mean by comment=1
add action=deny comment=1 disabled=yes path=*.exe
add action=deny comment=1 disabled=yes path=*.rar
add action=deny comment=1 disabled=yes path=*.zip
add action=deny comment=1 disabled=yes path=*.mp3
add action=deny comment=1 disabled=yes path=*.wav
add action=deny comment=1 disabled=yes path=*.ram
add action=deny comment=1 disabled=yes path=*.wmv
add action=deny comment=1 disabled=yes path=*.rmvb
add action=deny comment=1 disabled=yes path=*.avi
add action=deny comment=1 disabled=yes path=*.asf
add action=deny comment="" disabled=yes path=*.torren
you mean !!
:if ([:len [
:local count 0;
# cycle through all Hotspot queues
:foreach queue in=[/queue simple find name~"^<hotspot"] do={
# retrieve max-limit for queue
:local limit [/queue simple get $queue max-limit];
# take out the upload limit, since we only care about downstream traffic
:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];
# convert k and m abbreviations into numerical values
:if ([:pick $limit ([:len $limit] - 1)] = "k") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000)
};
:if ([:pick $limit ([:len $limit] - 1)] = "m") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000000)
};
# get the current rate in the queue
:local rate [/queue simple get $queue rate];
# again parse out the downstream portion
:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];
# calculate the delta between the two
:local delta ($limit - $rate);
# increase high utilization queue count if delta is within 10% of queue size of filling up the queue (75% utilization)
:if ($delta < ($limit / 4)) do={
:set count ($count + 1)
}
};
:put $local;]] >= 75%)do={/ip proxy access enable [/ip proxy access find comment=1]}
or wat did u mean????
Re: :if do=[ help ????
Posted: Thu Oct 08, 2009 12:35 am
by mohamed
p.s. red is >= 75%
thanks mr Chupaka i think u remember me !!!!
Re: :if do=[ help ????
Posted: Thu Oct 08, 2009 12:50 am
by fewi
Well, no. That wouldn't make any sense at all. A complete script would look something like this:
:local count 0;
# cycle through all Hotspot queues
:foreach queue in=[/queue simple find name~"^<hotspot"] do={
# retrieve max-limit for queue
:local limit [/queue simple get $queue max-limit];
# take out the upload limit, since we only care about downstream traffic
:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];
# convert k and m abbreviations into numerical values
:if ([:pick $limit ([:len $limit] - 1)] = "k") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000)
};
:if ([:pick $limit ([:len $limit] - 1)] = "m") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000000)
};
# get the current rate in the queue
:local rate [/queue simple get $queue rate];
# again parse out the downstream portion
:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];
# calculate the delta between the two
:local delta ($limit - $rate);
# increase high utilization queue count if delta is within 10% of queue size of filling up the queue (75% utilization)
:if ($delta < ($limit / 4)) do={
:set count ($count + 1)
}
};
:if ($count >=5) do={
:foreach proxyElement in=[/ip proxy access find comment=1] do={
/ip proxy access enable $proxyElement;
}
}
Re: :if do=[ help ????
Posted: Thu Oct 08, 2009 1:39 am
by mohamed
I'm sorry its not working
and thanks
Re: :if do=[ help ????
Posted: Thu Oct 08, 2009 2:01 am
by fewi
Works for me. Here a slightly extended script that prints the proxy access items, logs whether or not it'll change anything, and then prints them again. Modified just like you did to fire on 1 or more overutilized queue:
[admin@MikroTik] > /system script print
Flags: I - invalid
0 name="stuff" owner="admin" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive last-started=oct/07/2009 15:47:54 run-count=1 source=
/ip proxy access print terse
:local count 0;
# cycle through all Hotspot queues
:foreach queue in=[/queue simple find name~"^<hotspot"] do={
# retrieve max-limit for queue
:local limit [/queue simple get $queue max-limit];
# take out the upload limit, since we only care about downstream traffic
:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];
# convert k and m abbreviations into numerical values
:if ([:pick $limit ([:len $limit] - 1)] = "k") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000)
};
:if ([:pick $limit ([:len $limit] - 1)] = "m") do={
:set limit [:pick $limit 0 ([:len $limit] - 1)];
:set limit ($limit * 1000000)
};
# get the current rate in the queue
:local rate [/queue simple get $queue rate];
# again parse out the downstream portion
:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];
# calculate the delta between the two
:local delta ($limit - $rate);
# increase high utilization queue count if delta is within 10% of queue size of filling up the queue (75% utilization)
:if ($delta < ($limit / 4)) do={
:set count ($count + 1)
}
};
:if ($count >=1) do={
:put "enabling proxy access rules"
:foreach proxyElement in=[/ip proxy access find comment=1] do={
/ip proxy access enable $proxyElement;
}
} else={
:put "not enabling proxy access rules, condition not met"
}
/ip proxy access print terse
Test box in my lab, just one logged in Hotspot user (so there's one queue):
[admin@MikroTik] > /queue simple print
Flags: X - disabled, I - invalid, D - dynamic
0 D name="<hotspot-test>" target-addresses=10.2.1.254/32 dst-address=0.0.0.0/0 interface=all parent=none direction=both priority=8 queue=default-small/default-small limit-at=128k/128k max-limit=128k/128k burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s total-queue=default-small
1 D name="hs-<Wired>" dst-address=0.0.0.0/0 interface=Wired parent=none direction=both priority=8 queue=hotspot-default/hotspot-default limit-at=1M/1M max-limit=1M/1M burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s total-queue=default-small
2 D name="hs-<Wireless>" dst-address=0.0.0.0/0 interface=Wireless parent=none direction=both priority=8 queue=hotspot-default/hotspot-default limit-at=1M/1M max-limit=1M/1M burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s total-queue=default-small
At this point the client is not passing any traffic, rate is 0/0:
[admin@MikroTik] > :put [/queue simple get 0 rate]
0/0
Run the script:
[admin@MikroTik] > /system script run 0
0 X comment=1 src-address=1.1.1.1 dst-address=2.2.2.2 action=allow hits=0
not enabling proxy access rules, condition not met
0 X comment=1 src-address=1.1.1.1 dst-address=2.2.2.2 action=allow hits=0
As expected the condition of "($count >= 1)" is not met and no proxy access items are enabled. I started a large download on the client:
[admin@MikroTik] > :put [/queue simple get 0 rate]
4584/129000
Run the script again:
[admin@MikroTik] > /system script run 0
0 X comment=1 src-address=1.1.1.1 dst-address=2.2.2.2 action=allow hits=0
enabling proxy access rules
0 comment=1 src-address=1.1.1.1 dst-address=2.2.2.2 action=allow hits=0
And the proxy access rule has been enabled.
----
What happens when you run just
:foreach proxyElement in=[/ip proxy access find comment=1] do={/ip proxy access enable $proxyElement;}
Does that enable all the proxy access items? If not, please post the output of
/ip proxy access print detail where disabled=yes
Re: :if do=[ help ????
Posted: Thu Oct 08, 2009 4:32 am
by mohamed
ok
i try to do wat you say and that wat i have
[admin@Mohamed]/system script print
8 name="ques2" owner="admin" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff
last-started=oct/08/2009 03:21:05 run-count=5
source=:local count 0;:foreach queue in=[/queue simple find name~"^<hotspot"] do={:local limit [/queue simple get
$queue max-limit];:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];:if ([:pick $limit ([:len
$limit] - 1)] = "k") do={:set limit [:pick $limit 0 ([:len $limit] - 1)];:set limit ($limit * 1000)};:if
([:pick $limit ([:len $limit] - 1)] = "m") do={:set limit [:pick $limit 0 ([:len $limit] - 1)];:set limit
($limit * 1000)};:local rate [/queue simple get $queue rate];:set rate [:pick $rate ([:find $rate "/"] + 1)
[:len $rate]];:local delta ($limit - $rate);:if ($delta < ($limit / 4)) do={:set count ($count + 1)}};:if
($count >=1) do={:put "enabling proxy access rules";:foreach proxyElement in=[/ip proxy access find comment=1]
do={/ip proxy access enable $proxyElement;}} else={:put "not enabling proxy access rules, condition not met"}
[admin@Mohamed]/queue simple print
0 D name="<hotspot-185>" target-addresses=192.168.0.185/32 dst-address=0.0.0.0/0 interface=all parent=none direction=bot>
priority=8 queue=default-small/default-small limit-at=32000/64000 max-limit=32000/64000 burst-limit=0/0
burst-threshold=0/0 burst-time=0s/0s total-queue=default-small
1 D name="<hotspot-176>" target-addresses=192.168.0.176/32 dst-address=0.0.0.0/0 interface=all parent=none direction=bot>
priority=8 queue=default-small/default-small limit-at=56000/280000 max-limit=56000/280000 burst-limit=56000/320000
burst-threshold=56000/280000 burst-time=10s/10s total-queue=default-small
2 D name="<hotspot-166>" target-addresses=192.168.0.166/32 dst-address=0.0.0.0/0 interface=all parent=none direction=bot>
priority=8 queue=default-small/default-small limit-at=56000/280000 max-limit=56000/280000 burst-limit=56000/320000
burst-threshold=56000/280000 burst-time=10s/10s total-queue=default-small
3 D name="<hotspot-118>" target-addresses=192.168.0.118/32 dst-address=0.0.0.0/0 interface=all parent=none direction=bot>
priority=8 queue=default-small/default-small limit-at=56000/280000 max-limit=56000/280000 burst-limit=56000/320000
burst-threshold=56000/280000 burst-time=10s/10s total-queue=default-small
4 D name="<hotspot-196>" target-addresses=192.168.0.196/32 dst-address=0.0.0.0/0 interface=all parent=none direction=bot>
priority=8 queue=default-small/default-small limit-at=56000/280000 max-limit=56000/280000 burst-limit=56000/320000
burst-threshold=56000/280000 burst-time=10s/10s total-queue=default-small
5 D name="<hotspot-110>" target-addresses=192.168.0.110/32 dst-address=0.0.0.0/0 interface=all parent=none direction=bot>
priority=8 queue=default-small/default-small limit-at=56000/280000 max-limit=56000/280000 burst-limit=56000/320000
burst-threshold=56000/280000 burst-time=10s/10s total-queue=default-small
6 D name="<hotspot-132>" target-addresses=192.168.0.132/32 dst-address=0.0.0.0/0 interface=all parent=none direction=bot>
priority=8 queue=default-small/default-small limit-at=56000/280000 max-limit=56000/280000 burst-limit=56000/320000
burst-threshold=56000/280000 burst-time=10s/10s total-queue=default-small
7 D name="<hotspot-170>" target-addresses=192.168.0.170/32 dst-address=0.0.0.0/0 interface=all parent=none direction=bot>
priority=8 queue=default-small/default-small limit-at=56000/280000 max-limit=56000/280000 burst-limit=56000/320000
burst-threshold=56000/280000 burst-time=10s/10s total-queue=default-small
8 D name="<hotspot-102>" target-addresses=192.168.0.102/32 dst-address=0.0.0.0/0 interface=all parent=none direction=bot>
priority=8 queue=default-small/default-small limit-at=56000/280000 max-limit=56000/280000 burst-limit=56000/320000
burst-threshold=56000/280000 burst-time=10s/10s total-queue=default-small
9 D name="<hotspot-178>" target-addresses=192.168.0.178/32 dst-address=0.0.0.0/0 interface=all parent=none direction=bot>
priority=8 queue=default-small/default-small limit-at=32000/200000 max-limit=32000/200000 burst-limit=0/0
burst-threshold=0/0 burst-time=0s/0s total-queue=default-small
10 D name="hs-<hotspot1>" dst-address=0.0.0.0/0 interface=Lan parent=none direction=both priority=8
queue=hotspot-default/hotspot-default limit-at=0/0 max-limit=0/0 burst-limit=0/0 burst-threshold=0/0
[admin@Mohamed]/system script> run 8
not enabling proxy access rules, condition not met
[admin@Mohamed]/ip proxy access print detail where disabled=yes
Flags: X - disabled
0 X ;;; 1
path=*.exe action=deny hits=82818
1 X ;;; 1
path=*.rar action=deny hits=563862
2 X ;;; 1
path=*.zip action=deny hits=2811
3 X ;;; 1
path=*.mp3 action=deny hits=92659
4 X ;;; 1
path=*.wav action=deny hits=224
5 X ;;; 1
path=*.ram action=deny hits=447
6 X ;;; 1
path=*.wmv action=deny hits=3529
7 X ;;; 1
path=*.rmvb action=deny hits=29618
8 X ;;; 1
path=*.avi action=deny hits=35782
9 X ;;; 1
path=*.asf action=deny hits=38
10 X ;;; 1
path=*.torren action=deny hits=0
the condition not met mean = $count >=1 have'nt any client over 75 % ????
if its mean that wen i run thes script i was have 4 client over 75%
and itray it alot of time
Re: :if do=[ help ????
Posted: Thu Oct 08, 2009 7:02 pm
by fewi
:local count 0;:foreach queue in=[/queue simple find name~"^<hotspot"] do={:local limit [/queue simple get $queue max-limit];:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];:if ([:pick $limit ([:len $limit] - 1)] = "k") do={:set limit [:pick $limit 0 ([:len $limit] - 1)];:set limit ($limit * 1000)};:if ([:pick $limit ([:len $limit] - 1)] = "M") do={:set limit [:pick $limit 0 ([:len $limit] - 1)];:set limit ($limit * 1000)};:local rate [/queue simple get $queue rate];:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];:local delta ($limit - $rate);:if ($delta < ($limit / 4)) do={:set count ($count + 1); :put "rate: $rate, limit: $limit, increasing count"} else={:put "rate: $rate, limit: $limit, not increasing count"}};:put "total count: $count";:if ($count >=1) do={:put "enabling proxy access rules";:foreach proxyElement in=[/ip proxy access find comment=1] do={/ip proxy access enable $proxyElement;}} else={:put "not enabling proxy access rules, condition not met"}
Try that for debugging purposes
Re: :if do=[ help ????
Posted: Thu Oct 08, 2009 9:50 pm
by mohamed
tahts wat i have
Re: :if do=[ help ????
Posted: Thu Oct 08, 2009 10:47 pm
by fewi
The script I posted last should be printing additional debug lines.
Re: :if do=[ help ????
Posted: Fri Oct 09, 2009 3:41 am
by mohamed
im sory mr
fewi itray wat would u say its right script but its not wat i need also i need if 4 user make download enable the proxy wich disable the download or disble exe,avi ......
:if ([:len [//queue simple
%nmber-of-red-colour%]] >=5) do={/ip proxy access enable [/ip proxy access find comment=1]}
wen i tray this
:local count 0;:foreach queue in=[/queue simple find name~"^<hotspot"] do={:local limit [/queue simple get $queue max-limit];:set limit [:pick $limit ([:find $limit "/"] + 1) [:len $limit]];:if ([:pick $limit ([:len $limit] - 1)] = "k") do={:set limit [:pick $limit 0 ([:len $limit] - 1)];:set limit ($limit * 1000)};:if ([:pick $limit ([:len $limit] - 1)] = "M") do={:set limit [:pick $limit 0 ([:len $limit] - 1)];:set limit ($limit * 1000)};:local rate [/queue simple get $queue rate];:set rate [:pick $rate ([:find $rate "/"] + 1) [:len $rate]];:local delta ($limit - $rate);:if ($delta < ($limit / 4)) do={:set count ($count + 1); :put "rate: $rate, limit: $limit, increasing count"} else={:put "rate: $rate, limit: $limit, not increasing count"}};:put "total count: $count";:if ($count >=1) do={:put "enabling proxy access rules";:foreach proxyElement in=[/ip proxy access find comment=1] do={/ip proxy access enable $proxyElement;}} else={:put "not enabling proxy access rules, condition not met"}
and its not working
iwas have 4 client make downlaod
Re: :if do=[ help ????
Posted: Fri Oct 09, 2009 3:56 am
by fewi
Unless I'm mistaken, that screenshot does not show you running the script you quote in the same post. The script you're quoting in the same post outputs one line per Hotspot queue found.
If you are sure you're running that script, post the output of
foreach queue in=[/queue simple find name~"^<hotspot"] do={:put /queue simple get $queue name}
If that doesn't output anything, version 3.13 doesn't support find by regular expression and the script cannot work on 3.13, and you'd have to upgrade to 3.30 (as stated earlier, the script works for me running 3.30). Maybe try upgrading anyway and see if it works.
Re: :if do=[ help ????
Posted: Fri Oct 09, 2009 4:10 am
by mohamed
Unless I'm mistaken, that screenshot does not show you running the script you quote in the same post. The script you're quoting in the same post outputs one line per Hotspot queue found.
If you are sure you're running that script, post the output of
foreach queue in=[/queue simple find name~"^<hotspot"] do={:put /queue simple get $queue name}
If that doesn't output anything, version 3.13 doesn't support find by regular expression and the script cannot work on 3.13, and you'd have to upgrade to 3.30 (as stated earlier, the script works for me running 3.30). Maybe try upgrading anyway and see if it works.
ok thank u very mach and this is the out put of it
out.JPG
and i well tray to upgrading to 3.30 and tray but thanks thanks thanks !!!
Re: :if do=[ help ????
Posted: Fri Oct 09, 2009 4:25 am
by fewi
I'm sorry I was quickly posting that before leaving work and that code won't run:
:foreach queue in=[/queue simple find name~"^<hotspot"] do={:put [/queue simple get $queue name]}
Try that instead. My apologies.
Re: :if do=[ help ????
Posted: Fri Oct 09, 2009 4:53 am
by mohamed
I'm sorry I was quickly posting that before leaving work and that code won't run:
:foreach queue in=[/queue simple find name~"^<hotspot"] do={:put [/queue simple get $queue name]}
Try that instead. My apologies.
as welcom
thanks.JPG
Re: :if do=[ help ????
Posted: Fri Oct 09, 2009 5:43 am
by fewi
I think that pretty much confirms that the script is incompatible with 3.13. I'm unable to downgrade anything to that to test myself, so I'm afraid I can't help out any further unless you go up to 3.30.
Re: :if do=[ help ????
Posted: Sun Oct 11, 2009 11:44 pm
by mohamed
ok ihave an idea
:if [/queue simlpe get $i total-rate] >=1m) do={/ip proxy access enable [/ip proxy access find comment=1]}
i mean if the all queue simlpe rate >=1m do ip proxy access enable find comment=1
haw can i Type that in the mikrotik ?????