From 50a69149072be4f66cbd05362fef9ec68f293323 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Fri, 1 Mar 2024 12:09:29 +0100 Subject: netwatch-notify: (mis-)use firewall address-list for lookup... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... and drop the racy code querying dns cache. 😁 --- doc/netwatch-notify.md | 4 ++-- netwatch-notify.rsc | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/doc/netwatch-notify.md b/doc/netwatch-notify.md index a7cc2d6..e252d39 100644 --- a/doc/netwatch-notify.md +++ b/doc/netwatch-notify.md @@ -84,8 +84,8 @@ with a resolvable name: /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 -to those. But be warned: CNAME chains to multiple records will cause a high -rate of configuration changes (and flash writes)! +to those. An update happens only if no more record with the configured host +address is found. ### No notification on host down diff --git a/netwatch-notify.rsc b/netwatch-notify.rsc index cd4fc0d..6501ea9 100644 --- a/netwatch-notify.rsc +++ b/netwatch-notify.rsc @@ -56,21 +56,15 @@ :local Name [ :tostr $1 ]; :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; } - :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; } -- cgit v1.2.3-54-g00ecf