diff options
author | Christian Hesse <mail@eworm.de> | 2022-07-05 13:23:34 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2022-07-06 11:37:02 +0200 |
commit | 19103cd3451a9a5a6be6faa8c2745754ddc40606 (patch) | |
tree | 2c496efcf121a216690040e94fe55cad05c01ea5 | |
parent | 5a02c32d7d0c5d8b0951898e040b7918ff1b560a (diff) |
netwatch-notify: rename parameter: hostname -> namechange-82
Starting with RouterOS 7.4 the netwatch tool has been extended, it can
now do tcp and http probes. Rename the parameter for reasonable naming
with services.
-rw-r--r-- | doc/netwatch-dns.md | 2 | ||||
-rw-r--r-- | doc/netwatch-notify.md | 28 | ||||
-rw-r--r-- | global-config | 2 | ||||
-rw-r--r-- | global-config-overlay | 2 | ||||
-rw-r--r-- | global-config.changes | 2 | ||||
-rw-r--r-- | global-functions | 2 | ||||
-rw-r--r-- | netwatch-notify | 6 |
7 files changed, 23 insertions, 21 deletions
diff --git a/doc/netwatch-dns.md b/doc/netwatch-dns.md index 6f30225..8e897d1 100644 --- a/doc/netwatch-dns.md +++ b/doc/netwatch-dns.md @@ -57,7 +57,7 @@ Tips & Tricks Netwatch entries can be created to work with both - this script and [netwatch-notify](netwatch-notify.md). Just give options for both: - /tool/netwatch/add comment="doh, notify, hostname=cloudflare-dns" host=1.1.1.1; + /tool/netwatch/add comment="doh, notify, name=cloudflare-dns" host=1.1.1.1; Also this allows to update host address, see option `resolve`. diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md index 85bfb73..1352495 100644 --- a/doc/netwatch-notify.md +++ b/doc/netwatch-notify.md @@ -36,7 +36,7 @@ Configuration The hosts to be checked have to be added to netwatch with specific comment: - /tool/netwatch/add comment="notify, hostname=example.com" host=[ :resolve "example.com" ]; + /tool/netwatch/add comment="notify, name=example.com" host=[ :resolve "example.com" ]; ### Hooks @@ -44,7 +44,7 @@ It is possible to run an up hook command (`up-hook`) or down hook command (`down-hook`) when a notification is triggered. This has to be added in comment, note that some characters need extra escaping: - /tool/netwatch/add comment=("notify, hostname=device, down-hook=/interface/ethernet \\{ disable \\\"en2\\\"; enable \\\"en2\\\"; \\}") host=10.0.0.20; + /tool/netwatch/add comment=("notify, name=device, down-hook=/interface/ethernet \\{ disable \\\"en2\\\"; enable \\\"en2\\\"; \\}") host=10.0.0.20; Also there is a `pre-down-hook` that fires at two thirds of failed checks required for the notification. The idea is to fix the issue before a @@ -54,15 +54,15 @@ notification is sent. 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; + /tool/netwatch/add comment="notify, name=example.com, count=10" host=104.18.144.11; ### Parents & dependencies 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; + /tool/netwatch/add comment="notify, name=gateway" host=93.184.216.1; + /tool/netwatch/add comment="notify, name=example.com, parent=gateway" host=93.184.216.34; Note that every configured parent in a chain increases the check count threshould by one. @@ -72,7 +72,7 @@ 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"; + /tool/netwatch/add comment="notify, name=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 @@ -84,7 +84,7 @@ Also suppressing the notification on host down is possible with parameter `no-down-notification`. This may be desired for devices that are usually powered off, but accessibility is of interest. - /tool/netwatch/add comment="notify, hostname=printer, no-down-notification" host=10.0.0.30; + /tool/netwatch/add comment="notify, name=printer, no-down-notification" host=10.0.0.30; Go and get your coffee ☕️ before sending the print job. @@ -99,10 +99,10 @@ Tips & Tricks 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. +`name`. 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; + /tool/netwatch/add comment="notify, name=service, count=10" host=10.0.0.10; + /tool/netwatch/add comment="notify, name=service, count=10" host=10.0.0.20; ### Checking internet connectivity @@ -112,11 +112,11 @@ check `1.1.1.1` (Cloudflare DNS), `9.9.9.9` (Quad-nine DNS), `8.8.8.8` (Google DNS) or any other reliable address that indicates internet connectivity. - /tool/netwatch/add comment="notify, hostname=internet" host=1.1.1.1; + /tool/netwatch/add comment="notify, name=internet" host=1.1.1.1; A target like this suits well to be parent for other checks. - /tool/netwatch/add comment="notify, hostname=example.com, parent=internet" host=93.184.216.34; + /tool/netwatch/add comment="notify, name=example.com, parent=internet" host=93.184.216.34; ### Checking specific ISP @@ -130,7 +130,7 @@ Create a route and firewall mangle rule. Finally monitor the address with `netwatch-notify`. - /tool/netwatch/add comment="notify, hostname=quad-one via isp1" host=1.0.0.1; + /tool/netwatch/add comment="notify, name=quad-one via isp1" host=1.0.0.1; Note that *all* traffic to the given address is routed that way. In case of link failure this address is not available, so use something reliable but @@ -142,7 +142,7 @@ non-essential. In this example the address `1.0.0.1` is used, the same service Netwatch entries can be created to work with both - this script and [netwatch-dns](netwatch-dns.md). Just give options for both: - /tool/netwatch/add comment="doh, notify, hostname=cloudflare-dns" host=1.1.1.1; + /tool/netwatch/add comment="doh, notify, name=cloudflare-dns" host=1.1.1.1; See also -------- diff --git a/global-config b/global-config index b1f4770..d36e63b 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 81; +:global GlobalConfigVersion 82; # This is used for DNS and backup file. :global Domain "example.com"; diff --git a/global-config-overlay b/global-config-overlay index eaa43f6..5af0e09 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 81; +:global GlobalConfigVersion 82; # Copy configuration from global-config here and modify it. diff --git a/global-config.changes b/global-config.changes index 04f88e7..1a72527 100644 --- a/global-config.changes +++ b/global-config.changes @@ -90,6 +90,7 @@ 79="Introduced new script 'backup-partition' to save configuration to fallback partition."; 80="The 'routeros-v7' branch will now freeze, and vanish any time in future. You already switched to 'main' branch, well done!"; 81="Dropped script 'rotate-ntp', as the limitation does no longer exist."; + 82="Renamed the comment parameter 'hostname' to just 'name' for 'netwatch-notify'."; }; # Migration steps to be applied on script updates @@ -103,4 +104,5 @@ 67=":global ScriptInstallUpdate; :global CharacterReplace; :foreach Script in=[ /system/script/find where name~\"^global-functions.d/\" ] do={ /system/script/set name=[ \$CharacterReplace [ /system/script/get \$Script name ] \"global-functions.d/\" \"mod/\" ] \$Script; }; \$ScriptInstallUpdate;"; 73=":global ScriptInstallUpdate; :global CharacterReplace; :foreach Old,New in={ \"cloud-backup\"=\"backup-cloud\"; \"email-backup\"=\"backup-email\"; \"upload-backup\"=\"backup-upload\" } do={ /system/script/set name=\$New [ find where name=\$Old ]; :foreach Scheduler in=[ /system/scheduler/find where on-event~\$Old ] do={ /system/scheduler/set \$Scheduler name=[ \$CharacterReplace [ get \$Scheduler name ] \$Old \$New ] on-event=[ \$CharacterReplace [ get \$Scheduler on-event ] \$Old \$New ]; }; }; \$ScriptInstallUpdate;"; 81=":global NtpPool; :if ([ :len [ /system/script/find where name=\"rotate-ntp\" ] ] > 0) do={ /system/script/remove [ find where name=\"rotate-ntp\" ]; /system/scheduler/remove [ find where name=\"rotate-ntp\" ]; /system/ntp/client/set servers=\$NtpPool; };"; + 82=":global CharacterReplace; :foreach Netwatch in=[ /tool/netwatch/find where comment~\"notify\" !disabled ] do={ /tool/netwatch/set \$Netwatch comment=[ \$CharacterReplace [ get \$Netwatch comment ] \"hostname=\" \"name=\" ]; };"; }; diff --git a/global-functions b/global-functions index daa6526..bab2716 100644 --- a/global-functions +++ b/global-functions @@ -10,7 +10,7 @@ :local 0 "global-functions"; # expected configuration version -:global ExpectedConfigVersion 81; +:global ExpectedConfigVersion 82; # global variables not to be changed by user :global GlobalFunctionsReady false; diff --git a/netwatch-notify b/netwatch-notify index d9b8cf0..e1c8e43 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -59,7 +59,7 @@ $ScriptLock $0; :local HostInfo [ $ParseKeyValueStore ($HostVal->"comment") ]; :if ($HostInfo->"notify" = true && $HostInfo->"disabled" != true) do={ - :local HostName ($HostInfo->"hostname"); + :local HostName ($HostInfo->"name"); :local Metric { "count"=0; "notified"=false }; :if ([ :typeof ($NetwatchNotify->$HostName) ] = "array") do={ @@ -72,7 +72,7 @@ $ScriptLock $0; :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") "" ] . \ + $HostInfo->"name") ("' for host '" . $HostInfo->"name") "" ] . \ "' resolves to different address " . $Resolve . ", updating.") false; /tool/netwatch/set host=$Resolve $Host; :set ($Metric->"resolve-failed") false; @@ -80,7 +80,7 @@ $ScriptLock $0; } 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; + $HostInfo->"name") ("' for host '" . $HostInfo->"name") "" ] . "' failed.") false; :set ($Metric->"resolve-failed") true; } } |