mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-16 13:04:30 +02:00
netwatch-notify: nest conditions
The logic here was right, but RouterOS runs the checks simultaneously.
This caused delays even if no resolving was needed.
Nesting the checks fixes this.
(cherry picked from commit 0b46c508dc
)
This commit is contained in:
parent
c03da561cd
commit
0c607a8f9c
1 changed files with 17 additions and 15 deletions
|
@ -66,21 +66,23 @@ $ScriptLock $0;
|
|||
: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 ([ :typeof ($HostInfo->"resolve") ] = "str") do={
|
||||
:if ([ $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue