G’day,
So as I understand it there is no way to run a particular script on any type of event (other than using say the LOG watching script).
example - ospf primary gateway goes down, every router switches to route 2.. However - they need to switch DNS servers when this happens.. I’ve found no better way than to just run the following script every 10 seconds or so.
# Watch for MAIN route up (10.0.1.1) if it is up keep DNS
# if it's down - we will be going out alternate ISP so then use
# google DNS 8.8.8.8 and 8.8.4.4
# Begin Configuration
:local secondaryDNSServers "8.8.8.8,8.8.4.4"
:local primaryDNSServers "10.0.1.1"
# End Configuration
:local curGateway
:local curDNS
:set $curGateway [/ip route find gateway=10.0.1.1 dst-address=0.0.0.0/0]
#:log info "curGateway=$curGateway"
# Now compared curGateway with current DNS to see if it is matched up
# Get list of current DNS servers and put into variable
#
# mangle DNS server list into format acceptable for the
# ip dns set command
#
:foreach srv in=[/ip dns get servers] do={
:if ( [:len $curDNS] = 0 ) do={
:set $curDNS $srv
} else={
:set $curDNS ( $curDNS . "," . $srv )
}
}
# See if curGateway returned any results - if it DID NOT.. then we know we
# are NOT using our primary gateway. In which case switch DNS to public
# google DNS servers
:if ( $curGateway = "" ) do={
# :log info "curGateway != true; curDNS=$curDNS, primaryDNS=$secondaryDNSServers"
:if ( $curDNS != $secondaryDNSServers ) do {
/ip dns set servers $secondaryDNSServers
/ip dns cache flush
:log info "PRIMARY INTERNET DOWN, set DNS servers to Google's Public DNS $pubServers"
}
} else={
# :log info "curGateway == true; curDNS=$curDNS, primaryDNS=$primaryDNSServers"
:if ( $curDNS != $primaryDNSServers ) do={
/ip dns set servers $primaryDNSServers
/ip dns cache flush
:log info "PRIMARY INTERNET UP, set DNS servers to $primaryDNSServers"
}
}
Is it bad form - to run a script every 10 seconds.. just seems so darn inefficient when 99% of the time it will do nothing.. would be MUCH better to run when the OSPF event happens…
Is this just way it is and deal with it?
cheers,
Paul