mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2024-05-11 05:55:19 +00:00
Merge branch 'netwatch-notify' into next
This commit is contained in:
@ -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)
|
||||
|
@ -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";
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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") };
|
||||
}
|
||||
|
Reference in New Issue
Block a user