Mirotik queue change through API

I was implementing time based queue change. Rather than using mikrotik in-built scheduler i thought to execute a crontab through central location. Therefore i tried with except scripting but with telnet it failed or not working properly. I think the returned results might have any color coding input. while searching i stumble on the mikrotik perl api written by Hugh [URL:http://forum.mikrotik.com/viewtopic.php?f=8&t=22744].
i just edited the example code as follows. this is the upgrade this will be edited for the download.

#!/usr/bin/perl -w
#to define the api.
BEGIN {push @INC, '/root/upgradefolder'}
use Mtik ;

$mtik_host = "192.168.28.49";
$mtik_user = "user_script";
$mtik_passwd = "passwordscript";
my(@cmd);
push(@cmd,"/queue/simple/set");
push(@cmd,"=limit-at=6144000/6144000");
push(@cmd,"=max-limit=6144000/6144000");
push(@cmd,"=.id=2M");

$Mtik::debug = 0;
if (Mtik::login($mtik_host,$mtik_user,$mtik_passwd)) {
my($retval,@results) = Mtik::raw_talk(\@cmd);
foreach my $result (@results) {
print ">>> $result\n";
}
Mtik::logout();
}
else {
print "Couldn't log in to $mtik_host\n";
}



Mikrotik side I've enabled api services.

ip service print
Flags: X - disabled, I - invalid
# NAME PORT ADDRESS CERTIFICATE
0 telnet 23 0.0.0.0/0
1 ftp 21 0.0.0.0/0
2 www 80 0.0.0.0/0
3 ssh 22 0.0.0.0/0
4 X www-ssl 443 0.0.0.0/0 none
5 api 8728 0.0.0.0/0
6 winbox 8291 0.0.0.0/0


and named the queue as 2M

>queue simple print
Flags: X - disabled, I - invalid, D - dynamic
0 name="2M" target-addresses=192.168.28.48/29 dst-address=0.0.0.0/0
interface=ether3 parent=none direction=both priority=8
queue=default-small/default-small limit-at=4096000/4096000
max-limit=4096000/4096000 burst-limit=0/0 burst-threshold=0/0
burst-time=0s/0s total-queue=default-small



And added the crontab according to it .

#Auto bandwidth upgrade script
01 19 * * * /root/upgradefolder/test_upgrade.pl
01 07 * * 1-5 /root/upgradefolder/test_downgrade.pl

Comments

mt450 said…
thanks for the post. I am using the same command to change bandwidth on mikrotik user. I am sending following commnad from java program.

ret.sendCommand("/queue/simple/set");
ret.sendCommand("=numbers=");
ret.sendCommand("=max-limit=512K/512K");

After sending the above command I get !done. but bandwidth is not changed.
Hi , I'm not sure about the Java API better to post this question in Mikrotik Forum

Popular posts from this blog

l2tpv3 configuration reference

mikrotik queue tree - Per connection queuing.

Decoding BGP Notification Error