I am currently writing a API program for my Blackberry. I see this in most posts about API commands here:
Connecting…
command sent
response received
Disconnecting…
You don’t log in, send one command, wait for one response, then log out, do you? I logout only when I am finished with all commands. But I use a thread to open, monitor and close the connection.
Hey Chupaka! I hear you wrote an API script for this OS. Any way you could post the link to that script for me? Doesn’t matter what language it is in. I speak many computer languages. I would really like to see it! Maybe some inspiration will come of it. Thanks for all!
Correct me if I’m wrong, but you cannot close an API session in RouterOS? At least nothing is mentioned in API documentation. I’m mostly using PHP implementation and it only closes socket that has been opened, which in fact doesn’t kill the entry in active session list.
Mikrotik responded and said that this bug of sessions not timing out is fixed in ROS v5. Unfortunately I don’t think I want to move to v5 for now and I use API queries alot. The problem is that when ROS issues about 100 challenges it responds with “cannot get challenge” error and you can’t connect to ROS via API anymore. Reboot being the only way to get it working again is totally out of question for me, so maybe some bright minds could suggest something or at least put worries to an end by telling there’s nothing more to do about it?
I really do like working with API, it’s very convenient and simple. Since everything is already in place and working as it should (except for that challenge thingy), I don’t want to rewrite everything using PHP telnet class. If somehow I could overcome that session overfilling issue, I could get myself a nice vacation
API closes login when you close connection gracefully.
But you are able to issue /quit command to close login, but note that to re-connect again you will have to close connection and create that again to get challenge, so there is no point of using /quit since you will have to close connection anyway.
Use case for API is not to monitor, but to do other things as for monitoring you can use SNMP, for example the Dude
Ok, I shall try /quit’ing after acquiring data or making changes, I don’t think this would cause troubles for me as long as that challenge issuing thing doesn’t apply. Currently I’m using the PHP API script provided in Mikrotik Wiki. I haven’t modified it at all, and it’s application doesn’t differ much from the example of use provided in that same Wiki page. I don’t want to seem annoying, but how do you imagine graceful connection close?
I use API for controlling firewall adress-list entries. The custom web management system is used to enable or disable internet access or create redirects to custom pages for certain customers. I see of no other way of achieving that, with an exception of telnet. My clients often get friendly remainders that they haven’t paid yet, and this means they need to press “Continue browsing” button which in turn eventually calls for API script to remove entries from ROS firewall addr-list.
I don’t know how things are handled past PHP API implementation and I don’t think I am qualified enough to dig any deeper. The connection is closed simply by closing the socket with fclose() that has previously been opened with fsockopen(). What else could you do? People are reporting that other implementations doesn’t work correctly either, so what needs fixing here?
Btw, /quit doesn’t end session in Active session list either.
As mentioned, this is a bug. I don’t think there’s anything that will fix it other then Mikrotik fixing it in v5. I think v4 will not be fixed.
Also see here for more information: http://forum.mikrotik.com/t/php-api-connection/33417/1
Use case for API is not to monitor, but to do other things as for monitoring you can use SNMP, for example the Dude
What is use case for API?
Monitoring with SNMP.. yes it is doable, but it takes ages to complete to scan one busy MT system.
Yes - you implemented snmp bulk pdu (cool ), but only In 5.x which is rc.
Is it so difficult to backport working API from 3.30 or 5.x to 4.x branch, and snmp bulk pdu from 5.x to 4.x ?
Or maybe you have no interest in doing that.
I define gracefully as closing the connection when I am finished. I use Java and a thread to do the communication with the router. That way if the thread stalls, I can recover it with the main program. The main program controls the thread with vectors holding the commands and boolean control bits as “signal lines” between the thread and the program, like a Unix fork and pipe.
My Blackberry does very well at handling the connection. My router shows one login and one logout, no matter how long I stay connected or how many commands I use. The API is easier for a newbie than CLI.
I am not certain I can do a tcpdump from my Blackberry. But why would I need to? The API responds perfectly, and the router shows the login, the correct changes, and a logout. I can log in again right away, do more changes, and logout without exiting the Java program. In the main program: