Community discussions

MikroTik App
 
User avatar
ppereira
just joined
Topic Author
Posts: 9
Joined: Mon Sep 09, 2013 10:24 pm

RouterOS local variable

Sat Apr 29, 2017 1:26 am

Hello guys,

I have some difficults when need to collect information for our managment system.

[The problem]
I need to get some information displayed at terminal/winbox, but it was inside a "monitor" command that keep refreshing. If you use the "once" argument, it does not get the proper data.


So after some research i would like to share this little but helpful detail. My case is about the identification os local variables that routerOs uses at a "monitor" or "info" scope.
If you google it, you will find this link https://www.mikrotik.com/testdocs/ros/2 ... ipting.php, you should move forward to Special action and check the example:
[admin@MikroTik] interface> monitor-traffic ether2 once do={:environment print}
    received-packets-per-second: 0
       received-bits-per-second: 0bps
        sent-packets-per-second: 0
           sent-bits-per-second: 0bps

Global Variables
i=1
Local Variables
sent-bits-per-second=0
received-packets-per-second=0
received-bits-per-second=0
sent-packets-per-second=0
[admin@MikroTik] interface>
It would be great, and would help me a lot if it works. But its for ROS2.8 and does not work for ROS 5.26 and 6.38.5 (both tested).

So if you keep googling you maybe find this link viewtopic.php?t=57697
:local i 0;
/interface ppp-client info umts do={
:set i ($i+1);
:if ($i=5) do={
:global modemstatus $"status";
:global pinstatus $"pin-status";
:global currentoperator $"current-operator";
:global signalstrengh $"signal-strengh";
/system script job remove [ find script=umts_info ];
}
}
The user Alphil share this code, and it help me a lot when i need to take some info from my 3G dongle.

Today i need to collect some data from my radius client and if you open an terminal and type:
radius monitor numbers=0
You should get it:
          pending: 0
          requests: 1046
          accepts: 494
          rejects: 552
          resends: 0
          timeouts: 0
          bad-replies: 0
          last-request-rtt: 10ms
Now i need to pass to my managment system this information, but it´s a monitor "print" and i can´t get this variables to work with it.
I try to get the variable like $"requests", using the same logic that was used at "info" from ppp-client. But it does not work.

[The Solution]

So to make it works we need to discover the real name of the local variable that routerOs use here.

To get it you should use the "do={:local }" and you friend "tab" ^^
By this i use the command:
radius monitor numbers=0 do={:local }
And press "tab" to get this result:
"bad-replies"       accepts  rejects   resends   do     name
"last-request-rtt"  pending  requests  timeouts  value 
So i discovery that the local variable used by the routerOs for the fields that i need was accepts, rejects and pending.
With this information i make this script, and now i can manipulate this information in global variables :)
:local i 0;
/radius monitor numbers=0 do={
:set i ($i+1);
:if ($i=5) do={
:global req $requests;
:global rej $rejects;
:global accpt $accepts;
/system script job remove [ find script=script23 ];
}
}
I would like just to share this information with you guys.

Best Regards


keywords: routeros info, routeros monitor, routeros local variable;

Who is online

Users browsing this forum: SkIng, tarasfilatov and 7 guests