From 95274e0d23d956c48be2fdecd502a05e00bcd359 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 7 Sep 2022 21:54:14 +0200 Subject: netwatch-notify: rename variable --- netwatch-notify | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/netwatch-notify b/netwatch-notify index 305baba..994a8d1 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -98,8 +98,8 @@ $ScriptLock $0; } :if ($HostVal->"status" = "up") do={ - :local Count ($Metric->"count"); - :if ($Count > 0) do={ + :local CountDown ($Metric->"count"); + :if ($CountDown > 0) do={ $LogPrintExit2 info $0 \ ("The " . $Type . " '" . $Name . "' (" . $HostDetails . ") is up.") false; :set ($Metric->"count") 0; @@ -107,7 +107,7 @@ $ScriptLock $0; :if ($Metric->"notified" = true) do={ :local Message ("The " . $Type . " '" . $Name . "' (" . $HostDetails . \ ") is up since " . $HostVal->"since" . ".\n" . \ - "It was down for " . $Count . " checks since " . ($Metric->"since") . "."); + "It was down for " . $CountDown . " checks since " . ($Metric->"since") . "."); :if ([ :typeof ($HostInfo->"up-hook") ] = "str") do={ :set Message ($Message . "\n\n" . [ $NetwatchNotifyHook $Name $Type "up" \ ($HostInfo->"up-hook") ]); @@ -124,10 +124,10 @@ $ScriptLock $0; :set ($Metric->"count") ($Metric->"count" + 1); :set ($Metric->"parent") ($HostInfo->"parent"); :set ($Metric->"since") ($HostVal->"since"); - :local Count [ $IfThenElse ([ :tonum ($HostInfo->"count") ] > 0) ($HostInfo->"count") 5 ]; + :local CountDown [ $IfThenElse ([ :tonum ($HostInfo->"count") ] > 0) ($HostInfo->"count") 5 ]; :local Parent ($HostInfo->"parent"); :while ([ :len $Parent ] > 0) do={ - :set Count ($Count + 1); + :set CountDown ($CountDown + 1); :set Parent ($NetwatchNotify->$Parent->"parent"); } :set Parent ($HostInfo->"parent"); @@ -142,13 +142,13 @@ $ScriptLock $0; $LogPrintExit2 [ $IfThenElse ($HostInfo->"no-down-notification" != true) info debug ] $0 \ ("The " . $Type . " '" . $Name . "' (" . $HostDetails . ") is down for " . \ $Metric->"count" . " checks, " . [ $IfThenElse ($ParentNotified = false) [ $IfThenElse \ - ($Metric->"notified" = true) ("already notified.") ($Count - $Metric->"count" . \ + ($Metric->"notified" = true) ("already notified.") ($CountDown - $Metric->"count" . \ " to go.") ] ("parent " . $Type . " " . $Parent . " is down.") ]) false; - :if ((($Count * 2) - ($Metric->"count" * 3)) / 2 = 0 && \ + :if ((($CountDown * 2) - ($Metric->"count" * 3)) / 2 = 0 && \ [ :typeof ($HostInfo->"pre-down-hook") ] = "str") do={ $NetwatchNotifyHook $Name $Type "pre-down" ($HostInfo->"pre-down-hook"); } - :if ($ParentNotified = false && $Metric->"count" >= $Count && \ + :if ($ParentNotified = false && $Metric->"count" >= $CountDown && \ $Metric->"notified" != true) do={ :local Message ("The " . $Type . " '" . $Name . "' (" . $HostDetails . \ ") is down since " . $HostVal->"since" . "."); -- cgit v1.2.3-54-g00ecf From 6f772e92a616acb15bdef8ab7b7bfdb9d002bfeb Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 7 Sep 2022 21:54:57 +0200 Subject: netwatch-notify: rename array element --- netwatch-notify | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/netwatch-notify b/netwatch-notify index 994a8d1..0451823 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -69,7 +69,7 @@ $ScriptLock $0; :if ($HostInfo->"notify" = true && $HostInfo->"disabled" != true) do={ :local Name [ $EitherOr ($HostInfo->"name") ($HostVal->"name") ]; - :local Metric { "count"=0; "notified"=false }; + :local Metric { "count-down"=0; "notified"=false }; :if ([ :typeof ($NetwatchNotify->$Name) ] = "array") do={ :set $Metric ($NetwatchNotify->$Name); } @@ -98,11 +98,11 @@ $ScriptLock $0; } :if ($HostVal->"status" = "up") do={ - :local CountDown ($Metric->"count"); + :local CountDown ($Metric->"count-down"); :if ($CountDown > 0) do={ $LogPrintExit2 info $0 \ ("The " . $Type . " '" . $Name . "' (" . $HostDetails . ") is up.") false; - :set ($Metric->"count") 0; + :set ($Metric->"count-down") 0; } :if ($Metric->"notified" = true) do={ :local Message ("The " . $Type . " '" . $Name . "' (" . $HostDetails . \ @@ -121,10 +121,10 @@ $ScriptLock $0; :set ($Metric->"parent") ($HostInfo->"parent"); :set ($Metric->"since"); } else={ - :set ($Metric->"count") ($Metric->"count" + 1); + :set ($Metric->"count-down") ($Metric->"count-down" + 1); :set ($Metric->"parent") ($HostInfo->"parent"); :set ($Metric->"since") ($HostVal->"since"); - :local CountDown [ $IfThenElse ([ :tonum ($HostInfo->"count") ] > 0) ($HostInfo->"count") 5 ]; + :local CountDown [ $IfThenElse ([ :tonum ($HostInfo->"count-down") ] > 0) ($HostInfo->"count-down") 5 ]; :local Parent ($HostInfo->"parent"); :while ([ :len $Parent ] > 0) do={ :set CountDown ($CountDown + 1); @@ -141,14 +141,14 @@ $ScriptLock $0; } $LogPrintExit2 [ $IfThenElse ($HostInfo->"no-down-notification" != true) info debug ] $0 \ ("The " . $Type . " '" . $Name . "' (" . $HostDetails . ") is down for " . \ - $Metric->"count" . " checks, " . [ $IfThenElse ($ParentNotified = false) [ $IfThenElse \ - ($Metric->"notified" = true) ("already notified.") ($CountDown - $Metric->"count" . \ + $Metric->"count-down" . " checks, " . [ $IfThenElse ($ParentNotified = false) [ $IfThenElse \ + ($Metric->"notified" = true) ("already notified.") ($CountDown - $Metric->"count-down" . \ " to go.") ] ("parent " . $Type . " " . $Parent . " is down.") ]) false; - :if ((($CountDown * 2) - ($Metric->"count" * 3)) / 2 = 0 && \ + :if ((($CountDown * 2) - ($Metric->"count-down" * 3)) / 2 = 0 && \ [ :typeof ($HostInfo->"pre-down-hook") ] = "str") do={ $NetwatchNotifyHook $Name $Type "pre-down" ($HostInfo->"pre-down-hook"); } - :if ($ParentNotified = false && $Metric->"count" >= $CountDown && \ + :if ($ParentNotified = false && $Metric->"count-down" >= $CountDown && \ $Metric->"notified" != true) do={ :local Message ("The " . $Type . " '" . $Name . "' (" . $HostDetails . \ ") is down since " . $HostVal->"since" . "."); @@ -166,7 +166,7 @@ $ScriptLock $0; } } :set ($NetwatchNotify->$Name) { - "count"=($Metric->"count"); + "count-down"=($Metric->"count-down"); "notified"=($Metric->"notified"); "parent"=($Metric->"parent"); "resolve-failed"=($Metric->"resolve-failed"); -- cgit v1.2.3-54-g00ecf From a6645b3e75d55ad0028f349a8c4de5618e77beb7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 7 Sep 2022 22:02:46 +0200 Subject: netwatch-notify: add new array element to count up-checks --- netwatch-notify | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/netwatch-notify b/netwatch-notify index 0451823..dbf6e10 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -69,7 +69,7 @@ $ScriptLock $0; :if ($HostInfo->"notify" = true && $HostInfo->"disabled" != true) do={ :local Name [ $EitherOr ($HostInfo->"name") ($HostVal->"name") ]; - :local Metric { "count-down"=0; "notified"=false }; + :local Metric { "count-down"=0; "count-up"=0; "notified"=false }; :if ([ :typeof ($NetwatchNotify->$Name) ] = "array") do={ :set $Metric ($NetwatchNotify->$Name); } @@ -104,6 +104,7 @@ $ScriptLock $0; ("The " . $Type . " '" . $Name . "' (" . $HostDetails . ") is up.") false; :set ($Metric->"count-down") 0; } + :set ($Metric->"count-up") ($Metric->"count-up" + 1); :if ($Metric->"notified" = true) do={ :local Message ("The " . $Type . " '" . $Name . "' (" . $HostDetails . \ ") is up since " . $HostVal->"since" . ".\n" . \ @@ -122,6 +123,7 @@ $ScriptLock $0; :set ($Metric->"since"); } else={ :set ($Metric->"count-down") ($Metric->"count-down" + 1); + :set ($Metric->"count-up") 0; :set ($Metric->"parent") ($HostInfo->"parent"); :set ($Metric->"since") ($HostVal->"since"); :local CountDown [ $IfThenElse ([ :tonum ($HostInfo->"count-down") ] > 0) ($HostInfo->"count-down") 5 ]; @@ -167,6 +169,7 @@ $ScriptLock $0; } :set ($NetwatchNotify->$Name) { "count-down"=($Metric->"count-down"); + "count-up"=($Metric->"count-up"); "notified"=($Metric->"notified"); "parent"=($Metric->"parent"); "resolve-failed"=($Metric->"resolve-failed"); -- cgit v1.2.3-54-g00ecf From 5aff4019fe00f9c5781efb0cd1a37863b8eacab5 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 7 Sep 2022 22:16:11 +0200 Subject: 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. --- netwatch-notify | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/netwatch-notify b/netwatch-notify index dbf6e10..1d285de 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -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={ -- cgit v1.2.3-54-g00ecf