Community discussions

MUM Europe 2020
 
synologic
newbie
Topic Author
Posts: 38
Joined: Tue Aug 11, 2009 2:03 pm

Interface Operation

Tue Nov 03, 2009 5:51 pm

Hi,

i have 2 questions for which i couldnt find anything in the manual:

1. how do i log interface state changes, i need to know when the link goes down and comes back up
2. is there any way to have some sort of Keepalive on the ethernet interfaces, it so happens that sometimes, some devices flaps their eth links which causes the OSPF tree to be recalculated (which is obvious under normal circumstances), however very short flaps, on light-traffic links do not create many problems, and since the default times on OSPF are 10 hello and 40 dead. It will be rather useful under certain conditions.

Thanks,
Viorel
 
User avatar
Belyivulk
Member Candidate
Member Candidate
Posts: 285
Joined: Mon Mar 06, 2006 10:53 pm
Location: Whangarei, New Zealand
Contact:

Re: Interface Operation

Mon Apr 05, 2010 7:31 am

i have the same question - is there a way? Anyone?
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: Interface Operation

Mon Apr 05, 2010 10:53 am

This script will detect the running state change of an interface. An action can then be specified upon state change.
# Detects changes to interface running state

:global InterfaceID
:global InterfaceState

:local findindex
:local prevstate
:local curstate
:local tmpstate

/interface {

   :foreach i in=[find] do={
      :set curstate [:tostr [get $i running]]
      :if ([:len $curstate] = 0) do={ :set curstate [:tostr false] }

      :set findindex [:find [:toarray $InterfaceID] [:tostr $i]]
      :if ([:len $findindex] > 0) do={
#      interface found. compare it's current state to previous state
         :set prevstate [:tostr [:pick [:toarray $InterfaceState] $findindex]]

         :if ( $prevstate != $curstate ) do={
#         --- start interface state change action ---

            :put ([get $i name] . " running state changed: " . $prevstate . " -> " . $curstate)
            :log info ([get $i name] . " running state changed: " . $prevstate . " -> " . $curstate)

#         --- end interface state change action ---

#         update interface record with new state
            :set tmpstate ""
            :for x from=0 to=([:len [:toarray $InterfaceState]] - 1) do={
               :set prevstate [:tostr [:pick [:toarray $InterfaceState] $x]]
               :if ($x = $findindex) do={
                  :set tmpstate ([:tostr $tmpstate] . $curstate . ",") } else={
                     :set tmpstate ([:tostr $tmpstate] . $prevstate . ",") }
            }
            :set InterfaceState [:tostr $tmpstate]

#      end if ( $prevstate != $curstate )
         }

      } else={

#      interface wasn't found, record it's state
         :set InterfaceID ([:tostr $InterfaceID] . [:tostr $i] . ",")
         :set InterfaceState ([:tostr $InterfaceState] . [get $i running] . ",")

      }

# end foreach i
   }

# /interface
}
 
User avatar
Belyivulk
Member Candidate
Member Candidate
Posts: 285
Joined: Mon Mar 06, 2006 10:53 pm
Location: Whangarei, New Zealand
Contact:

Re: Interface Operation

Tue Apr 06, 2010 8:43 am

Cool Cool :) Do you mind explaining how it works?
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: Interface Operation

Tue Apr 06, 2010 10:29 am

1) The script starts off and get's the running state of all interfaces.
2) The script would run via scheduler at specified intervals, for example:
/system scheduler add name="Interface State Check" on-event="<script name>" interval=5s
3) Each time the script is run, it checks all interfaces' current running state against their previous state.
3a) If the state changes, an action is performed (in the above case a log entry is created)
3b) If the state is the same, no action is performed.

To customize the action to perform on interface state change, modify the code between:
# --- start interface state change action ---
# --- end interface state change action ---

Also, you could modify the script to support other information (disabled/enabled) (running:true/false), etc..

RouterOS, AFAIK does not have a facility built-in, so this script should be able to track interface state changes.

Try this out on a router and see if it works for you. If not, post back here, and I may be able to assist further.

Who is online

Users browsing this forum: Google [Bot], Lifz, MSN [Bot], Schlimmerfinger, svmk and 111 guests