Community discussions

MikroTik App
 
tonny
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Fri Oct 09, 2015 10:50 am

'whoami' in vrrp script

Mon Apr 04, 2022 5:12 pm

Hi,

The VRRP interfaces have an "on-master"/"on-backup" script trigger.
Is there a variable that specifies the vrrp interface that triggered the script?

Kind regards,
Ton
 
tonny
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 54
Joined: Fri Oct 09, 2015 10:50 am

Re: 'whoami' in vrrp script

Wed Apr 06, 2022 4:01 pm

the idea is to be able to t.ex. "/system script run vrrphaschanged" in the 'on master' and 'on backup'
then in the vrrphaschanged script have two variable that refers to which vrrp interface and to the (new-)state

For now i've worked around it with :global variables but that's kind of an issue because they overwrite each other if multiple vrrp's fail at the same time (t.ex. vlans on a trunk interface).
That too has been worked around, but clearly the idea above is more appealing and stable
 
Sob
Forum Guru
Forum Guru
Posts: 9119
Joined: Mon Apr 20, 2009 9:11 pm

Re: 'whoami' in vrrp script

Wed Apr 06, 2022 4:34 pm

It's good idea, but currently it seems that it doesn't exist. There's nothing in documentation and none of obvious variable names I tried worked ($name, $interface, $"interface-name").
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: 'whoami' in vrrp script

Thu Apr 07, 2022 12:23 am

use one unique global variable of type array,
create it on startup with all vrrp required like:
:global thearray [:toarray ""]
:foreach item in=[/interface vrrp find] do={
    :local iname [/interface vrrp get $item name]
    :set ($thearray->$iname) "unset"
}

and "on-master" / "on-backup" set the proper value before call the script, like:
:global thearray
:set ($thearray->"vrrp1234") "master"
/system script run vrrphaschanged

and inside vrrphaschanged you can read what vrrp is on master or on backup or unset (never run on-master or on-backup for that vrrp)
:global thearray
:foreach item,value in=$thearray do={
    :local vrname $item
    :local status $value
    :if ($status = "master") do={
        :log info "$vrname is now $status"

        # place here what you want to do if vrrp is on master status

        # you done it, set again unset for not execute again on next call
        :set ($thearray->$item) "unset"
    }
    :if ($status = "backup") do={
        :log info "$vrname is now $status"

        # place here what you want to do if vrrp is on backup status

        # you done it, set again unset for not execute again on next call
        :set ($thearray->$item) "unset"
    }
}

Who is online

Users browsing this forum: No registered users and 24 guests