Community discussions

MikroTik App
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

Usermanager 5 Script to change rate limits based on usage

Thu Nov 29, 2012 10:15 pm

Hi all

I had a script running in Usermanager 4 that could change the rate limits if a user used more than a 40 Gigs amount of data in a month.

I have in the mean while upgraded my usermanager router to routeros v5.21

This script does not work in usermanager 5.21 any more

I have tried making corrections to the syntax but it doesn't work

{
:local user
:local surname
:local bytesin
:local bytesout
:local bytestotal
:local megstotal
:local profilename

/tool user-manager user
:foreach i in=[find customer="admin"] do={

:set user [get $i first-name]
:set surname [get $i last-name]
:set bytesin [get $i download-used]
:set bytesout [get $i upload-used]
:set bytestotal ($bytesin + $bytesout)
:set megstotal ($bytestotal / 1000000)
:set profilename [get $i actual-profile]

:if (($megstotal > 40000) && ($profilename= "1.5 M Uncapped")) do={
/tool user-manager profile limitation set [find name="$user"] Rate-limit="192k/192k 192k/288k 96k/144k 60/60 0 "
:log info "User Rate Limit set to 192k/192k 192k/288k 96k/144k 60/60 0 "
:log info $user
:log info $profilename
:log info $megstotal}

}
}


Any help will be appreciated to get it working
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Usermanager 5 Script to change rate limits based on usag

Fri Nov 30, 2012 12:06 am

Looks like the syntax labeling has changed... The Rate-limit label no longer exists.
screen1.gif
...and has been broken up into multiple labels:
screen2.gif
So, you'll have to change this line of your script:
/tool user-manager profile limitation set [find name="$user"] Rate-limit="192k/192k 192k/288k 96k/144k 60/60 0 "
To something like this (except I don't know what that last 0 (zero) was for in your code above...)
/tool user-manager profile limitation set [find name="$user"] rate-limit-rx=192k rate-lim
it-tx=192k rate-limit-burst-rx=192k rate-limit-burst-tx=288k rate-limit-burst-treshold-r
x=96k rate-limit-burst-treshold-tx=144k rate-limit-burst-time-rx=60s rate-limit-burst-ti
me-tx=60s
You do not have the required permissions to view the files attached to this post.
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

Re: Usermanager 5 Script to change rate limits based on usag

Sun Dec 02, 2012 7:41 pm

Thank you very much for your assistance. I am going to try this and will post my findings.

Regards
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

Re: Usermanager 5 Script to change rate limits based on usag

Tue Dec 04, 2012 7:51 pm

Hi Skot I am completely lost

The script executes only the log info at the bottom but the rate limits are not changed in user-manager

{
:local user
:local surname
:local bytesin
:local bytesout
:local bytestotal
:local megstotal
:local profilename

/tool user-manager user
:foreach i in=[find customer="admin"] do={

:set user [get $i first-name]
:set surname [get $i last-name]
:set bytesin [get $i download-used]
:set bytesout [get $i upload-used]
:set bytestotal ($bytesin + $bytesout)
:set megstotal ($bytestotal / 1000000)
:set profilename [get $i actual-profile]

:put "megstotal:$megstotal"

:if (($megstotal > 1900) && ($profilename= "1.5 M Uncapped")) do={
/tool user-manager profile limitation set [find name="$user"] rate-limit-rx=192k rate-limit-tx=192k rate-limit-burst-rx=192k rate-limit-burst-tx=288k rate-limit-burst-treshold-rx=96k rate-limit-burst-treshold-tx=144k rate-limit-burst-time-rx=60s rate-limit-burst-time-tx=60s

:log info $user
:log info $profilename
:log info $megstotal}

}
}
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Usermanager 5 Script to change rate limits based on usag

Wed Dec 05, 2012 7:32 am

If you copy / paste code in Terminal, are there any errors?
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

Re: Usermanager 5 Script to change rate limits based on usag

Wed Dec 05, 2012 9:35 pm

There are no errors when I copy into Terminal
You do not have the required permissions to view the files attached to this post.
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Usermanager 5 Script to change rate limits based on usag

Fri Dec 07, 2012 9:09 am

When I run that script on v5.21, it erases all the rate limits! Trying to figure it out...

Does it do anything when you run it? Are any of the rates changed or erased?
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Usermanager 5 Script to change rate limits based on usag

Sun Dec 09, 2012 10:17 am

Using v5.22, the problem still exists. There are problems when setting values in User Manager > Profiles > Limitations > Rate Limits using the command line. (The web interface works fine. There I can add / edit / remove values without any problem)

I start with a blank Limitation profile:
s1.gif
I try to add a combination of values, or a single value.
/tool user-manager profile limitation set [find name="John"] rate-limit-rx=524288 rate-limit-tx=524288;
/tool user-manager profile limitation set [find name="John"] rate-limit-burst-time-tx=90;

Profile remains blank:
s1.gif
I use Web interface to add values, they work:
s2.gif
It seems that settings these values from the Terminal somehow hinges upon the Rate limit Rx and Rate limit Tx. If I set the Rate limit Rx or Rate limit Rx in the web interface, then I am able to add / edit any of the other rate-limit-... values from the Terminal, one at a time, or in a group. Setting these other values does not seem to cause any problems.
/tool user-manager profile limitation set [find name="John"] rate-limit-burst-rx=2M
/tool user-manager profile limitation set [find name="John"] rate-limit-burst-treshold-rx=512k rate-limit-burst-treshold-tx=256k rate-limit-burst-time-rx=2m rate-limit-burst-time-tx=60
s3.gif
Now if I try to set the Rate limit Rx and Rate limit Tx from the command line, I have mixed results. It seems setting values to a higher number works fine:
/tool user-manager profile limitation set [find name="John"] rate-limit-tx=5M
But sometimes a lower number might cause all rate-limit... values to disappear!
/tool user-manager profile limitation set [find name="John"] rate-limit-rx=512
Web interface still shows previous values, but when I log out / log back in, they are gone again, all blank.
s1.gif
You do not have the required permissions to view the files attached to this post.
 
vahidjaf
just joined
Posts: 4
Joined: Sat Dec 08, 2012 2:43 pm

Re: Usermanager 5 Script to change rate limits based on usag

Sun Dec 09, 2012 11:57 am

....
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

Re: Usermanager 5 Script to change rate limits based on usag

Thu Dec 13, 2012 8:14 pm

Hi Skot

Thanks for your time spent to help me with the problem

I would not have figured this out myself ;-)

