50. Mikrotik Auto Limit Speed When 1 connection is DOWN.

/system scheduler
add disabled=yes interval=5s name=ping_google_link_B on-event=scheduler-B \
    policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=jan/01/1970 start-time=00:00:00
add interval=5s name=ping_google_link_Both on-event=scheduler-Both policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=jan/01/1970 start-time=00:00:00
add disabled=yes interval=5s name=ping_google_link_A on-event=scheduler-A \
    policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    start-date=jan/01/1970 start-time=00:00:00


Scheduler-A:

#set variables
:local pingcount  3
:local ipA 192.168.73.3
:local ipB 192.168.74.3


#ping gateways with src
:local pingresultA [/ping 8.8.8.8 src-address=$ipA count=$pingcount]
:local pingresultB [/ping 8.8.8.8 src-address=$ipB count=$pingcount]


#if link_A is UP
:if (($pingresultA=3)) do={
#send email
/tool e-mail send subject=($ipA . " is up, WAN2 Speed is Downgraded ") \
body=("the gateway is up now at: " . [/system clock get date] . " time " .  [/system clock get time]) \ to=("alertphalla@gmail.com")
#Limite Speed
/queue simple
set queue2 max-limit=1M/1M

#enable scheduler-Both
/system scheduler set [find name=ping_google_link_Both] disabled=no

#disablescheduler-B
/system scheduler set [find name=ping_google_link_B] disabled=yes

#disable scheduler-A
/system scheduler set [find name=ping_google_link_A] disabled=yes

}



Scheduler-B:

#set variables
:local pingcount  3
:local ipA 192.168.73.3
:local ipB 192.168.74.3


#ping gateways with src
:local pingresultA [/ping 8.8.8.8 src-address=$ipA count=$pingcount]
:local pingresultB [/ping 8.8.8.8 src-address=$ipB count=$pingcount]

#if Link_B is UP
:if (($pingresultB=3)) do={
#send email
/tool e-mail send subject=($ipB . " is up, WAN1 Speed is Downgraded ") \
body=("the gateway is up now at: " . [/system clock get date] . " time " .  [/system clock get time]) \ to=("alertphalla@gmail.com")
#Limite Speed
/queue simple
set queue1 max-limit=1M/1M

#enable scheduler-Both
/system scheduler set [find name=ping_google_link_Both] disabled=no

#disable scheduler-A
/system scheduler set [find name=ping_google_link_A] disabled=yes

#disable scheduler-B
/system scheduler set [find name=ping_google_link_B] disabled=yes

}



Scheduler-Both:

#set variables
:local pingcount  3
:local ipA 192.168.73.3
:local ipB 192.168.74.3
:global state no

#ping gateways with src
:local pingresultA [/ping 8.8.8.8 src-address=$ipA count=$pingcount]
:local pingresultB [/ping 8.8.8.8 src-address=$ipB count=$pingcount]


#if link_A is DOWN and link_B is UP then:
:if (($pingresultA=0) && ($pingresultB>0)) do={
#send email
/tool e-mail send subject=($ipA . " is down, WAN2 Speed is Upgraded ") \
body=("the gateway is down now at: " . [/system clock get date] . " time " .  [/system clock get time]) \ to=("alertphalla@gmail.com")
#Limite Speed
/queue simple
set queue2 max-limit=2M/2M

#disable scheduler-A
/system scheduler set [find name=ping_google_link_A] disabled=no

#disable scheduler-B
/system scheduler set [find name=ping_google_link_B] disabled=yes

#disable scheduler-Both
/system scheduler set [find name=ping_google_link_Both] disabled=yes
}


#if link_A is UP and link_B is DOWN then:
:if (($pingresultA>0) && ($pingresultB=0)) do={
#send email
/tool e-mail send subject=($ipB . " is down, WAN1 Speed is Upgraded ") \
body=("the gateway is down now at: " . [/system clock get date] . " time " .  [/system clock get time]) \ to=("alertphalla@gmail.com")
#Limite Speed
/queue simple
set queue1 max-limit=2M/2M

#disable scheduler-B
/system scheduler set [find name=ping_google_link_B] disabled=no

#disable scheduler-A
/system scheduler set [find name=ping_google_link_A] disabled=yes

#disable scheduler-Both
/system scheduler set [find name=ping_google_link_Both] disabled=yes

}

You can contact me: plus.google.com/+PhallaCCMT; youtube.com/phallaccmt; facebook.com/Phalla.CCMT; twitter.com/PhallaCCMT and Phalla.CCMT@gmail.com
Previous
Next Post »