08-09-2023 02:07 AM
I have created an EEM script to failover from 1 connection type to another if the primary connection goes down by changing the tunnel source.
However I now have a situation where there are 3 connection types on one router, and I need to use EEM to failover all 3 if possible.
My current script activates when track 1 goes down as below.
event manager applet TunnelChange
event track 1 state down
action 1.0 cli command "enable"
action 2.0 cli command "configure term"
action 3.0 cli command "interface <Tunnel Number>"
action 4.0 cli command "tunnel source <Backup Connection Interface>"
Is there a way to track 2 tracks and activate the script if both are down so it failovers to the 2nd backup connection if both the primary and backup are down?
08-09-2023 02:57 AM
Hello @alnic123
event manager applet TunnelChange
event track 1 state down
event track 2 state down
action 1.0 cli command "enable"
action 2.0 cli command "configure term"
action 3.0 cli command "interface <Tunnel Number>"
action 4.0 cli command "tunnel source <Second Backup Connection Interface>"
The script will be triggered if both track 1 and track 2 are in the "down" state. Once both tracks are down, the actions will be executed, changing the tunnel source to the second backup connection interface.
08-09-2023 03:02 AM
Thanks for the reply. However i had already tried this and when i enter the 2nd event track line it overwrites the first one.
So entering this;
event manager applet TunnelChange
event track 1 state down
event track 2 state down
Results in this;
event manager applet TunnelChange
event track 2 state down
08-09-2023 03:40 AM
OK @alnic123
Try this:
event manager applet TunnelChange1
event track 1 state down
action 1.0 cli command "enable"
action 2.0 cli command "event manager environment TRACK_DOWN=1"
event manager applet TunnelChange2
event track 2 state down
action 1.0 cli command "enable"
action 2.0 cli command "event manager environment TRACK_DOWN2=1"
event manager applet TunnelChange3
event none
action 1.0 cli command "enable"
action 2.0 if $_environment_TRACK_DOWN eq "1" && $_environment_TRACK_DOWN2 eq "1"
action 2.1 cli command "configure term"
action 2.2 cli command "interface <Tunnel Number>"
action 2.3 cli command "tunnel source <Backup Connection Interface>"
action 2.4 end
--The third applet "TunnelChange3" is triggered when none of the events occur, but it checks the values of both environment variables to decide whether to execute the action. If both variables are set to "1," meaning both tracks are down, the action within the "if" statement is executed.
08-10-2023 02:18 PM
Could also try this. Gig2 is primary(track 1), Gig3.109 is secondary(track 2) and Gig7.107 is tertiary(track 3). Will try and revert back to primary when possible, if not then revert to secondary when possible.
track 1 ip sla 1 reachability
!
track 2 ip sla 2 reachability
!
track 3 ip sla 3 reachability
ip sla 1
icmp-echo 192.168.16.1 source-interface GigabitEthernet2
frequency 10
ip sla schedule 1 life forever start-time now
ip sla 2
icmp-echo 172.27.1.37 source-interface GigabitEthernet3.109
frequency 10
ip sla schedule 2 life forever start-time now
ip sla 3
icmp-echo 172.27.3.29 source-interface GigabitEthernet7.107
frequency 10
ip sla schedule 3 life forever start-time now
event manager applet tunnelSource
event tag sla1 track 1 state any
event tag sla2 track 2 state any
event tag sla3 track 3 state any
trigger
correlate event sla1 or event sla2 or event sla3
action 010 cli command "enable"
action 015 puts "track $_track_number state = $_track_state"
action 020 cli command "show track 1 | inc Reachability"
action 025 regexp "Reachability is ([a-zA-Z]+)" "$_cli_result" match state1
action 030 cli command "show track 2 | inc Reachability"
action 035 regexp "Reachability is ([a-zA-Z]+)" "$_cli_result" match state2
action 040 cli command "show track 3 | inc Reachability"
action 045 regexp "Reachability is ([a-zA-Z]+)" "$_cli_result" match state3
action 050 cli command "config t"
action 055 cli command "int Tunnel100"
action 060 if $state1 eq "Up"
action 065 cli command "tunnel source GigabitEthernet2"
action 070 elseif $state2 eq Up
action 075 cli command "tunnel source GigabitEthernet3.109"
action 080 else
action 085 cli command "tunnel source GigabitEthernet7.107"
action 090 end
action 100 cli command "end"
action 110 cli command "show run interface Tunnel100"
action 120 puts "$_cli_result"
Test
cat8kv21_1#
Aug 10 21:09:38.124: %TRACK-6-STATE: 1 ip sla 1 reachability Up -> Down
Aug 10 21:09:38.238: %HA_EM-6-LOG: tunnelSource: track 1 state = down
Aug 10 21:09:38.926: %HA_EM-6-LOG: tunnelSource:
Building configuration...
Current configuration : 127 bytes
!
interface Tunnel100
ip address 1.2.3.1 255.255.255.252
tunnel source GigabitEthernet3.109
tunnel destination dynamic
end
cat8kv21_1#
Aug 10 21:10:13.127: %TRACK-6-STATE: 2 ip sla 2 reachability Up -> Down
Aug 10 21:10:13.240: %HA_EM-6-LOG: tunnelSource: track 2 state = down
Aug 10 21:10:13.831: %HA_EM-6-LOG: tunnelSource:
Building configuration...
Current configuration : 127 bytes
!
interface Tunnel100
ip address 1.2.3.1 255.255.255.252
tunnel source GigabitEthernet7.107
tunnel destination dynamic
end
cat8kv21_1#
Aug 10 21:10:33.128: %TRACK-6-STATE: 1 ip sla 1 reachability Down -> Up
Aug 10 21:10:33.241: %HA_EM-6-LOG: tunnelSource: track 1 state = up
Aug 10 21:10:33.924: %HA_EM-6-LOG: tunnelSource:
Building configuration...
Current configuration : 123 bytes
!
interface Tunnel100
ip address 1.2.3.1 255.255.255.252
tunnel source GigabitEthernet2
tunnel destination dynamic
end
cat8kv21_1#
Aug 10 21:10:58.129: %TRACK-6-STATE: 2 ip sla 2 reachability Down -> Up
Aug 10 21:10:58.242: %HA_EM-6-LOG: tunnelSource: track 2 state = up
Aug 10 21:10:58.932: %HA_EM-6-LOG: tunnelSource:
Building configuration...
Current configuration : 123 bytes
!
interface Tunnel100
ip address 1.2.3.1 255.255.255.252
tunnel source GigabitEthernet2
tunnel destination dynamic
end
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide