What's new

Email notification when switching to secondary WAN?

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Hmmm that's really interesting.
While waiting for your answer - i decided to upgrade from 380.66.4 to 380.66.6 and router asked me for a manual power off.
After that i tried to switch from primary to secondary - and got TWO emails as usual. But when i switched back from secondary to primary - i finally started getting emails. So power cycle helped to solve one of two problems.
So i'll make some tests. The only problem left for now is:

Code:
Jun 24 18:58:06 miniupnpd[1807]: HTTP listening on port 50089
Jun 24 18:58:06 miniupnpd[1807]: Listening for NAT-PMP/PCP traffic on port 5351
Jun 24 18:58:07 admin: wan_connect_notification: WAN connection restored. Ping cycles = 4, Actual time = 8, via /jffs/scripts/wan-start
Jun 24 18:58:07 admin: wan_connect_notification: WAN connection restored. Ping cycles = 2, Actual time = 4, via /jffs/scripts/wan-start
Jun 24 18:58:09 miniupnpd[1807]: upnp_event_recv: recv(): Connection reset by peer
Jun 24 18:58:09 miniupnpd[1807]: upnp_event_recv: recv(): Connection reset by peer
Jun 24 18:58:09 admin: wan_connect_notification: WAN type change detected, notification sent to avoronkov@gmail.com via /jffs/scripts/wan-start
Jun 24 18:58:10 admin: wan_connect_notification: WAN type change detected, notification sent to avoronkov@gmail.com via /jffs/scripts/wan-start
Jun 24 18:59:29 rc_service: wanduck 274:notify_rc restart_wan_if 0
The wan-start script is called twice, that's why you get two emails. but that's easily fixable on my end.
Will do that as soon as time permits.
 
Version 1.6 of the WAN connect notification script is now available.
- prevents sending duplicate notification, change LOCK_FILE_REMOVE_WAIT= if necessary
- last WebUI login IP address in email

Download in Other Scripts section here.
 
Just to make you update to 1.7... :)

echo " NPT update cycles: $NTP_UP_CYCLES" >>/tmp/wanmail.txt

# Set enctyption type: SSL = smtps (default), TLS = smtp
 
Just to make you update to 1.7... :)

echo " NPT update cycles: $NTP_UP_CYCLES" >>/tmp/wanmail.txt

# Set enctyption type: SSL = smtps (default), TLS = smtp
That would be part of a reason to work on v1.7.
But maybe someone has an idea to make this even more useful?
Add more info perhaps?
 
But maybe someone has an idea to make this even more useful?

A few minor things. You probably should make your lock file "smarter". In the event the script gets terminated while running, the lock file will exist until manually deleted or reboot (thus clearing /tmp). The way I overcame this was inserting the PID into the lock file upon creation and only honouring the lock file if it exists & the process is still active, example.

Code:
Check_Lock () {
        if [ -f "/tmp/skynet.lock" ] && [ -d "/proc/$(cat /tmp/skynet.lock)" ]; then
            logger -st Skynet "[INFO] Lock File Detected (pid=$(cat /tmp/skynet.lock)) - Exiting"
            exit 1
        else
            echo "$$" > /tmp/skynet.lock
        fi
}

Another minor improvement would be POSIX compliance, although I doubt ASUSWRT will ever change shells, its always good practice to make it portable as possible. A good tool for this is the website ShellCheck
 
A few minor things. You probably should make your lock file "smarter". In the event the script gets terminated while running, the lock file will exist until manually deleted or reboot (thus clearing /tmp). The way I overcame this was inserting the PID into the lock file upon creation and only honouring the lock file if it exists & the process is still active, example.

Code:
Check_Lock () {
        if [ -f "/tmp/skynet.lock" ] && [ -d "/proc/$(cat /tmp/skynet.lock)" ]; then
            logger -st Skynet "[INFO] Lock File Detected (pid=$(cat /tmp/skynet.lock)) - Exiting"
            exit 1
        else
            echo "$$" > /tmp/skynet.lock
        fi
}

Another minor improvement would be POSIX compliance, although I doubt ASUSWRT will ever change shells, its always good practice to make it portable as possible. A good tool for this is the website ShellCheck
Excellent advice, I was thinking about a timestamp but dropped the idea in case NTP fails to update.
But I knew your scenario can happen and planned to implement something less dumb for the next version.
 
