Now that we have lots of 4G dongles providing clients a failover when their ADSL dies (crappy copper means when not if) We need to monitor the status of the routes.

For this to work you need to do a few things first.

Setup email on the router. Server IP and username/password. Dont use the ISPs one as you will be changing ISP when the connection fails, use a webserver, make a crappy account and bounce it from there.

Setup static routes to the internet, with check gateway enabled on each.

 

Then, put in this script, setting it to run every 1 min

 

# MUST BE RUN EVERY 1 MINUTE
# FIRST ALERT AFTER 10 MINUTES, SECOND ALERT AFTER 1 HOUR

:local emlFrom mikrotik@theclient.com
:local emlRec1 somepoorbunny@getsthespam.com
:local emlRec2 0
:local emlRec3 0
:local emlRec4 0

# ALL PRECEDING ENTRIES MUST BE REPLACED BY ACTUAL DATA INSIDE DOUBLE QUOTES OR ZEROS

# ACTUAL SMTP SERVER TO BE INSERTED ABOVE

:global gwur10m
:global gwur50m
:local aa
:local emlRecs [:toarray ($emlRec1,$emlRec2,$emlRec3,$emlRec4)]
:local emlText (” unreachable on “.[/system identity get name])
:local unrable 0
:if ( [:typeof $gwur10m]!=”num” ) do={ :set gwur10m -1 }
:if ( [:typeof $gwur50m]!=”num” ) do={ :set gwur50m 50 } else={ :set gwur50m ($gwur50m+1) }
:if ( $gwur50m>49 ) do={
:foreach pp in=[/ip route find] do={
:foreach qq in=[/ip route get $pp gateway-status] do={
:set aa [:find $qq “reachable”]
:if ( [:pick $qq ($aa-2) $aa]=”un” ) do={ :set unrable ($unrable+1) }
} }
:if ( $unrable=0 ) do={
:set gwur10m -1
} else={
:if ( $gwur10m<9 ) do={
:set gwur10m ($gwur10m+1)
} else={
:set gwur10m -1
:set gwur50m -1
:if ( $unrable=1 ) do={ :set aa “Gateway” } else={ :set aa ($unrable.” gateways”) }
:log info “••• Unr_able: $aa unreachable, e-mail alert sent.”
:foreach pp in=$emlRecs do={
:if ( $pp!=0 ) do={
/tool e-mail send body=”Gateway(s)$emlText for over 10 minutes.” subject=”>>> $aa$emlText <<<” to=$pp
} } } } }

Credit for this has to go to

http://forum.mikrotik.com/viewtopic.php?f=9&t=70698

But i have removed some of the email settings to make it easier to use.

I haven’t used this in anger yet, that is tomorrows job 🙂

« »