From 877e95d4be240835e2153ba4ce5fe615a127eda1 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 1 Jul 2021 09:56:34 +0200 Subject: collect-wireless-mac: properly handle vanished device --- collect-wireless-mac.template | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'collect-wireless-mac.template') diff --git a/collect-wireless-mac.template b/collect-wireless-mac.template index 8ccfeff..2be6447 100644 --- a/collect-wireless-mac.template +++ b/collect-wireless-mac.template @@ -32,9 +32,21 @@ $ScriptLock $0 false 10; :local PlaceBefore ([ / %PATH% access-list find where comment="--- collected above ---" disabled ]->0); :foreach RegTbl in=[ / %PATH% registration-table find ] do={ - :local Mac [ / %PATH% registration-table get $RegTbl mac-address ]; - :local AccessList ([ / %PATH% access-list find where mac-address=$Mac ]->0); - :if ([ :len $AccessList ] = 0) do={ + :local Mac; + :local AccessList; + :do { + :set Mac [ / %PATH% registration-table get $RegTbl mac-address ]; + :set AccessList ([ / %PATH% access-list find where mac-address=$Mac ]->0); + } on-error={ + $LogPrintExit2 debug $0 ("Device already gone... Ignoring.") false; + } + + :if ([ :len $AccessList ] > 0) do={ + $LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \ + [ / %PATH% access-list get $AccessList comment ]) false; + } + + :if ([ :typeof $Mac ] = "str" && [ :len $AccessList ] = 0) do={ :local Address "no dhcp lease"; :local DnsName "no dhcp lease"; :local HostName "no dhcp lease"; @@ -72,8 +84,5 @@ $ScriptLock $0 false 10; "Address: " . $Address . "\n" . \ "DNS name: " . $DnsName . "\n" . \ "Date: " . $DateTime) }); - } else={ - $LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \ - [ / %PATH% access-list get $AccessList comment ]) false; } } -- cgit v1.2.3-70-g09d2