Community discussions

MikroTik App
 
ripemango
just joined
Topic Author
Posts: 4
Joined: Sun Aug 09, 2020 10:23 am

Wan status through Email notification with up time and down time

Fri Aug 21, 2020 11:35 pm

An easy way to set up wan status through Email for a single upstream.

Step 1:
Set up email first.
/tool e-mail
set address=173.194.77.108
set port=587
set from=myuser@gmail.com
set user=myuser
set password=mypassword 
For details https://wiki.mikrotik.com/wiki/Manual:Tools/email

Step 2:

Now set up scheduler to check Wan status
/system scheduler
add interval=10s name="WAN STATUS" on-event=":global my;\r\
    \nif ([/ping 8.8.8.8 interval=1 count=5]=0 && \$my=1) do={\\\r\
    \nsystem script run down; \\ \r\
    \nglobal my value=0; }\r\
    \nif ([/ping 8.8.8.8 interval=1 count=5]=5 && \$my=0) do={\\\r\
    \nsystem script run up; \\  \r\
    \nglobal my value=1;}  " policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-date=dec/22/2019 start-time=17:00:00
    
    add name="VARIABLE VALUE" on-event=\
    ":global my;\r\
    \n/system script environment set my value=0" policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-time=startup
    
Step 3:
Up and down time scripting:

When the Wan is Down:
/system script
add dont-require-permissions=yes name=down policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":\
    global mydown;/\r\
    \n:set mydown \"\$[/system clock get time]\";/\r\
    \n:log error \"WAN link is down\";"
When the wan is Up:
/system script
add dont-require-permissions=yes name=up policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source=":\
    global mydown;/\r\
    \n:log error \"WAN link is up again\";/\r\
    \n:tool e-mail send to=\"myuser@gmail.com\" subject=\"WAN STATUS\" body=\"\
    WAN Link was down from \$mydown. WAN Link is up again on \$[/system clock \
    get time]. \";"

Hope you like it.
Feel free to make suggestions.
Thank you.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Wan status through Email notification with up time and down time

Mon Aug 24, 2020 11:57 am

Why do the WAN goes down?
 
gotsprings
Forum Guru
Forum Guru
Posts: 2102
Joined: Mon May 14, 2012 9:30 pm

Re: Wan status through Email notification with up time and down time

Mon Sep 07, 2020 5:41 pm

I pay the 75 bucks a year to Domotz.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Wan status through Email notification with up time and down time

Mon Mar 07, 2022 3:41 pm

From 20 May is impossible to use gmail without OAuth2

Who is online

Users browsing this forum: rogerioqueiroz and 20 guests