I investigated doing this via the API but found it to be quite difficult and not ideal for someone new to RouterOS.
I in the end settled on scripting a SSH session in PHP.
I currently run some screen scraping PHP cron jobs that connect to my ISP's management pages (clueless on AAISP, a UK independent internet provider) and grab relevant information, one piece of information that is retrieved is my current IP / Bras profile.
Using this information and an available PHP SSH library I created a script to talk to my RB and automatically update the max limit on my relevant download queue trees.
I though I would share this here in the hope it is useful for other people.
First of you will need to install the following SSH library for PHP details on how to do this are listed here: http://kevin.vanzonneveld.net/techblog/ ... _with_php/
You can then include the following PHP script (or modify it) to make the changes to your queue trees.
You will need to call this script from another PHP file using the following method : update_queue_profile($profile) where $profile is the IP / Bras profile rate in megabits per second, for example 9,10,8,7.1. It expect this in that kind of format and not in kilobits.
Obviously I don't know how you will get your rate in megabits as I get mine from screen scraping a webpage at my ISP's end, you may wish do get your actual sync rate from your modem via SNMP and do some calculations based on that or you may get a direct feed from your ISP via xml or the like.
If people would like to see my screen scraping scrips for AAISP or for my Zyxel router (I get information from both and insert them into a mysql database) please let me know.
My script is rather basic and I have no doubt can be improved.
You will need to change the variables $rbUser to reflect your routeros username and $rbPass for the password. You will also need to change the $queuetrees array to reflect the name of your queue trees.
Code: Select all
<?php
function update_queue_profile($profile){
$kbrate=calculate_rate($profile);
if($kbrate>1000){
//basic check if we have a profile that is less than 1M something is up so dont make change
$rbUser = "RouterOS UserName";
$rbPass = "RouterOS Password";
$queuetrees = array('"Incoming queue"','"Critical download"','"High-pri interactive download"','"Low-pri interactive download"','"Low-pri non-marked download"','"Low-pri non-interactive download"');
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
if(!($con = ssh2_connect("192.168.0.254", 22))){
echo "fail: unable to establish connection\n";
} else {
// try to authenticate with username root, password secretpassword
if(!ssh2_auth_password($con, $rbUser, $rbPass)) {
echo "fail: unable to authenticate\n";
} else {
foreach($queuetrees as $q){
if (!($stream = ssh2_exec($con, "/queue tree set " .$q ." max-limit=" .$kbrate ."k" ))) {
echo "fail: unable to execute command\n";
} else {
stream_set_blocking($stream, true);
fclose($stream);
}
}
}
}
}else{
}
}
function calculate_rate($profile){
//convert to float and check if sane
$profileF = floatval($profile);
if ($profileF>0){
//we did not get 0 so we make the assumption (maybe wrong) that we are in Mbits so values like 10, 11, 8,7.1 etc
//we need to convert this to kilobits as this will make things easier then take 95% of the value (overheads) and pass
//this value back.
$kbits = $profileF*1000;
$per95 = ($kbits/100)*95;
return $per95;
}else{
//if we end up with zero just pass this back
//and debug upstream
return 0;
}
}
?>