Community discussions

MikroTik App
 
ukzerosniper
Member Candidate
Member Candidate
Topic Author
Posts: 129
Joined: Tue Jul 23, 2013 9:20 pm

Alert on AS Route becomes inactive

Sun Oct 28, 2018 3:54 pm

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"} 
}
 
ukzerosniper
Member Candidate
Member Candidate
Topic Author
Posts: 129
Joined: Tue Jul 23, 2013 9:20 pm

Re: Alert on AS Route becomes inactive

Sun Oct 28, 2018 8:08 pm

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
}
 
ashpri
Member Candidate
Member Candidate
Posts: 154
Joined: Sun Oct 14, 2018 3:11 am

Re: Alert on AS Route becomes inactive

Sat Aug 13, 2022 5:31 pm

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.
 
djshaunvt
just joined
Posts: 10
Joined: Fri May 29, 2020 8:34 am

Re: Alert on AS Route becomes inactive

Tue Mar 12, 2024 7:49 am

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

Who is online

Users browsing this forum: ko00000000001 and 19 guests