I hope Mikrotik fix this bug soon.
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

Re: Usermanager 5 Script to change rate limits based on usag

Tue Dec 18, 2012 10:23 pm

Hi Skot

I realized that there is no need for changing the rate limitation details with a script in v 5.22.

When a customer's monthly usage exceed a certain amount of data, a script must activate a predefined profile with reduced speed.

I am struggling with the terminal command to activate a predefined profile.

Do you know what the terminal command is for activating a predefined profile?
 
User avatar
skot
Long time Member
Long time Member
Posts: 584
Joined: Wed Nov 30, 2011 3:05 am

Re: Usermanager 5 Script to change rate limits based on usag

Thu Dec 20, 2012 7:18 pm

Do you know what the terminal command is for activating a predefined profile?
This command will create and activate a predefined profile for a user:
/tool user-manager user create-and-activate-profile UserName customer=admin profile="1.5 M Uncapped";
Depending on the Profile settings, this change will either start "Now" or "At first Login"
t.gif
However, I don't see a command to remove a profile. (You can view available commands by typing, for example, /tool user-manager user, and then pressing Tab):
s.gif
So, running that command does change the profile, but causes the old profiles to keep stacking up... You can remove them from the web interface, but I can't find where to do this from the command line...
u.gif
You do not have the required permissions to view the files attached to this post.
 
jparg
just joined
Posts: 8
Joined: Thu Apr 18, 2013 6:57 pm
Location: Bahia Blanca, Argentina

Re: Usermanager 5 Script to change rate limits based on usag

Tue Aug 27, 2013 6:55 pm

Hi.

How can i Active the profile by the terminal?

Because if i add a new profile, the status is Waiting or Paused, but never is Active.

Do you know what the terminal command is for activating a predefined profile?
This command will create and activate a predefined profile for a user:
/tool user-manager user create-and-activate-profile UserName customer=admin profile="1.5 M Uncapped";
Depending on the Profile settings, this change will either start "Now" or "At first Login"
t.gif
However, I don't see a command to remove a profile. (You can view available commands by typing, for example, /tool user-manager user, and then pressing Tab):
s.gif
So, running that command does change the profile, but causes the old profiles to keep stacking up... You can remove them from the web interface, but I can't find where to do this from the command line...
u.gif

Who is online

Users browsing this forum: flapviv and 32 guests