From e7855b4611f754fcde4f5adaff0e1a6006ddaaac Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 17 Nov 2020 21:37:23 +0100 Subject: netwatch-notify: support parents in a chain --- netwatch-notify | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/netwatch-notify b/netwatch-notify index 4c3586c..1cfd4a6 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -42,19 +42,28 @@ } } :set ($Metric->"notified") false; + :set ($Metric->"parent") ($HostInfo->"parent"); :set ($Metric->"since"); } else={ :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 ParentNotified [ $IfThenElse (($NetwatchNotify->($HostInfo->"parent")->"notified") = true) true false ]; - :if ([ :len ($HostInfo->"parent") ] > 0) do={ + :local Parent ($HostInfo->"parent"); + :if ([ :len $Parent ] > 0) do={ :set Count ($Count + 1); } + :local ParentNotified false; + :while ($ParentNotified = false && [ :len $Parent ] > 0) do={ + :set ParentNotified [ $IfThenElse (($NetwatchNotify->$Parent->"notified") = true) true false ]; + :if ($ParentNotified = false) do={ + :set Parent ($NetwatchNotify->$Parent->"parent"); + } + } $LogPrintExit info ("Host " . $HostName . " (" . $HostVal->"host" . ") is down for " . \ $Metric->"count" . " checks, " . [ $IfThenElse ($ParentNotified = false) [ $IfThenElse \ ($Metric->"notified" = true) ("already notified.") ($Count - $Metric->"count" . " to go.") ] \ - ("parent host " . $HostInfo->"parent" . " is down.") ]) false; + ("parent host " . $Parent . " is down.") ]) false; :if ($ParentNotified = false && $Metric->"count" >= $Count && $Metric->"notified" != true) do={ $SendNotification ([ $SymbolForNotification "cross-mark" ] . "Netwatch Notify: " . $HostName . " down") \ ("Host " . $HostName . " (" . $HostVal->"host" . ") is down since " . $HostVal->"since" . "."); @@ -68,5 +77,6 @@ :set ($NetwatchNotify->$HostName) { "count"=($Metric->"count"); "notified"=($Metric->"notified"); + "parent"=($Metric->"parent"); "since"=($Metric->"since") }; } -- cgit v1.2.3-54-g00ecf