10 May, 2021

Dual WAN PCC Based WAN Link Monitoring

 # ------------------- header -------------------

# Script by Tomas Kirnak, version 1.0.7

# If you use this script, or edit and

# re-use it, please keep the header intact.

#

# For more information and details about

# this script please visit the wiki page at

# http://wiki.mikrotik.com/wiki/Failover_Scripting

# ------------------- header -------------------




# ------------- start editing here -------------

# Edit the variables below to suit your needs


# Please fill the WAN interface names

:local InterfaceISP1 WAN1

:local InterfaceISP2 WAN2


# Please fill the gateway IPs (or interface names in case of PPP)

:local GatewayISP1 192.168.1.1

:local GatewayISP2 192.168.10.1


# Please fill the ping check host - currently: one.one.one.one Secure DNS

:local PingTarget 1.1.1.1


# Please fill how many ping failures are allowed before fail-over happends

:local FailTreshold 3


# Define the distance increase of a route when it fails

:local DistanceIncrease 2


# Editing the script after this point may break it

# -------------- stop editing here --------------




# Declare the global variables

:global PingFailCountISP1

:global PingFailCountISP2


# This inicializes the PingFailCount variables, in case this is the 1st time the script has ran

:if ([:typeof $PingFailCountISP1] = "nothing") do={:set PingFailCountISP1 0}

:if ([:typeof $PingFailCountISP2] = "nothing") do={:set PingFailCountISP2 0}


# This variable will be used to keep results of individual ping attempts

:local PingResult




# Check ISP1

:set PingResult [ping $PingTarget count=1 routing-table=to_WAN1]

:put $PingResult


:if ($PingResult = 0) do={

:if ($PingFailCountISP1 < ($FailTreshold+2)) do={

:set PingFailCountISP1 ($PingFailCountISP1 + 1)

:if ($PingFailCountISP1 = $FailTreshold) do={

:log warning "FiberLink has a problem - Changing the Internet to PTCL"

/ip route set [find comment="ISP1"] distance=2

/ip route set [find comment="ISP2"] distance=1

:log warning "Route distance increase finished."

}

}

}

:if ($PingResult = 1) do={

:if ($PingFailCountISP1 > 0) do={

:set PingFailCountISP1 ($PingFailCountISP1 - 1)

:if ($PingFailCountISP1 = ($FailTreshold -1)) do={

:log warning "Restoring Connection to FiberLink as Primary Internet Source."

/ip route set [find comment="ISP1"] distance=1

/ip route set [find comment="ISP2"] distance=2

}

}

}




# Check ISP2

:set PingResult [ping $PingTarget count=1 routing-table=to_WAN2]

:put $PingResult


:if ($PingResult = 0) do={

:if ($PingFailCountISP2 < ($FailTreshold+2)) do={

:set PingFailCountISP2 ($PingFailCountISP2 + 1)

:if ($PingFailCountISP2 = $FailTreshold) do={

:log warning "Secondary Internet Source is Down - Keeping Primary Up."

/ip route set [find comment="ISP1"] distance=1

/ip route set [find comment="ISP2"] distance=2

}

}

}

:if ($PingResult = 1) do={

:if ($PingFailCountISP2 > 0) do={

:set PingFailCountISP2 ($PingFailCountISP2 - 1)

:if ($PingFailCountISP2 = ($FailTreshold -1)) do={

/ip route set [find comment="ISP1"] distance=1

/ip route set [find comment="ISP2"] distance=2

}

}

}

No comments:

Post a Comment

Redirection in IIS

 This config will redirect every request to https://www.domain.com <configuration>     <system.webServer>         <rewrite>...