mirror of
https://github.com/nymurbd/MikroTik-scripts.git
synced 2025-08-02 17:24:36 +02:00
netwatch-notify: work around race condition
This used to crash every now and then with: > script;error script error: no such item (4) I guess this is caused by querying the dns cache just exactly when a record expires. The chance is maximized: The script is started by scheduler every minute, and the record's ttl is a multiple of a minute. Let's query records that are not about to expire immediately, and try again.
This commit is contained in:
parent
c2f5272f18
commit
93bed1b081
1 changed files with 12 additions and 8 deletions
|
@ -80,14 +80,18 @@ $ScriptLock $0;
|
|||
:do {
|
||||
:local Resolve [ :resolve ($HostInfo->"resolve") ];
|
||||
:if ($Resolve != $HostVal->"host" && \
|
||||
[ :len [ /ip/dns/cache/find where name=($HostInfo->"resolve") data=[ :tostr ($HostVal->"host") ] ] ] = 0) do={
|
||||
$LogPrintExit2 info $0 ("Name '" . $HostInfo->"resolve" . [ $IfThenElse \
|
||||
($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \
|
||||
$HostInfo->"name") "" ] . "' resolves to different address " . $Resolve . \
|
||||
", updating.") false;
|
||||
/tool/netwatch/set host=$Resolve $Host;
|
||||
:set ($Metric->"resolve-failcnt") 0;
|
||||
:set ($HostVal->"status") "unknown";
|
||||
[ :len [ /ip/dns/cache/find where name=($HostInfo->"resolve") data=[ :tostr ($HostVal->"host") ] ttl>0s ] ] = 0) do={
|
||||
:delay 1500ms;
|
||||
:resolve ($HostInfo->"resolve");
|
||||
:if ([ :len [ /ip/dns/cache/find where name=($HostInfo->"resolve") data=[ :tostr ($HostVal->"host") ] ] ] = 0) do={
|
||||
$LogPrintExit2 info $0 ("Name '" . $HostInfo->"resolve" . [ $IfThenElse \
|
||||
($HostInfo->"resolve" != $HostInfo->"name") ("' for " . $Type . " '" . \
|
||||
$HostInfo->"name") "" ] . "' resolves to different address " . $Resolve . \
|
||||
", updating.") false;
|
||||
/tool/netwatch/set host=$Resolve $Host;
|
||||
:set ($Metric->"resolve-failcnt") 0;
|
||||
:set ($HostVal->"status") "unknown";
|
||||
}
|
||||
}
|
||||
} on-error={
|
||||
:set ($Metric->"resolve-failcnt") ($Metric->"resolve-failcnt" + 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue