How to detect when WAN failover mode is activated on the router ?

  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.

SR-G

New Around Here
Hello,

I have a RT-AC88U (with Asus Merlin firmware) at home, WAN connected through a fiber connection (via the "free" french network), on which i have quite often some shutdowns (it seems that it's vandalism and that some guys are unplugging everything in the neighborhood (sigh) ...)

So i configured Dual Wan, in failover mode, and everything is working fine (with a TP-LINK 4G router connected to LAN1).

But is there any way for me to easily set up "something" in order to be warned when the router is switching to the failover WAN ?

I don't see any built-in notifications about this, so is there something like an ASUS or ASUS-MERLIN API, or a SSH command maybe, that would easily allow me to remotely check this like twice a day (in order for me to be warned that my main connection is down and that i have to create a ticket for the situation to be solved by the provider ...) ? (i would cron a small script on one of my server to the check, for example)

Thanks in advance for any clue about this.
 

eibgrad

Very Senior Member
I don't use dual WAN. But if you configure DDNS on the router (even if you don't need it for remote access purposes), I would think you should be able to detect a change to the public IP associated w/ that domain name that is NOT typically associated w/ your ISP, strongly suggesting a changeover has occurred. That is unless a failover doesn't update DDNS (again, I don't use dual WAN, so I'm just assuming it does).
 

john9527

Part of the Furniture
Check the following nvram variables to see which is the primary interface

nvram get wan0_primary
nvram get wan1_primary

The active wan will return '1'.....the inactive '0'
 

SR-G

New Around Here
Thanks - it does the trick.

Current status on router :


Quick script to detect changes :

Code:
#!/bin/zsh

# nohup check-dual-wan-status.sh >/var/log/check-dual-wan-status.log 2>&1 & disown

PREVIOUS_WAN_PRIMARY=-1
PREVIOUS_WAN_SECONDARY=-1

DEST="<email>@<domain.tld>"
INTERVAL=3600

while [[ true ]] ; do
  ssh [email protected] /bin/sh << EOF | tr "\n" " " | read WAN_PRIMARY WAN_SECONDARY
    nvram get wan0_primary
    nvram get wan1_primary
EOF
  DATE=$(date "+%Y-%m-%d %H:%M")
  if [[ $PREVIOUS_WAN_PRIMARY -eq -1 && $PREVIOUS_WAN_SECONDARY -eq -1 ]] ; then
    echo "$DATE --- Initialization ... \n - Primary WAN detected as [$WAN_PRIMARY]\n - Secondary WAN detected as [$WAN_SECONDARY]"
  elif [[ $PREVIOUS_WAN_PRIMARY -ne $WAN_PRIMARY || $PREVIOUS_WAN_SECONDARY -ne $WAN_SECONDARY ]] ; then
    EXPLANATIONS=""
    [[ $PREVIOUS_WAN_PRIMARY -eq 1 && $WAN_PRIMARY -eq 0 ]] && EXPLANATIONS="${EXPLANATIONS}\n - Primary WAN not connected anymore"
    [[ $PREVIOUS_WAN_PRIMARY -eq 0 && $WAN_PRIMARY -eq 1 ]] && EXPLANATIONS="${EXPLANATIONS}\n - Primary WAN connected again"
    [[ $PREVIOUS_WAN_SECONDARY -eq 1 && $WAN_SECONDARY -eq 0 ]] && EXPLANATIONS="${EXPLANATIONS}\n - Secondary WAN not connected anymore"
    [[ $PREVIOUS_WAN_SECONDARY -eq 0 && $WAN_SECONDARY -eq 1 ]] && EXPLANATIONS="${EXPLANATIONS}\n - Secondary WAN connected again"

    echo "$DATE --- Something has changed ... : $EXPLANATIONS"
    echo "$DATE --- Something has changed ... : $EXPLANATIONS" | mail -v -s "[$(hostname)] Controls : check-dual-wan-status" "$DEST"

  else
    echo "$DATE --- No changes"
  fi
  PREVIOUS_WAN_PRIMARY=$WAN_PRIMARY
  PREVIOUS_WAN_SECONDARY=$WAN_SECONDARY
  sleep $INTERVAL
done
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

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