aboutsummaryrefslogtreecommitdiffstats
path: root/netwatch-notify
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-11-17 21:37:23 +0100
committerGravatar Christian Hesse <mail@eworm.de>2020-11-17 22:28:05 +0100
commite7855b4611f754fcde4f5adaff0e1a6006ddaaac (patch)
tree5cd127c1fed0236a59484e9fbecd7e69aab89cf6 /netwatch-notify
parentd5125b816aeef0f86e48bdf5dbd1dccfe0164c9f (diff)
netwatch-notify: support parents in a chain
Diffstat (limited to 'netwatch-notify')
-rw-r--r--netwatch-notify16
1 files 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") };
}