Sunday, December 12, 2010

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:].
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 = "";
$mtik_user = "user_script";
$mtik_passwd = "passwordscript";

$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";
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
0 telnet 23
1 ftp 21
2 www 80
3 ssh 22
4 X www-ssl 443 none
5 api 8728
6 winbox 8291

and named the queue as 2M

>queue simple print
Flags: X - disabled, I - invalid, D - dynamic
0 name="2M" target-addresses= dst-address=
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/
01 07 * * 1-5 /root/upgradefolder/

CCNA Access list lab

Tasks are defined in the packet trace file. network ip address not bound to the PC.
Otherwise this is the basic diagram.