Community discussions

MikroTik App
 
User avatar
fischerdouglas
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 80
Joined: Thu Mar 07, 2019 6:38 pm
Location: Brazil
Contact:

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

Tue Feb 11, 2025 1:17 pm

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?
 
CGGXANNX
Member Candidate
Member Candidate
Posts: 296
Joined: Thu Dec 21, 2023 6:45 pm

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

Tue Feb 11, 2025 1:32 pm

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];
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12687
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

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

Tue Feb 11, 2025 3:30 pm

Since you can not choice the path of the graphs file, if your device use NAND or flash, do not do it...
 
User avatar
fischerdouglas
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 80
Joined: Thu Mar 07, 2019 6:38 pm
Location: Brazil
Contact:

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

Tue Feb 11, 2025 3:57 pm

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.
 
User avatar
fischerdouglas
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 80
Joined: Thu Mar 07, 2019 6:38 pm
Location: Brazil
Contact:

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

Tue Feb 11, 2025 4:02 pm

... 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.
 
User avatar
fischerdouglas
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 80
Joined: Thu Mar 07, 2019 6:38 pm
Location: Brazil
Contact:

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

Tue Feb 11, 2025 4:05 pm

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12687
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

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

Tue Feb 11, 2025 4:16 pm

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]
}