Page 1 of 1

Script to create /tool/graphs/interface - Help for dummy

Posted: Tue Feb 11, 2025 1:17 pm
by fischerdouglas
I want to define the creation of graphs only for some types of interfaces (ethernet, vlan and bridge). A way to avoid PPP or similar graphs being created.

I actually really like the scripting syntax of RouterOS. But I'm not a programmer!
My way of thinking is linear, and that doesn't help me when it comes to finding solutions to small syntax rules.
But my brain gets stuck on what the syntax and logic of some recursions in RouterOS are.

I did some tests that obviously failed, but I'll bring them here to show how far I was able to get.

The following command gives me the arrays of interfaces I want.
:put [/interface find type=ether]
:put [/interface find type=vlan]
:put [/interface find type=bridge]
So I thought if is a printed that variables in a loop, it would give something similar to previous:
:foreach varinterfaceid in={/interface find type=ether} do={:put "$varinterfaceid" }
But what I get as output is a single "true", even on a multivalued array.

And this is where I got stuck...

I imagined that I needed to do soothing like:
:foreach varinterfaceid in={/interface find type=ether} do={/tool/graphing/interface/add [/interface get [:put "$varinterfaceid"} name]
But this is obviously wrong!
Wrong because of the wrong use of syntax, and wrong because there is no "/interface/get".

Could anybody give me some help with this?

Re: Script to create /tool/graphs/interface - Help for dummy

Posted: Tue Feb 11, 2025 1:32 pm
by CGGXANNX
You need square brackets instead of curly braces:

:foreach varinterfaceid in=[/interface find type=ether] do={:put "$varinterfaceid" }  

As for the add command, it's probably like this:

/tool/graphing/interface/add interface=[/interface/get number=$varinterfaceid name]

EDIT: Complete code:

:foreach varinterfaceid in=[/interface find type=ether] do={
    :put "$varinterfaceid"; 
    /tool/graphing/interface/add interface=[/interface/get number=$varinterfaceid name];
}

Re: Script to create /tool/graphs/interface - Help for dummy

Posted: Tue Feb 11, 2025 3:30 pm
by rextended
Since you can not choice the path of the graphs file, if your device use NAND or flash, do not do it...

Re: Script to create /tool/graphs/interface - Help for dummy

Posted: Tue Feb 11, 2025 3:57 pm
by fischerdouglas
Since you can not choice the path of the graphs file, if your device use NAND or flash, do not do it...
Yep! I now! Intensive writes corrupts flashs...
On MikroTiks, on Cisco, on Huawei... Flash were not designed to that.
Thank you for the warning.


But, in my defense... Wrong choices in the past around ISP management software resulted in a system so bad, but soooo bad, that the damn system can't even keep track of the client's bandwidth consumption. At this point, it's not a question of how to solve it, but of how to make it hurt less.

I'm going to put "store-on-disk=no" as a way of putting a bandaid on a wound caused by a .380 bullet.

Re: Script to create /tool/graphs/interface - Help for dummy

Posted: Tue Feb 11, 2025 4:02 pm
by fischerdouglas
... if your device use NAND or flash, do not do it...
Yep! I now! Intensive writes corrupts flashs...
By the way... I can't understand how the default setting for "store-on-disk" is "yes".
In my opinion, this is a mistake by MikroTik. By leaving it as "yes", they are creating problems for themselves.

Re: Script to create /tool/graphs/interface - Help for dummy

Posted: Tue Feb 11, 2025 4:05 pm
by fischerdouglas
You need square brackets instead of curly braces:
Yep! I understood now...

:foreach varinterfaceid in=[/interface find type=ether] do={
    :put "$varinterfaceid"; 
    /tool/graphing/interface/add interface=[/interface/get number=$varinterfaceid name];
}
It Worked!
Thank you for the patience for teaching.

Re: Script to create /tool/graphs/interface - Help for dummy

Posted: Tue Feb 11, 2025 4:16 pm
by rextended
More simple and compatible with v6 and v7

only ethernet code

:foreach iface in=[/interface ethernet find] do={
    /tool graphing interface add store-on-disk=no interface=[/interface ethernet get $iface name]
}

only ethernet, vlan and bridge code

:foreach iface in=[/interface find where type~"(ether|vlan|bridge)"] do={
    /tool graphing interface add store-on-disk=no interface=[/interface get $iface name]
}

only ethernet, vlan and bridge NOT SLAVEs code

:foreach iface in=[/interface find where type~"(ether|vlan|bridge)" and !slave] do={
    /tool graphing interface add store-on-disk=no interface=[/interface get $iface name]
}