I hope everyone is doing ok.
I have written a failover script, it checks for ping reply via WAN 1 every 5 mins and if replay is not received, it will send an email and switch to Backup. After that it will check for primary internet (WAN 1) after every 4 mins. And if internet is received via WAN !, it will send an email that Primary is up now.
Basically it is a scheduler
Just wanted to share something with the community. How it helps someone. Dont forget to change gateways, emails and password from this script
Regards,
Code: Select all
/ip route
add comment=Main distance=1 gateway=198.42.12.1 scope=10
add comment=Backup distance=2 gateway=192.168.42.129
add check-gateway=ping comment=Primary disabled=yes distance=1 gateway=8.8.8.8
add comment=Secondary disabled=yes distance=2 gateway=192.168.42.129
add comment="Validate Primary" disabled=yes distance=1 dst-address=8.8.8.8/32 gateway=198.42.12.1 scope=10
add comment="BBC website" distance=1 dst-address=151.101.192.81/32 gateway=192.168.42.129
add comment="CNN website" distance=1 dst-address=151.101.193.67/32 gateway=198.42.12.1
/system clock
set time-zone-name=Asia/Karachi
/system scheduler
add comment="This will run after 4 mins" interval=5m name=main on-event="/syst\
em scheduler set [find name=checker] disabled=yes\r\
\n:local pinged [/ping address=151.101.192.81 count=5 interface=ether1 siz\
e=50]\r\
\n:if ((\$pinged=0)) do={\r\
\n#send email\r\
\n/tool e-mail send subject=(\"Backup is up and Primary is down\") \\\r\
\nbody=(\"Backup is being used now \" . [/system clock get time]) \\\r\
\nto=(\"XXXXX@gmail.com\")\r\
\n/system scheduler set [find name=backupwan] disabled=no\r\
\n}\r\
\n" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=jun/21/2019 start-time=20:21:53
add disabled=yes interval=15s name=backupwan on-event="/ip route set [find com\
ment=\"Main\"] distance=2\r\
\n/ip route set [find comment=\"Backup\"] distance=1\r\
\n/system scheduler set [find name=main] disabled=yes\r\
\n/system scheduler set [find name=checker] disabled=no\r\
add comment="This will run after 5 mins" disabled=yes interval=5m25s name=\
checker on-event="/system scheduler set [find name=backupwan] disabled=yes\
\r\
\n:local pinged [/ping address=151.101.193.67 count=5 interface=ether1 siz\
e=50]\r\
\n:if ((\$pinged=5)) do={\r\
\n#send email\r\
\n/tool e-mail send subject=(\"Primary is back\") \\\r\
\nbody=(\"PTCL is being used at \" . [/system clock get time]) \\\r\
\nto=(\"xxxxxxxx@gmail.com\")\r\
\n\r\
\n#change route to enable primary\r\
\n\r\
\n/ip route set [find comment=\"Main\"] distance=1\r\
\n/ip route set [find comment=\"Backup\"] distance=2\r\
\n#delay 5\r\
\n/system scheduler set [find name=main] disabled=no\r\
\n}" policy=\
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=jun/21/2019 start-time=21:33:27
/tool bandwidth-server
set enabled=no
/tool e-mail
set address=74.125.206.109 from=XXXX@gmail.com password=\
XXXXXXXXXX port=587 start-tls=yes user=XXXXXX@gmail.com