Can anybody publicate Mikrotik failover script for such configuration:
Hello
This code from
MikroTik config generator
If you specify a USB modem, is created and the script to switch to the modem.Though there is all in Russian, but nothing complicated.
/ip route add dst-address=8.8.4.4 gateway=127.0.0.1 distance=1
/system scheduler add disabled=no interval=30s name=CheckInet on-event=BackupModem
/system script add name=BackupModem owner=admin policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive source="#Name: BackupModem\r\
\n#Version: 3.4\r\
\n\r\
\n:local debug false;\r\
\n\r\
\n:local ShutdownModem false;\r\
\n\r\
\n:local UseModem false;\r\
\n\r\
\n:local OldGW [/ip route get [find dst-address=8.8.4.4/32] gateway];\r\
\n:local NewGW [/ip dhcp-client get [/interface find name=wan] gateway];\r\
\n:if (\$OldGW!=\$NewGW) do={\r\
\n\t/ip route set [find dst-address=8.8.4.4/32] gateway=\$NewGW;\r\
\n\t:log info \"BackupModem: Change gateway for 8.8.4.4 from \$OldGW to \$NewGW\";\r\
\n} else {\r\
\n\t:if (\$debug) do={:log info \"BackupModem: GW for 8.8.4.4 not change \$OldGW/\$NewGW\";}\r\
\n}\r\
\n\r\
\n:local WANstatus [/interface get wan running];\r\
\n:if (\$WANstatus=false) do={\r\
\n\t:set UseModem true;\r\
\n\t:if (\$debug) do={:log info \"BackupModem: wan link Down, must use Modem.\";}\r\
\n} else {\r\
\n\t:if (\$debug) do={:log info \"BackupModem: wan link OK.\";}\r\
\n\t:local CheckMainISP [/ping 8.8.4.4 count=3 interface=wan];\r\
\n\t:if (\$CheckMainISP=3) do={\r\
\n\t\t:set UseModem false;\r\
\n\t\t:if (\$debug) do={:log info \"BackupModem: Ping Ok, Not use USB modem\";}\r\
\n\t} else {\r\
\n\t\t:set UseModem true;\r\
\n\t\t:if (\$debug) do={:log info \"BackupModem: Ping lost, Must use USB modem\";}\r\
\n\t}\r\
\n}\r\
\n:local Distance [/ip dhcp-client get [/interface find name=\"wan\"] default-route-distance];\r\
\n:if (\$Distance=1) do={\r\
\n\t:if (\$debug) do={:log info \"BackupModem: Distance is 1\";}\r\
\n\t:if (\$UseModem=true) do={\r\
\n\t\t:local ModemStatus [/interface get [/interface find name=\"wan-4G\"] running];\r\
\n\t\t:if (\$ModemStatus=false) do={\r\
\n\t\t\t/interface enable [find name=\"wan-4G\"];\r\
\n\t\t\t:delay 5s;\r\
\n\t\t\t:local ModemStatus [/interface get [/interface find name=\"wan-4G\"] running];\r\
\n\t\t}\r\
\n\t\t:if (\$ModemStatus=false) do={\r\
\n\t\t\t:log warning \"BackupModem: USB modem not ready\";\r\
\n\t\t} else {\r\
\n\t\t\t:if (\$debug) do={:log info \"BackupModem: USB modem ready.\";}\r\
\n\t\t\t/ip dhcp-client set [/interface find name=\"wan\"] default-route-distance=3;\r\
\n\t\t\t:log info \"BackupModem: use USB modem as backup.\";\r\
\n\t\t}\r\
\n\t}\r\
\n} else {\r\
\n\t:if (\$debug) do={:log info \"BackupModem: Distance is NOT 1\";}\r\
\n\t:if (\$UseModem=false) do={\r\
\n\t\t:log info \"BackupModem: Use main ISP.\";\r\
\n\t\t/ip dhcp-client set [/interface find name=\"wan\"] default-route-distance=1;\r\
\n\t\t:if (\$ShutdownModem) do={/interface disable [find name=\"wan-4G\"]};\r\
\n\t} else {\r\
\n\t\t:if (\$debug) do={:log info \"BackupModem: already use USB modem.\";}\r\
\n\t}\r\
\n}\r\n"