Alert on AS Route becomes inactive

Hi Guys,

I am trying to generate alerts for when certain routes become inactive. I have two WANs, one of them is an LTE with limited data. Therefore I want to know when it’s in use so that I can investigate.

I have used the script below to successfully detect my WAN outage by running the script on a schedule, however, I obviously get a notification for each time the schedule runs whilst the outage is in play.

Is there a way I could do this and only get a single notification for this as I intend to email the notifications and don’t want to spam myself. I also don’t want to slow down the schedule as that would potentially leave it longer before I receive a notification of the outage and use more of the expensive data.

{
local status [ip route get value-name=active [find comment="3.  Recursive lookup for Virgin connection (Via WAN routing table)"]]
if ($status= false) do={/log info "gateway is down"} 
}

Hi Guys,

Thought I would update the post with what I ended up with. I received assistance from a few users on Facebook groups.

{
:global prevstatus;
:global status [:ip route get value-name=active [:ip route find comment="3.  Recursive lookup for Virgin connection (Via WAN routing table)"]]
:if ( "$status" != "$prevstatus" ) do={
:log warn "Virgin gateway changed status from \"$prevstatus\" -> \"$status\" (true=up, false=down, nothing=unintialized)";
:tool e-mail send to=user1@jdomain1.com subject="Virgin WAN gateway changed status" body=( [ :system clock get date ] . " " . [ :system clock get time ] . " gateway changed status from \"$prevstatus\" -> \"$status\" (true=up, false=down, nothing=unintialized)" )
:tool e-mail send to=user2@domain2.com subject="Virgin WAN gateway changed status" body=( [ :system clock get date ] . " " . [ :system clock get time ] . " gateway changed status from \"$prevstatus\" -> \"$status\" (true=up, false=down, nothing=unintialized)" )
}
:global prevstatus $status
}

I hate to revive an old thread, but this script worked perfectly the first time and the poster deserves a kudos. Thank you!

My condition: My office has 3 WAN routes. Because they are fail-over and load-balanced, if one ISP fails, internet access is not affected and nobody knows. So I needed a script which would detect when a route fails and sends an email.

All I needed to do was:

  1. Change the email address in the script
  2. Change the comment search text
  3. Make sure the SMTP server is setup properly so that the mikrotik can send emails
  4. Schedule the script to run every few minutes.
  5. Repeat for WAN-2 and WAN-3

I am a beginner to MT scripting and this script worked flawlessly. I don’t know if it is the optimal way to do so but for now it is perfect.

HI there ashpri thanks for your info.

How would i add more route names to monitor in that script and then to send a custom email message for that specific route that changed ?

Many thanks

Hi, the script works perfectly in version 6, but in version 7 it has a certain error since it does not show the false status. Someone must have updated the script? Many thanks

Till now, not.

This works on both v6 and v7:

/ip route
:global routePrevStat
:global routeCurrStat "NOT Active"
:if ([get [find where comment~"comment on route"] active]) do={:set routeCurrStat "ACTIVE"}
:if ($routePrevStat != $routeCurrStat) do={
    :local logmsg "The route with comment \"comment on route\" change status from $routePrevStat to $routeCurrStat"
    :log warn $logmsg
    /system clock
    :local cdate [get date]
    :local ctime [get time]
    :tool e-mail send to="user1@example.com,user2@example.com" subject=$logmsg body="$cdate $ctime $logmsg"
}
:set routePrevStat $routeCurrStat

Obviously the route with comment "comment on route" nmust already exist, and must be only one...

1 Like

Simply excellent, tested in v7. I've been struggling for about three days trying to reorganize the main post script, but nothing new. This new script has saved me from having to constantly monitor the Winbox. Thank you very much for your collaboration.