netwatch-notify: rename parameter: hostname -> name

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.
This commit is contained in:
Christian Hesse 2022-07-05 13:23:34 +02:00
parent 5a02c32d7d
commit 19103cd345
7 changed files with 23 additions and 21 deletions

View file

@ -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`.

View file

@ -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
--------

View file

@ -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";

View file

@ -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.

View file

@ -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=\" ]; };";
};

View file

@ -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;

View file

@ -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;
}
}