aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2021-05-06 12:55:05 +0200
committerGravatar Christian Hesse <mail@eworm.de>2021-05-06 15:11:05 +0200
commitcfb31e844c39089046de1fc7021d5dedef14c145 (patch)
tree12f421b5e8d2df7345040dc3b108de4149cac427
parent9d19313eee7e647a7f094aa01f40f179bfd23b0b (diff)
netwatch-notify: support dynamic address updatechange-50
-rw-r--r--doc/netwatch-notify.md9
-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-notify15
6 files changed, 28 insertions, 3 deletions
diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md
index a3d8ccd..ff1eae9 100644
--- a/doc/netwatch-notify.md
+++ b/doc/netwatch-notify.md
@@ -52,6 +52,15 @@ 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
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 9cb99bb..50441a9 100644
--- a/netwatch-notify
+++ b/netwatch-notify
@@ -33,6 +33,21 @@
:set $Metric ($NetwatchNotify->$HostName);
}
+ :if ([ :typeof ($HostInfo->"resolve") ] = "str") 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;
+ }
+ } on-error={
+ $LogPrintExit2 warning $0 ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse ($HostInfo->"resolve" != \
+ $HostInfo->"hostname") ("' for host '" . $HostInfo->"hostname") "" ] . "' failed.") false;
+ }
+ }
+
:if ($HostVal->"status" = "up") do={
:local Count ($Metric->"count");
:if ($Count > 0) do={