diff options
author | Christian Hesse <mail@eworm.de> | 2022-02-07 21:46:10 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2022-02-10 09:14:49 +0100 |
commit | 0c607a8f9ce7ed9d33df775f03b0292787d9326f (patch) | |
tree | d6f9db2538641f564f359340d144415de68dff21 /netwatch-notify | |
parent | c03da561cdf7cf6f47de79772749ef459f6ee495 (diff) |
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 0b46c508dc8f76955dd528900882b54c07b62ef3)
Diffstat (limited to 'netwatch-notify')
-rw-r--r-- | netwatch-notify | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/netwatch-notify b/netwatch-notify index e82cea6..34a9e8f 100644 --- a/netwatch-notify +++ b/netwatch-notify @@ -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; + } } } } |