aboutsummaryrefslogtreecommitdiffstats
path: root/netwatch-notify
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-11-17 22:45:35 +0100
committerGravatar Christian Hesse <mail@eworm.de>2020-11-17 22:45:35 +0100
commit34a0d4ab853ed31220b73b4ca2470778873f8108 (patch)
treeb747d87ee2d1ce63386eea39fcf2d839e14b0503 /netwatch-notify
parente1d9b08b9af23a20b612e92b150aded8ee1b1b68 (diff)
parent62ef70e5dd0da2eee841359b8aa0305088880e58 (diff)
Merge branch 'netwatch-notify'
Diffstat (limited to 'netwatch-notify')
-rw-r--r--netwatch-notify24
1 files changed, 21 insertions, 3 deletions
diff --git a/netwatch-notify b/netwatch-notify
index 6c2a18c..9a12c5a 100644
--- a/netwatch-notify
+++ b/netwatch-notify
@@ -42,14 +42,31 @@
}
}
: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 Parent ($HostInfo->"parent");
+ :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 ];
+ :if ($ParentNotified = false) do={
+ :set Parent ($NetwatchNotify->$Parent->"parent");
+ }
+ }
$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={
+ $Metric->"count" . " checks, " . [ $IfThenElse ($ParentNotified = false) [ $IfThenElse \
+ ($Metric->"notified" = true) ("already notified.") ($Count - $Metric->"count" . " to go.") ] \
+ ("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" . ".");
:set ($Metric->"notified") true;
@@ -62,5 +79,6 @@
:set ($NetwatchNotify->$HostName) {
"count"=($Metric->"count");
"notified"=($Metric->"notified");
+ "parent"=($Metric->"parent");
"since"=($Metric->"since") };
}