Skip to content

Commit 1dd97ec

Browse files
ns-plug: avoid mwan3 alerts during restart
Running /etc/init.d/mwan3 restart produces a rapid disconnect/connect sequence which triggers an alert lasting a few seconds. This PR avoid the false alarm delaying disconnect alerts by 30 seconds. #992 required.
1 parent ee52d04 commit 1dd97ec

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

packages/ns-plug/files/send-mwan-alert

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
lk=$(uci -q get ns-plug.config.system_id)
1010
secret=$(uci -q get ns-plug.config.secret)
1111
url=$(uci -q get ns-plug.config.alerts_url)"alerts/store"
12+
pidfile="/tmp/mwan3.$INTERFACE"
1213

1314
# Do not send alert if system_id or secret is not set
1415
if [ -z "$lk" ] || [ -z "$secret" ]; then
@@ -17,8 +18,21 @@ fi
1718

1819
# Ignore ifup and ifdown events, they both triggers connected and disconnected events
1920
if [ "${ACTION}" == "connected" ]; then
21+
pid=$(cat "$pidfile" 2>/dev/null)
22+
# If a wan is connected within 30 seconds from disconnect, assume it's a restart
23+
# and kill the alert sending process
24+
# mwan3 restart should complete within 30 seconds
25+
if [ -n "$pid" ]; then
26+
kill -s SIGHUP "$pid"
27+
rm "$pidfile"
28+
exit 0
29+
fi
2030
status="OK"
2131
elif [ "${ACTION}" == "disconnected" ]; then
32+
echo $$ > "$pidfile"
33+
# Delay alert by 30 seconds, so that it can be canceled
34+
sleep 30
35+
rm "$pidfile"
2236
status="FAILURE"
2337
fi
2438

@@ -30,6 +44,6 @@ fi
3044
alert_id="wan:${INTERFACE}:down"
3145
logger -t mwan3-alert "Sending alert ${alert_id} with status ${status}"
3246
payload='{"lk": "'$lk'", "alert_id": "'$alert_id'", "status": "'$status'"}'
33-
/usr/bin/curl -m 180 --retry 3 -L -s \
47+
/usr/bin/curl -m 30 --retry 3 -L -s \
3448
--header "Authorization: token ${secret}" --header "Content-Type: application/json" --header "Accept: application/json" \
35-
--data-raw "${payload}" ${url}
49+
--data-raw "${payload}" ${url}

0 commit comments

Comments
 (0)