Making it POSIX compliant @Adamm is simle for that small script.
I once tried to paste the AB-Solution code into the checker. It didn't even timeout but simply ignored the 4 or 5000 lines of it.
 
But maybe someone has an idea to make this even more useful?
I think it would be interesting to add option to reboot router when both primary and secondary WAN cannot ping 8.8.8.8 within XX minutes. Sometimes reboot helps to get new ip from ISP or reboot can help to fix dongle.
Actually asus' watchdog for dual wan is not reliable at all. I don't know yet how it works with secondary wan via lan cable but when i used usb dongle as secondary wan - it was a 2 year disaster. So rewriting dual wan switch mechanism would be great.
 
Version 1.7 of the WAN connect notification script is now available.
- smarter lock file handling
- now with auto-reboot feature if WAN does not come up when a change is detected

IMPORTANT: Remove the word "source" in /jffs/scripts/wan-start, like so:
OLD /jffs/scripts/wan-start entry:
Code:
source /jffs/scripts/wan_connect_notification # WAN change notification email
NEW /jffs/scripts/wan-start entry:
Code:
/jffs/scripts/wan_connect_notification # WAN change notification email


The new auto-reboot feature is by default set to off.

Auto-reboot feature
This reboots the router once if the WAN does not restore fully for some reason.
The reboot is issued when all the timeout's are reached, with this formula:
NTP_TIMEOUT + WAN_WAIT_CYCLES + (PING_TIMEOUT * PING_COUNT)
Default setting is off (no rebooting), to activate, set to on

Download in Other Scripts section here.

Email after a reboot and WAN restoration:
Code:
  There's been a WAN type change on the router on Wed, 28 Jun 2017 18:09:02 +0200.

  Router RT-AC1900P is now connected through Primary WAN
  The WAN IP is: 192.168.2.60

  Router has been rebooted once to restore WAN connection.

  Router uptime: 0 days 00 hours 05 minutes 49 seconds
  The LAN IP is: 172.20.0.1
  Last WebUI login IP address: 172.20.0.8

  wan_connect_notification script stats:
  Seconds until NTP updated: 3
  Ping cycles = 1, actual wait time until WAN up = 2 seconds.
  WAN IP register wait cycles: 0

  ---
  Your friendly router.
 
perhaps instead of rebooting the router,
things may workout with just restarting pppd
or restarting wan

Code:
# For wan0 link, modify for dual wan 
if (cat /var/run/ppp0.pid)
then
   logger "wan0 already running..."
   killall pppd #or just kill the pid of cat cmd
fi

logger "Starting wan0..."
/usr/sbin/pppd file /tmp/ppp/options.wan0

service restart_wan
service restart_dnsmasq
service restart_ntpc
 
perhaps instead of rebooting the router,
things may workout with just restarting pppd
or restarting wan

Code:
# For wan0 link, modify for dual wan
if (cat /var/run/ppp0.pid)
then
   logger "wan0 already running..."
   killall pppd #or just kill the pid of cat cmd
fi

logger "Starting wan0..."
/usr/sbin/pppd file /tmp/ppp/options.wan0

service restart_wan
service restart_dnsmasq
service restart_ntpc
I was thinking of this too, but used the brute force method and see what users say first.
I don't have a USB Modem at hand to test if it fails, only my Android phone where you have to set the tethering by hand on the phone every time the USB ports get powered off and on.
This might be an option in v1.8 tough if interest is there.
Say, first try to restart the services and if WAN still does not come up to reboot as a last option.
 
@RMerlin, @john9527 or anyone in the know:
There are five WAN types,
dhcp, static, pppoe, pptp and l2tp.

What services need to restart to force detection of a WAN connection if it fails for each of the WAN types?
Obvious are these, although the ntpclient may not be necessary as it will continue probing anyway:
service restart_wan
service restart_dnsmasq
service restart_ntpc
Any more services to restart for pppoe, pptp and l2tp?
Thanks
 
@RMerlin, @john9527 or anyone in the know:
There are five WAN types,
dhcp, static, pppoe, pptp and l2tp.

What services need to restart to force detection of a WAN connection if it fails for each of the WAN types?
Obvious are these, although the ntpclient may not be necessary as it will continue probing anyway:
service restart_wan
service restart_dnsmasq
service restart_ntpc
Any more services to restart for pppoe, pptp and l2tp?
Thanks

AFAIK
Restarting pppd will restart pppoe, dnsmasq (dhcp) and wan.

