mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
netwatch-notify: (mis-)use firewall address-list for lookup...
... and drop the racy code querying dns cache. 😁
This commit is contained in:
parent
20d1ad17d7
commit
50a6914907
|
@ -84,8 +84,8 @@ with a resolvable name:
|
||||||
/tool/netwatch/add comment="notify, name=example.com, resolve=example.com";
|
/tool/netwatch/add comment="notify, name=example.com, resolve=example.com";
|
||||||
|
|
||||||
This supports multiple A or AAAA records for a name just fine, even a CNAME
|
This supports multiple A or AAAA records for a name just fine, even a CNAME
|
||||||
to those. But be warned: CNAME chains to multiple records will cause a high
|
to those. An update happens only if no more record with the configured host
|
||||||
rate of configuration changes (and flash writes)!
|
address is found.
|
||||||
|
|
||||||
### No notification on host down
|
### No notification on host down
|
||||||
|
|
||||||
|
|
|
@ -56,21 +56,15 @@
|
||||||
:local Name [ :tostr $1 ];
|
:local Name [ :tostr $1 ];
|
||||||
:local Expected [ :tostr $2 ];
|
:local Expected [ :tostr $2 ];
|
||||||
|
|
||||||
:delay 100ms;
|
:global GetRandom20CharAlNum;
|
||||||
|
|
||||||
:if ([ :len [ /ip/dns/cache/find where name=$Name data=$Expected ] ] > 0) do={
|
:local FwAddrList ($0 . "-" . [ $GetRandom20CharAlNum ]);
|
||||||
|
/ip/firewall/address-list/add address=$Name list=$FwAddrList dynamic=yes timeout=1s;
|
||||||
|
:delay 20ms;
|
||||||
|
:if ([ :len [ /ip/firewall/address-list/find where list=$FwAddrList address=$Expected ] ] > 0) do={
|
||||||
:return true;
|
:return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
:local Cname [ /ip/dns/cache/find where name=$Name type="CNAME" ];
|
|
||||||
:if ([ :len $Cname ] > 0) do={
|
|
||||||
:set Cname [ /ip/dns/cache/get $Cname data ];
|
|
||||||
:set Cname [ :pick $Cname 0 ([ :len $Cname ] - 1) ];
|
|
||||||
:if ([ :len [ /ip/dns/cache/find where name=$Cname data=$Expected ] ] > 0) do={
|
|
||||||
:return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
:return false;
|
:return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue