MWAN3 alert script

I have a dual wan setup, one is a pppoe client. I have set up mwan3 which works fine, and I wrote a notification script which sends a pushover when the wan interface goes down. The problem is that my isp terminates the wan connection after every 7 days, when the router connects back, but every time I got a notification. How can I achieve not to get a notification is the connection goes down for less than 10 seconds?

You're asking us how to modify a script you haven't showed us ?

1 Like

Save the time (somewhere in /tmp/) connection goes down and check the time difference between saved time and current time in the notification script.

This is my script:

# This file is interpreted as shell script.
# Put your custom mwan3 action here, they will
# be executed with each netifd hotplug interface event
# on interfaces for which mwan3 is enabled.
# There are three main environment variables that are passed to this script.
#      <ifup>         Is called by netifd and mwan3track.
#      <ifdown>       Is called by netifd and mwan3track.
#      <connected>    Is only called by mwan3track if tracking was successful.
#      <disconnected> Is only called by mwan3track if tracking has failed.
# $INTERFACE	Name of the interface an action relates to (e.g. "wan" or "wwan").
# $DEVICE	Physical device name of the interface the action relates to (e.g. "eth0" or "wwan0").
#               Note: On an ifdown event, $DEVICE is not available, use $INTERFACE instead.
# Further documentation can be found here:


if [ "${INTERFACE}" = "wan" ]; then
	if [ "${ACTION}" = "connected" ] || [ "${ACTION}" = "disconnected" ] ; then
		#/bin/sleep 5;
		if [ "${ACTION}" = "connected" ] && [ "${INTERFACE}" = "wan" ] ; then
			po_title="Internetkapcsolat helyre√°llt"
			po_message="A DIGI internetkapcsolat helyre√°llt."
		elif [ "${ACTION}" = "disconnected" ] && [ "${INTERFACE}" = "wan" ] ; then
			po_title="Internetkapcsolat megszakadt"
			po_message="A DIGI internetkapcsolat megszakadt."
		push_res=$(curl -s -F "token=$po_app_token" -F "user=$po_user_key" -F "sound=$po_sound" -F "message=$po_message" -F "title=$po_title"
		logger "Pushover kuldes: $push_res"

This is okay, but what will call the script the second time? I need that after 10 seconds call the script, and check the wan state. If I put a sleep 10 to the script is a good way, but how can I check the wan state?

Well, if you store the time upon WAN disconnect and check it when the script is called again upon connect and do not send notification if the connection was established less than 10 seconds after disconnection, you'd end up with only one notification on disconnect.

The only solution really is to delay sending notification on disconnect by employing an external script (which would sleep for like 20 seconds before sending notification), and if connection is re-established within 10 seconds, kill that external script thus preventing any notifications from reaching you.

1 Like