As for the VPN protocols i.e., pptp etc.,
i assume if the VPN is configured to be ON,
it should restart auto after a ppp/wan restart/change.
 
AFAIK
Restarting pppd will restart pppoe, dnsmasq (dhcp) and wan.

As for the VPN protocols i.e., pptp etc.,
i assume if the VPN is configured to be ON,
it should restart auto after a ppp/wan restart/change.
Thanks, I'll test it.
 
Hmmm asus watchdog for switching between primary and secondary wan is not reliable at all. Now my primary line is down but it didnt switch to secondary i dont know why. And i cannot see the log because i am not there.
May be it is possible to add some mechanism to the script that can constantly ping 8.8.8.8 through primary wan and if ping fails - then check if asus switched to secondary. If it didnt - then force switch. And back for failover.
As far as i understand - its not too complicated but will help a lot those who suffer from asus' dual wan switch mechanist that works like sh"t.
Thanx!
 
UPD. Primary wan got back to norm and i managed to teamviewer the router's log. It even didn't try to switch from primary to secondary wan because it didn't see the problem. Watchdog is enabled, dual wan is enabled, ping to internet and failback are enabled and so on. But the router even didn't see that primary wan was down. So 2 questions:
1. May the script somehow interfear asus' dual wan switch mechanism? Not the one which works when you unplug network cable but the one that pings smth and swithces to secondary when primary is down.
2. Does anyone have the same problem like i do? Asus' dual wan switch mechanism is not reliable at all.
It means that it would be great to add some lines to the script that could check if asus did smth when primary wan got down or no. If no - then fix this. And after that - help with failback as well.

 
UPD. Primary wan got back to norm and i managed to teamviewer the router's log. It even didn't try to switch from primary to secondary wan because it didn't see the problem. Watchdog is enabled, dual wan is enabled, ping to internet and failback are enabled and so on. But the router even didn't see that primary wan was down. So 2 questions:
1. May the script somehow interfear asus' dual wan switch mechanism? Not the one which works when you unplug network cable but the one that pings smth and swithces to secondary when primary is down.
2. Does anyone have the same problem like i do? Asus' dual wan switch mechanism is not reliable at all.
It means that it would be great to add some lines to the script that could check if asus did smth when primary wan got down or no. If no - then fix this. And after that - help with failback as well.

I have seen the same behaviour, with the same settings for watchdog as yours.
Say, my Asus is on wan0, wan0 is connected to router0 with internet, wan1 to router1 with internet.
Then I unplug the wan cable on router0, you'd expect Asus to switch to wan1 within the watchdogs ping timeouts.
But no, it stubbornly stays on wan0 even though the pings must fail.
This happens on Merlin as well as on john9527 fork.

I find it concerning that such a simple function does not work reliably.
Do I really have to make a shell script that watches the watchdog and do it's function when Asus is unable to provide this service satisfactorily?
Seems I need to spend even more time on that already souped up script...
 
Do I really have to make a shell script that watches the watchdog and do it's function when Asus is unable to provide this service satisfactorily?
Seems I need to spend even more time on that already souped up script...
It would be really great to add this function to the wan notification script and make it "Dual WAN script" - because i am more then sure that many people face the same problem. When i had dual wan with usb modem - it didn't work properly as well. Thanx to asus.
The main problem with this script as i see - is not to interfear with asus' dual wan settings. If router decides to work properly with stock dual wan settings or if router fails to work with stock settings. So the script should work together with asus dual wan mechanism, controll it and fix if asus works wrong.
I think donation button would be quite ok for such a project - if you manage to fix this asus' f"ckup with your great script - i would be glad to make a donation as well.
P.S. By the way - when i unplug primary wan cable - router switches to secondary within ping time. So problem is only with ping to internet function, when primary wan cable is physically connected, but ISP is down because of some weather or other problems.
 
P.S. By the way - when i unplug primary wan cable - router switches to secondary within ping time. So problem is only with ping to internet function, when primary wan cable is physically connected, but ISP is down because of some weather or other problems.
I noticed the same, dead or unplugged works right away but not if internet connection is lost.
 
This happens on Merlin as well as on john9527 fork.
When is the last time you tried my fork? I touched the 'third rail' and did a bunch of wanduck changes in V23 working off-line with someone on dual-wan and got things pretty well working (at least for him).

One thing on my fork....make sure you set "Redirect to error page" to LAN or WAN down if running dual-wan. It turns out that setting has additional meaning in a dual-wan environment.
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top