aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/netwatch-notify.md21
-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-notify27
6 files changed, 50 insertions, 5 deletions
diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md
index 627070a..ff1eae9 100644
--- a/doc/netwatch-notify.md
+++ b/doc/netwatch-notify.md
@@ -52,8 +52,29 @@ suppress notification if the parent host is down:
Note that every configured parent in a chain increases the check count
threshould by one.
+The host address can be updated dynamically. Give extra parameter `resolve`
+with a resolvable name:
+
+ / tool netwatch add comment="notify, hostname=example.com, resolve=example.com";
+
+But be warned: Dynamic updates will probably cause issues if the name has
+more than one record in dns - a high rate of configuration changes (and flash
+writes) at least.
+
Also notification settings are required for e-mail and telegram.
+Tips & Tricks
+-------------
+
+### One of several hosts
+
+Sometimes it is sufficient if one of a number of hosts is available. You can
+make `netwatch-notify` check for that by adding several items with same
+`hostname`. Note that `count` has to be multiplied to keep the actual time.
+
+ / tool netwatch add comment="notify, hostname=service, count=10" host=10.0.0.10;
+ / tool netwatch add comment="notify, hostname=service, count=10" host=10.0.0.20;
+
---
[◀ Go back to main README](../README.md)
[▲ Go back to top](#top)
diff --git a/global-config b/global-config
index 25d0496..77f41f6 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 49;
+:global GlobalConfigVersion 50;
# This is used for DNS and backup file.
:global Domain "example.com";
diff --git a/global-config-overlay b/global-config-overlay
index 7057765..ac5e396 100644
--- a/global-config-overlay
+++ b/global-config-overlay
@@ -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'!
# Comment or remove to disable news and change notifications.
-:global GlobalConfigVersion 49;
+:global GlobalConfigVersion 50;
# Copy configuration from global-config here and modify it.
diff --git a/global-config.changes b/global-config.changes
index 61850dd..74af117 100644
--- a/global-config.changes
+++ b/global-config.changes
@@ -53,6 +53,7 @@
47="Removed obsolete intermediate certificate 'Let's Encrypt Authority X3' from store.";
48="Added support for overriding e-mail and Telegram settings for every script.";
49="Dropped '\$EmailBackupTo' & '\$EmailBackupCc' from configuration, use settings override if required.";
+ 50="Added support for dynamic address update in 'netwatch-notify'.";
};
# Migration steps to be applied on script updates
diff --git a/global-functions b/global-functions
index 0c90ad8..2626c36 100644
--- a/global-functions
+++ b/global-functions
@@ -8,7 +8,7 @@
# https://git.eworm.de/cgit/routeros-scripts/about/
# expected configuration version
-:global ExpectedConfigVersion 49;
+:global ExpectedConfigVersion 50;
# global variables not to be changed by user
:global GlobalFunctionsReady false;
diff --git a/netwatch-notify b/netwatch-notify
index 5600857..27afd70 100644
--- a/netwatch-notify
+++ b/netwatch-notify
@@ -12,6 +12,7 @@
:global NetwatchNotify;
+:global DNSIsResolving;
:global IfThenElse;
:global LogPrintExit2;
:global ParseKeyValueStore;
@@ -33,10 +34,31 @@
:set $Metric ($NetwatchNotify->$HostName);
}
+ :if ([ :typeof ($HostInfo->"resolve") ] = "str" && [ $DNSIsResolving ] = true) do={
+ :do {
+ :local Resolve [ :resolve ($HostInfo->"resolve") ];
+ :if ($Resolve != $HostVal->"host") do={
+ $LogPrintExit2 info $0 ("Name '" . $HostInfo->"resolve" . [ $IfThenElse ($HostInfo->"resolve" != \
+ $HostInfo->"hostname") ("' for host '" . $HostInfo->"hostname") "" ] . \
+ "' resolves to different address " . $Resolve . ", updating.") false;
+ / tool netwatch set host=$Resolve $Host;
+ :set ($Metric->"resolve-failed") false;
+ }
+ } on-error={
+ :if ($Metric->"resolve-failed" != true) do={
+ $LogPrintExit2 warning $0 ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse ($HostInfo->"resolve" != \
+ $HostInfo->"hostname") ("' for host '" . $HostInfo->"hostname") "" ] . "' failed.") false;
+ :set ($Metric->"resolve-failed") true;
+ }
+ }
+ }
+
:if ($HostVal->"status" = "up") do={
- $LogPrintExit2 debug $0 ("Host " . $HostName . " (" . $HostVal->"host" . ") is up.") false;
:local Count ($Metric->"count");
- :set ($Metric->"count") 0;
+ :if ($Count > 0) do={
+ $LogPrintExit2 info $0 ("Host " . $HostName . " (" . $HostVal->"host" . ") is up.") false;
+ :set ($Metric->"count") 0;
+ }
:if ($Metric->"notified" = true) do={
$SendNotification2 ({ origin=$0; \
subject=([ $SymbolForNotification "white-heavy-check-mark" ] . "Netwatch Notify: " . $HostName . " up"); \
@@ -95,5 +117,6 @@
"count"=($Metric->"count");
"notified"=($Metric->"notified");
"parent"=($Metric->"parent");
+ "resolve-failed"=($Metric->"resolve-failed");
"since"=($Metric->"since") };
}