aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2020-11-17 15:03:01 +0100
committerGravatar Christian Hesse <mail@eworm.de>2020-11-17 22:28:05 +0100
commit6c14412aa936d24a7a6c124b390bbd95fdc66cd7 (patch)
tree51c0efbaf96849c76d2eb57420040136d5ffb853
parente1d9b08b9af23a20b612e92b150aded8ee1b1b68 (diff)
netwatch-notify: implemented simple dependency model
-rw-r--r--doc/netwatch-notify.md13
-rw-r--r--netwatch-notify8
2 files changed, 17 insertions, 4 deletions
diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md
index 557ae88..66c5c75 100644
--- a/doc/netwatch-notify.md
+++ b/doc/netwatch-notify.md
@@ -8,8 +8,9 @@ Description
This script sends notifications about host UP and DOWN events. In comparison
to just netwatch (`/ tool netwatch`) and its `up-script` and `down-script`
-this script implements a simple state machine. Host down events are triggered
-only if the host is down for several checks to avoid false alerts.
+this script implements a simple state machine and dependency model. Host
+down events are triggered only if the host is down for several checks and
+optional parent host is not down to avoid false alerts.
Requirements and installation
-----------------------------
@@ -39,6 +40,14 @@ The count threshould (default is 5 checks) is configurable as well:
/ tool netwatch add comment="notify, hostname=example.com, count=10" host=104.18.144.11;
+If the host is behind another checked host add a dependency, this will
+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.
+
Also notification settings are required for e-mail and telegram.
---
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;