From 6c14412aa936d24a7a6c124b390bbd95fdc66cd7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 17 Nov 2020 15:03:01 +0100 Subject: netwatch-notify: implemented simple dependency model --- netwatch-notify | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'netwatch-notify') diff --git a/netwatch-notify b/netwatch-notify index 6c2a18c..2462e9b 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -48,8 +48,12 @@ :set ($Metric->"since") ($HostVal->"since"); $LogPrintExit info ("Host " . $HostName . " (" . $HostVal->"host" . ") is down for " . \ $Metric->"count" . " checks.") false; - :if ($Metric->"count" >= [ $IfThenElse ([ :typeof ($HostInfo->"count") ] != "nothing") ($HostInfo->"count") 5 ] && \ - $Metric->"notified" != true) do={ + :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={ + :set Count ($Count + 1); + } + :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" . "."); :set ($Metric->"notified") true; -- cgit v1.2.3-54-g00ecf From d5125b816aeef0f86e48bdf5dbd1dccfe0164c9f Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 17 Nov 2020 15:14:27 +0100 Subject: netwatch-notify: be more verbose in logs --- netwatch-notify | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'netwatch-notify') diff --git a/netwatch-notify b/netwatch-notify index 2462e9b..4c3586c 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -46,13 +46,15 @@ } else={ :set ($Metric->"count") ($Metric->"count" + 1); :set ($Metric->"since") ($HostVal->"since"); - $LogPrintExit info ("Host " . $HostName . " (" . $HostVal->"host" . ") is down for " . \ - $Metric->"count" . " checks.") false; :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={ :set Count ($Count + 1); } + $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; :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" . "."); -- cgit v1.2.3-54-g00ecf 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(-) (limited to 'netwatch-notify') 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 From 23923619dd0d92e4af65060e7b51b058fc1842aa Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 17 Nov 2020 22:02:41 +0100 Subject: netwatch-notify: increase count for every parent in chain --- doc/netwatch-notify.md | 3 ++- netwatch-notify | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'netwatch-notify') diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md index 66c5c75..11371ff 100644 --- a/doc/netwatch-notify.md +++ b/doc/netwatch-notify.md @@ -46,7 +46,8 @@ suppress notification if the parent host is down: / tool netwatch add comment="notify, hostname=gateway" host=93.184.216.1; / tool netwatch add comment="notify, hostname=example.com, parent=gateway" host=93.184.216.34; -Note that a configured parent increases the check count threshould by one. +Note that every configured parent in a chain increases the check count +threshould by one. Also notification settings are required for e-mail and telegram. diff --git a/netwatch-notify b/netwatch-notify index 1cfd4a6..9a12c5a 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -50,9 +50,11 @@ :set ($Metric->"since") ($HostVal->"since"); :local Count [ $IfThenElse ([ :tonum ($HostInfo->"count") ] > 0) ($HostInfo->"count") 5 ]; :local Parent ($HostInfo->"parent"); - :if ([ :len $Parent ] > 0) do={ + :while ([ :len $Parent ] > 0) do={ :set Count ($Count + 1); + :set Parent ($NetwatchNotify->$Parent->"parent"); } + :set Parent ($HostInfo->"parent"); :local ParentNotified false; :while ($ParentNotified = false && [ :len $Parent ] > 0) do={ :set ParentNotified [ $IfThenElse (($NetwatchNotify->$Parent->"notified") = true) true false ]; -- cgit v1.2.3-54-g00ecf