Could some one show how using
ros code
/interface/monitor-traffic =interface=ether3-master-localwrite out data, I'm looking in WiKi and don't understand it. I want to get rx-bits-per-second and tx-bits-per-second
/interface/monitor-traffic =interface=ether3-master-localwrite out data, I'm looking in WiKi and don't understand it. I want to get rx-bits-per-second and tx-bits-per-second
!re
=rx-bits-per-second=<some number>
=tx-bits-per-second=<some number>
<more attributes>
I'm only start learning Java and couldn't understand how this working. Could you give me working example with using =rx-bits-per-second= plsEach time a sample is gathered, it's given to the client as a reply in the form of
How exactly do you extract the values you want depends on the client you're using.Code: Select all!re =rx-bits-per-second=<some number> =tx-bits-per-second=<some number> <more attributes>
With this client for example, you can access it the same way you'd access any other map object. Since this is a continuous command, you'd need to eventually cancel it if you want it to stop, or just process responses asynchronously (check out the Asynchronous commands in the readme).
//Near the top
import me.legrange.mikrotik;
//Within a method in your class
ApiConnection con = ApiConnection.connect("10.0.1.1"); // connect to router
con.login("admin","password"); // log in to router
String tag = con.execute("/interface/monitor-traffic numbers=ether3-master-local .proplist=tx-bits-per-second,rx-bits-per-second",
new ResultListener() {
public void receive(Map<String, String> result) {
System.out.println(result);
}
}
);
I try to use it but nothing happensCode: Select all//Near the top import me.legrange.mikrotik; //Within a method in your class ApiConnection con = ApiConnection.connect("10.0.1.1"); // connect to router con.login("admin","password"); // log in to router String tag = con.execute("/interface/monitor-traffic numbers=ether3-master-local .proplist=tx-bits-per-second,rx-bits-per-second", new ResultListener() { public void receive(Map<String, String> result) { System.out.println(result); } } );
import java.util.Map; import me.legrange.mikrotik.MikrotikApiException; import me.legrange.mikrotik.ResultListener; public class Ether3 extends Connect { public static void main(String... args) throws Exception { Ether3 ex = new Ether3(); ex.connect(); ex.test(); ex.disconnect(); } private void test() throws MikrotikApiException, InterruptedException { String tag = con.execute("/interface/monitor-traffic numbers=ether6-5th-floor .proplist=tx-bits-per-second,rx-bits-per-second", new ResultListener() { public void receive(Map<String, String> result) { System.out.println(result); } }); } }
nothing outputWhen you say "nothing happens", what do you mean? It doesn't compile, or it compiles, but it doesn't output anything?
String id = con.execute("/interface/monitor-traffic interface=wlan1 return tx-bits-per-second,rx-bits-per-second", new ResultListener() {
public void receive(Map<String, String> result) {
System.out.println(result);
}
});
Opps. My fault then.* I specify the interface with interface=. I'm not sure if numbers= will work.
Yeah, about that... you're already accepting ".id", and ".proplist" is just another argument name... Why introduce a new keyword? Seems unnecessary.* I specify the fields I want to receive with a "return" statement. The reason for this is a bit intricate and is to do with how the RouterOS API works.
Clearly you know the API protocol, but a big point to making an API library is to isolate developers from unnecessary details.Yeah, about that... you're already accepting ".id", and ".proplist" is just another argument name... Why introduce a new keyword? Seems unnecessary.
(I think I know enough about Java and the API protocol, so hit me with the non-dumbed down version of the explanation)
Oh. So it's just syntax sugar? That's... OK... I guess... as long as MikroTik don't decide to introduce a "return" argument with its own semantics. I thought maybe you were doing some additional work behind the scenes (which would be a legitimate reason to add a keyword or a dedicated method), but couldn't figure out what that might be.Adding ".proplist=" to the command passed to the API does work, I checked this after your post, so you don't have to use "return". I brought it up because I was unsure if it would be passed correctly, but it does.
Maybe add a new method to the listener that will get error replies? If mandatory, it would make users more cautious with their error handling... which tends to be a good thing. That, or perhaps adjust the listener to accept a Response, and adjust the Response to contain the type.What your post did make me realise is that there is definitely an issue with error handling when using the API asynchronously (your "numbers=" should cause an error), and I probably need to improve the documentation a lot.
That already exists. You can pass an implementation of ResponseListener (subclass of ResultsListener) and will receive errors and command completion information. It isn't mandatory, but most likely should be though, or at least documentedMaybe add a new method to the listener that will get error replies? If mandatory, it would make users more cautious with their error handling... which tends to be a good thing. That, or perhaps adjust the listener to accept a Response, and adjust the Response to contain the type.
(And most importantly - send all kinds of replies to the listener)
The API does not return one String. It returns a List containing Maps for the individual results. So if you have two users, then /ip/hotspot/user/print will return a List<Map<String, String>> containing two maps, one per user. The individual attributes for each user are accessible using the specific map instance's accessor methods.when I read for example (/ip/hotspot/user/print), your API returns one string containing all informations about the users.
I want to get this string and make java objects with the attributes.
Can you help?
Inserted where?I want to compare the list of active users with the inserted users.
Oh, so detecting a log off is needed too... Then try using the command "/ip/hotspot/user/active/listen" with no arguments. This should tell you not only when a user first logs into the hotspot, but also when they log off, either explicitly, or because their session has expired. A logged off user should be distinguishable from its logged in counterpart via the property ".dead", which will be set (and have a value of "yes") when the user is not active anymore.the listener works good to inform new active users, but when one logoff is made the listener doesn't recognize it.
Do you have some tricks to work with this issue?
But... you can get all hotspot users from "/ip/hotspot/user/print", and all active ones with a (sync) "/ip/hotspot/user/active/print". No need to look up a database, which may theoretically be out of date with the router.Basically it has to ADD user, Modify user, show the current inserted users and inform who is active (based on the current inserted users).
Pull the latest code from GitHub, it is fixed.Scanning for projects...
Some problems were encountered while building the effective model for me.legrange:mikrotik:jar:1.1.7-SNAPSHOT
'build.plugins.plugin.version' for org.apache.maven.plugins:maven-gpg-plugin is missing. @ line 72, column 21
It is highly recommended to fix these problems because they threaten the stability of your build.
For this reason, future Maven versions might no longer support building such malformed projects.
How can I solve this problem?
Its an interactive command u have to use once keyword to execute that command command will be :nothing outputWhen you say "nothing happens", what do you mean? It doesn't compile, or it compiles, but it doesn't output anything?
public void Monitors() throws Exception
{
ApiConnection con = ApiConnection.connect(DatosRouter.ip);
try
{
con.login(DatosRouter.user, DatosRouter.password);
String id = con.execute("/interface/monitor-traffic interface=ether1 return tx-bits-per-second,rx-bits-per-second",
new
public void receive(Map<String, String> result) {
System.out.println(result);
}
public void error(MikrotikApiException e) {
System.out.println("An error occurred: " + e.getMessage());
}
public void completed() {
System.out.println("Asynchronous command has finished");
}
});
System.out.println(id);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public abstract class test {
public static void main(String[] args) throws Exception {
BeanMonitor beanMonitor = new BeanMonitor();
beanMonitor.Monitors();
}
}
Try this.. this works for menothing outputWhen you say "nothing happens", what do you mean? It doesn't compile, or it compiles, but it doesn't output anything?
package examples;
import java.util.Map;
import me.legrange.mikrotik.MikrotikApiException;
import me.legrange.mikrotik.ResultListener;
/**
* Example 4: Asynchronous results. Run a command and receive results for it asynchronously with a ResultListener
*
* @author gideon
*/
public class AsyncCommand extends Example {
public static void main(String... args) throws Exception {
AsyncCommand ex = new AsyncCommand();
ex.connect();
ex.test();
ex.disconnect();
}
private void test() throws MikrotikApiException, InterruptedException {
String id = con.execute("/interface/monitor-traffic interface=ether1", new ResultListener() {
private int prev = 0;
public void receive(Map<String, String> result) {
System.out.println(result);
/* int val = Integer.parseInt(result.get("signal-strength"));
String sym = (val == prev) ? " " : ((val < prev) ? "-" : "+");
System.out.printf("%d %s\n", val, sym);
prev = val;
*/ }
@Override
public void error(MikrotikApiException ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
@Override
public void completed() {
}
});
// let it run for 60 seconds
Thread.sleep(60000);
con.cancel(id);
}
}