aboutsummaryrefslogtreecommitdiffstats
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
parente1d9b08b9af23a20b612e92b150aded8ee1b1b68 (diff)
parent62ef70e5dd0da2eee841359b8aa0305088880e58 (diff)
Merge branch 'netwatch-notify'
-rw-r--r--doc/netwatch-notify.md14
-rw-r--r--global-config2
-rw-r--r--global-config-overlay2
-rw-r--r--global-config.changes1
-rw-r--r--global-functions2
-rw-r--r--netwatch-notify24
6 files changed, 37 insertions, 8 deletions
diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md
index 557ae88..11371ff 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,15 @@ 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 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/global-config b/global-config
index 9bbbc29..591bdda 100644
--- a/global-config
+++ b/global-config
@@ -8,7 +8,7 @@
# Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'!
-:global GlobalConfigVersion 36;
+:global GlobalConfigVersion 37;
# This is used for DNS and backup file.
:global Domain "example.com";
diff --git a/global-config-overlay b/global-config-overlay
index 2777519..a0c6361 100644
--- a/global-config-overlay
+++ b/global-config-overlay
@@ -9,7 +9,7 @@
# Make sure all configuration properties are up to date and this
# value is in sync with value in script 'global-functions'!
# Comment or remove to disable change notifications.
-:global GlobalConfigVersion 36;
+:global GlobalConfigVersion 37;
# Copy configuration from global-config here and modify it.
diff --git a/global-config.changes b/global-config.changes
index 85529eb..5c400a5 100644
--- a/global-config.changes
+++ b/global-config.changes
@@ -40,4 +40,5 @@
34="Introduced script 'ospf-to-leds' to visualize OSPF instance state via LEDs.";
35="Implemented visual feedback for 'mode-button' with configurable LED.";
36="Added support for installing updates automatically if seen in neighbor list.";
+ 37="Implemented simple dependency model in 'netwatch-notify'.";
};
diff --git a/global-functions b/global-functions
index a4a3630..b0b27c2 100644
--- a/global-functions
+++ b/global-functions
@@ -8,7 +8,7 @@
# https://git.eworm.de/cgit/routeros-scripts/about/
# expected configuration version
-:global ExpectedConfigVersion 36;
+:global ExpectedConfigVersion 37;
# global variables not to be changed by user
:global GlobalFunctionsReady false;
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") };
}