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:
Code: Select all
[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>
So if you keep googling you maybe find this link viewtopic.php?t=57697
Code: Select all
: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 ];
}
}
Today i need to collect some data from my radius client and if you open an terminal and type:
Code: Select all
radius monitor numbers=0
Code: Select all
pending: 0
requests: 1046
accepts: 494
rejects: 552
resends: 0
timeouts: 0
bad-replies: 0
last-request-rtt: 10ms
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:
Code: Select all
radius monitor numbers=0 do={:local }
Code: Select all
"bad-replies" accepts rejects resends do name
"last-request-rtt" pending requests timeouts value
With this information i make this script, and now i can manipulate this information in global variables
Code: Select all
: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 ];
}
}
Best Regards
keywords: routeros info, routeros monitor, routeros local variable;