mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00: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.
This commit is contained in:
parent
c6e581d4f9
commit
0b46c508dc
1 changed files with 17 additions and 15 deletions
|
@ -66,21 +66,23 @@ $ScriptLock $0;
|
||||||
:set $Metric ($NetwatchNotify->$HostName);
|
:set $Metric ($NetwatchNotify->$HostName);
|
||||||
}
|
}
|
||||||
|
|
||||||
:if ([ :typeof ($HostInfo->"resolve") ] = "str" && [ $DNSIsResolving ] = true) do={
|
:if ([ :typeof ($HostInfo->"resolve") ] = "str") do={
|
||||||
:do {
|
:if ([ $DNSIsResolving ] = true) do={
|
||||||
:local Resolve [ :resolve ($HostInfo->"resolve") ];
|
:do {
|
||||||
:if ($Resolve != $HostVal->"host") do={
|
:local Resolve [ :resolve ($HostInfo->"resolve") ];
|
||||||
$LogPrintExit2 info $0 ("Name '" . $HostInfo->"resolve" . [ $IfThenElse ($HostInfo->"resolve" != \
|
:if ($Resolve != $HostVal->"host") do={
|
||||||
$HostInfo->"hostname") ("' for host '" . $HostInfo->"hostname") "" ] . \
|
$LogPrintExit2 info $0 ("Name '" . $HostInfo->"resolve" . [ $IfThenElse ($HostInfo->"resolve" != \
|
||||||
"' resolves to different address " . $Resolve . ", updating.") false;
|
$HostInfo->"hostname") ("' for host '" . $HostInfo->"hostname") "" ] . \
|
||||||
/ tool netwatch set host=$Resolve $Host;
|
"' resolves to different address " . $Resolve . ", updating.") false;
|
||||||
:set ($Metric->"resolve-failed") false;
|
/ tool netwatch set host=$Resolve $Host;
|
||||||
}
|
:set ($Metric->"resolve-failed") false;
|
||||||
} on-error={
|
}
|
||||||
:if ($Metric->"resolve-failed" != true) do={
|
} on-error={
|
||||||
$LogPrintExit2 warning $0 ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse ($HostInfo->"resolve" != \
|
:if ($Metric->"resolve-failed" != true) do={
|
||||||
$HostInfo->"hostname") ("' for host '" . $HostInfo->"hostname") "" ] . "' failed.") false;
|
$LogPrintExit2 warning $0 ("Resolving name '" . $HostInfo->"resolve" . [ $IfThenElse ($HostInfo->"resolve" != \
|
||||||
:set ($Metric->"resolve-failed") true;
|
$HostInfo->"hostname") ("' for host '" . $HostInfo->"hostname") "" ] . "' failed.") false;
|
||||||
|
:set ($Metric->"resolve-failed") true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue