Disclaimer: I am an absolute noob at scripting, please feel free to cleanup/modify/suggest/cuss as needed!
On my network I allow unlimited data download, but on the "“budget package”, I limit speeds during the the day (from 7am) as the Bytes increase. This then resets at 7pm.
At 7am, the Comment on the simple queue is adjust by adding “/bytes since midnite” by this code:
{:global traf;
:global http "0";
:global megsd "0";
:global max "0";
:global logmsg;
:global commnt "";
:set logmsg (" ");
/queue simple
:for i from=1 to=40 do={
:if ([/queue simple find name="10.254.253.$i"]!="") do={:set traf [get [find name="10.254.253.$i"] bytes]; :set megsd ((([:pick $traf ([:find $traf "/"] +1) ([:len $traf])]) + ([:pick $traf 0 ([:find $traf "/"] )]))/1048576);}
:set http ($megsd)
:set logmsg (" ");
:set commnt [get [find name="10.254.253.$i"] comment]
:if ($commnt!="" && $http=0) do={/queue simple set [find name="10.254.253.$i"] comment="$commnt/$megsd"; :set logmsg ("$commnt -10.254.253.$i :7am usage set at $megsd Mb"); }
:if ($commnt!="" && $http>0) do={/queue simple set [find name="10.254.253.$i"] comment="$commnt/$megsd"; :set logmsg ("$commnt -10.254.253.$i :7am usage set at $megsd Mb"); }
:if ($logmsg!=" ") do={ :log error ($logmsg) }
}
:for i from=199 to=200 do={
:if ([/queue simple find name="10.254.255.$i"]!="") do={:set traf [get [find name="10.254.255.$i"] bytes]; :set megsd ((([:pick $traf ([:find $traf "/"] +1) ([:len $traf])]) + ([:pick $traf 0 ([:find $traf "/"] )]))/1048576);}
:set http ($megsd)
:set logmsg (" ");
:set commnt [get [find name="10.254.255.$i"] comment]
:if ($commnt!="" && $http=0) do={/queue simple set [find name="10.254.255.$i"] comment="$commnt/$megsd"; :set logmsg ("$commnt -10.254.255.$i :7am usage set at $megsd Mb"); }
:if ($commnt!="" && $http>0) do={/queue simple set [find name="10.254.255.$i"] comment="$commnt/$megsd"; :set logmsg ("$commnt -10.254.255.$i :7am usage set at $megsd Mb"); }
:if ($logmsg!=" ") do={ :log error ($logmsg) }
}
}
}
This works fine so I get a comment like “Bob/47” on the users simple queue, indicating that Bob as downloaded 47Mb of data since midnite.
Now every half an hour (between 7am and 7pm) I run a script that adjusts the dl speed limits if certain levels of data have been downloaded.
{:global traf;
:global http "0";
:global megsd "0";
:global max "0";
:global logmsg;
:global commnt "";
:global con "";
:global startmb "0";
:set logmsg (" ");
/queue simple
:for i from=2 to=40 do={
:if ([/queue simple find name="10.254.253.$i"]!="") do={:set traf [get [find name="10.254.253.$i"] bytes]; :set megsd ((([:pick $traf ([:find $traf "/"] +1) ([:len $traf])]) + ([:pick $traf 0 ([:find $traf "/"] )]))/1048576);}
:if ([/queue simple find name="10.254.253.$i"]!="") do={:set max [get [find name="10.254.253.$i"] max-limit];}
:set http ($megsd)
:set logmsg (" ");
:set commnt [get [find name="10.254.253.$i"] comment]
:if ($max="64k/128k" && $http>50) do={/queue simple set [find name="10.254.253.$i"] max-limit=64k/96k burst-limit=64k/96k burst-threshold=64k/96k; :set logmsg ("$commnt -10.254.253.$i :Rate Limited at $megsd Mb"); }
:if ($max="64k/96k" && $http>100) do={/queue simple set [find name="10.254.253.$i"] max-limit=64k/64k burst-limit=64k/64k burst-threshold=64k/64k; :set logmsg ("$commnt -10.254.253.$i :Rate Limited at $megsd Mb"); }
:if ($max="64k/64k" && $http>150) do={/queue simple set [find name="10.254.253.$i"] max-limit=32k/50k burst-limit=32k/50k burst-threshold=32k/50k; :set logmsg ("$commnt -10.254.253.$i :Rate Limited at $megsd Mb"); }
:if ($max="32k/50k" && $http>200) do={/queue simple set [find name="10.254.253.$i"] max-limit=32k/32k burst-limit=32k/32k burst-threshold=32k/32k; :set logmsg ("$commnt -10.254.253.$i :Rate Limited at $megsd Mb"); }
:if ($logmsg!=" ") do={ :log error ($logmsg) }
}
/queue simple
:for i from=190 to=205 do={
:if ([/queue simple find name="10.254.255.$i"]!="") do={:set traf [get [find name="10.254.255.$i"] bytes]; :set megsd ((([:pick $traf ([:find $traf "/"] +1) ([:len $traf])]) + ([:pick $traf 0 ([:find $traf "/"] )]))/1048576);}
:if ([/queue simple find name="10.254.255.$i"]!="") do={:set max [get [find name="10.254.255.$i"] max-limit];}
:set http ($megsd)
:set logmsg (" ");
:set commnt [get [find name="10.254.255.$i"] comment]
:if ($max="64k/128k" && $http>50) do={/queue simple set [find name="10.254.255.$i"] max-limit=64k/96k burst-limit=64k/96k burst-threshold=64k/96k; :set logmsg ("$commnt -10.254.253.$i :Rate Limited at $megsd Mb"); }
:if ($max="64k/96k" && $http>100) do={/queue simple set [find name="10.254.255.$i"] max-limit=64k/64k burst-limit=64k/64k burst-threshold=64k/64k; :set logmsg ("$commnt -10.254.253.$i :Rate Limited at $megsd Mb"); }
:if ($max="64k/64k" && $http>150) do={/queue simple set [find name="10.254.255.$i"] max-limit=32k/50k burst-limit=32k/50k burst-threshold=32k/50k; :set logmsg ("$commnt -10.254.253.$i :Rate Limited at $megsd Mb"); }
:if ($max="32k/50k" && $http>200) do={/queue simple set [find name="10.254.255.$i"] max-limit=32k/32k burst-limit=32k/32k burst-threshold=32k/32k; :set logmsg ("$commnt -10.254.255.$i :Rate Limited at $megsd Mb"); }
:if ($logmsg!=" ") do={ :log error ($logmsg) }
}
}
This works fine and sets the rate limits as required and prints to log in red (error) to catch my eye.
Now my problem, which I am failing to solve.
I want to subtract the current 7am Mb from the Current Mb and then test that to see if the rate limiting should be applied. This would mean using a pcik command on each comment and saving the number after the / as a variable, and then subtracting this $http. How do I save that part after the / in the comment as a variable? I want the 47 as variable (say $7am) from “Bob/47” so that $max = $http-$7am…if that makes sense.
Thanks for reading, and any time you might spend on this problem.
Regards
Brian
Zimbabwe