netwatch-notify: do not (yet) notify if parent is up recently

Monitoring a VPN (or similar) may be tricky: This used to send notifications
if the physical connection recovered, but the VPN and/or its routing did not
yet. Let's work around and send notification only if the parent is up
for at least three checks.
This commit is contained in:
Christian Hesse 2022-09-07 22:16:11 +02:00
parent a6645b3e75
commit 5aff4019fe

View file

@ -128,6 +128,7 @@ $ScriptLock $0;
:set ($Metric->"since") ($HostVal->"since");
:local CountDown [ $IfThenElse ([ :tonum ($HostInfo->"count-down") ] > 0) ($HostInfo->"count-down") 5 ];
:local Parent ($HostInfo->"parent");
:local ParentUp false;
:while ([ :len $Parent ] > 0) do={
:set CountDown ($CountDown + 1);
:set Parent ($NetwatchNotify->$Parent->"parent");
@ -137,6 +138,7 @@ $ScriptLock $0;
:while ($ParentNotified = false && [ :len $Parent ] > 0) do={
:set ParentNotified [ $IfThenElse (($NetwatchNotify->$Parent->"notified") = true) \
true false ];
:set ParentUp ($NetwatchNotify->$Parent->"count-up");
:if ($ParentNotified = false) do={
:set Parent ($NetwatchNotify->$Parent->"parent");
}
@ -151,7 +153,7 @@ $ScriptLock $0;
$NetwatchNotifyHook $Name $Type "pre-down" ($HostInfo->"pre-down-hook");
}
:if ($ParentNotified = false && $Metric->"count-down" >= $CountDown && \
$Metric->"notified" != true) do={
($ParentUp = false || $ParentUp > 2) && $Metric->"notified" != true) do={
:local Message ("The " . $Type . " '" . $Name . "' (" . $HostDetails . \
") is down since " . $HostVal->"since" . ".");
:if ([ :typeof ($HostInfo->"down-hook") ] = "str") do={