Community discussions

MikroTik App
 
User avatar
dibatech
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Tue Apr 04, 2006 10:14 am

Count split routes

Fri May 06, 2022 1:46 pm

Hi. Has anyone found a way to count split routes (ecmp routes)?
Routes that are either statically defined or imported via OSPF.

This is handy when OSPF creates split routes in more complex networks under certain conditions.

So, in essense, alert on split route.
Anybody?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7042
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Count split routes

Fri May 06, 2022 2:14 pm

loop through routes and count +1 if gateway value is an array with more than one element
 
User avatar
dibatech
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Tue Apr 04, 2006 10:14 am

Re: Count split routes

Fri May 06, 2022 2:20 pm

loop through routes and count +1 if gateway value is an array with more than one element
Thank you.
 
User avatar
dibatech
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 94
Joined: Tue Apr 04, 2006 10:14 am

Re: Count split routes

Fri May 06, 2022 3:49 pm

Final result.
:local dst
:local splitcount 0
:foreach dst in=[/ip route find] do={
    :set dst [/ip route get value-name=gateway number=$dst]
    :local elementcount 0
    :foreach i in=$dst do={
        set elementcount ($elementcount + 1)
        }
    
    :if ( $elementcount > 1) do={
        #:put "$dst";
        set splitcount ($splitcount + 1)
        }
}
:put "splitcount $splitcount"
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Count split routes

Fri May 06, 2022 3:57 pm

Some conflicts here...

:local dst

:foreach dst in=[/ip route find] do={
:set dst [/ip route get value-name=gateway number=$dst]

used same name from local variable and variable obtained from foreach cycle


Probably the script must be like:
{
    :local splitcount 0
    /ip route
    :foreach item in=[find] do={
        :local gat [get $item gateway]
        :if ([:len $gat] > 1) do={
            :set splitcount ($splitcount + 1)
        }
    }
    :put "splitcount $splitcount"
}

Who is online

Users browsing this forum: rogerioqueiroz and 16 guests