From 41f7d1e4668a8ff1d72594e811df0b6c44d865ba Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 5 May 2021 08:28:58 +0200 Subject: doc/netwatch-notify: tips & tricks: one of several hosts --- doc/netwatch-notify.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md index 627070a..a3d8ccd 100644 --- a/doc/netwatch-notify.md +++ b/doc/netwatch-notify.md @@ -54,6 +54,18 @@ threshould by one. 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) -- cgit v1.2.3-70-g09d2 From 9d19313eee7e647a7f094aa01f40f179bfd23b0b Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 6 May 2021 14:50:45 +0200 Subject: netwatch-notify: log on host up... ... if logged on host down before. --- netwatch-notify | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netwatch-notify b/netwatch-notify index 5600857..9cb99bb 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -34,9 +34,11 @@ } :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"); \ -- cgit v1.2.3-70-g09d2 From cfb31e844c39089046de1fc7021d5dedef14c145 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 6 May 2021 12:55:05 +0200 Subject: netwatch-notify: support dynamic address update --- doc/netwatch-notify.md | 9 +++++++++ global-config | 2 +- global-config-overlay | 2 +- global-config.changes | 1 + global-functions | 2 +- netwatch-notify | 15 +++++++++++++++ 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={ -- cgit v1.2.3-70-g09d2 From 0b1bb0f2b2b388c3fb591e1872c18779bf034415 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 6 May 2021 15:10:33 +0200 Subject: netwatch-notify: attempt to update address with working resolver only --- netwatch-notify | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netwatch-notify b/netwatch-notify index 50441a9..3d0bd91 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -12,6 +12,7 @@ :global NetwatchNotify; +:global DNSIsResolving; :global IfThenElse; :global LogPrintExit2; :global ParseKeyValueStore; @@ -33,7 +34,7 @@ :set $Metric ($NetwatchNotify->$HostName); } - :if ([ :typeof ($HostInfo->"resolve") ] = "str") do={ + :if ([ :typeof ($HostInfo->"resolve") ] = "str" && [ $DNSIsResolving ] = true) do={ :do { :local Resolve [ :resolve ($HostInfo->"resolve") ]; :if ($Resolve != $HostVal->"host") do={ -- cgit v1.2.3-70-g09d2 From 96621e01cb6e0331fc9e2e4b90610fb7c210aab7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 6 May 2021 15:17:05 +0200 Subject: netwatch-notify: log failed resolve just once --- netwatch-notify | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/netwatch-notify b/netwatch-notify index 3d0bd91..27afd70 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -42,10 +42,14 @@ $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={ - $LogPrintExit2 warning $0 ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse ($HostInfo->"resolve" != \ - $HostInfo->"hostname") ("' for host '" . $HostInfo->"hostname") "" ] . "' failed.") false; + :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; + } } } @@ -113,5 +117,6 @@ "count"=($Metric->"count"); "notified"=($Metric->"notified"); "parent"=($Metric->"parent"); + "resolve-failed"=($Metric->"resolve-failed"); "since"=($Metric->"since") }; } -- cgit v1.2.3-70-g09d2