Community discussions

MUM Europe 2020
 
talmage
just joined
Topic Author
Posts: 5
Joined: Mon Aug 04, 2008 12:53 am

API Example

Mon Aug 04, 2008 12:58 am

Hi All,

I hope this is the right place to ask this question.

I am new to the MT API and am trying to create a set of scripts to collect some data and also do management of the MT using the API rather than attempting to use telnet to emulate a console.

I have found the numerous versions of the API (PHP, Perl, Python, etc) and have read the wiki on the API. However, I am still not sure how I would do a command such as:

:put [/queue simple get [/queue simple find target-address="10.10.10.251"] total-packets]

In the API.

Would there be a more efficient way to accomplish the same task using the API than the above console command?


I appreciate any help that you can provide as I learn quickly from seeing examples of basics and building on those examples.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6283
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: API Example

Mon Aug 04, 2008 1:06 pm

you cannot use :put or other commands that start with colon. (:beep does not work also)
 
talmage
just joined
Topic Author
Posts: 5
Joined: Mon Aug 04, 2008 12:53 am

Re: API Example

Mon Aug 04, 2008 6:37 pm

I feared as much.

In that case: Could anyone provide some example(s) of what I would send to the API to reproduce a similar result?
 
User avatar
vsaldarriaga
just joined
Posts: 6
Joined: Thu Jun 26, 2008 8:48 pm
Location: Colombia

Re: API Example

Fri Aug 22, 2008 2:36 am

I feared as much.

In that case: Could anyone provide some example(s) of what I would send to the API to reproduce a similar result?
I am also having problems running the python code on the wiki, there are non-utf characters that choke the python interpreter. Are they \xFF ?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5959
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: API Example

Fri Aug 22, 2008 7:32 am

/queue/simple/find - will list all simple queue IDs

Now for each id
/queue/simple/get =.id=<any_number_you_get_from_previous_command>

You will get all values from specific queue, like example below:
!done
=ret=.id=*c,.nextid=*ffffffff,name=queue7,dst-address=0.0.0.0/0,dst-netmask=0.0.0.0,interface=all,parent=none,packet-marks=aaaa,direction=both,priority=8,queue=default-small/default-small,limit-at=0/0,max-limit=0/0,burst-limit=0/0,burst-threshold=0/0,burst-time=0s/0s,total-queue=default-small,bytes=0/0,total-bytes=0,packets=0/0,total-packets=0,dropped=0/0,total-dropped=0,overlimits=0/0,total-overlimits=0,rate=0/0,total-rate=0,packet-rate=0/0,total-packet-rate=0,queued-packets=0/0,total-queued-packets=0,queued-bytes=0/0,total-queued-bytes=0,lends=0/0,total-lends=0,borrows=0/0,total-borrows=0,pcq-queues=0/0,total-pcq-queues=0,comment=,disabled=false

Now you have to start coding. Write parser which will extract value you need.

Who is online

Users browsing this forum: Bing [Bot] and 32 guests