collect-wireless-mac: properly handle vanished device

This commit is contained in:
Christian Hesse 2021-07-01 09:56:34 +02:00
parent 5f357fd242
commit 877e95d4be
3 changed files with 45 additions and 18 deletions

View file

@ -31,9 +31,21 @@ $ScriptLock $0 false 10;
:local PlaceBefore ([ / caps-man access-list find where comment="--- collected above ---" disabled ]->0); :local PlaceBefore ([ / caps-man access-list find where comment="--- collected above ---" disabled ]->0);
:foreach RegTbl in=[ / caps-man registration-table find ] do={ :foreach RegTbl in=[ / caps-man registration-table find ] do={
:local Mac [ / caps-man registration-table get $RegTbl mac-address ]; :local Mac;
:local AccessList ([ / caps-man access-list find where mac-address=$Mac ]->0); :local AccessList;
:if ([ :len $AccessList ] = 0) do={ :do {
:set Mac [ / caps-man registration-table get $RegTbl mac-address ];
:set AccessList ([ / caps-man 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: " . \
[ / caps-man access-list get $AccessList comment ]) false;
}
:if ([ :typeof $Mac ] = "str" && [ :len $AccessList ] = 0) do={
:local Address "no dhcp lease"; :local Address "no dhcp lease";
:local DnsName "no dhcp lease"; :local DnsName "no dhcp lease";
:local HostName "no dhcp lease"; :local HostName "no dhcp lease";
@ -70,8 +82,5 @@ $ScriptLock $0 false 10;
"Address: " . $Address . "\n" . \ "Address: " . $Address . "\n" . \
"DNS name: " . $DnsName . "\n" . \ "DNS name: " . $DnsName . "\n" . \
"Date: " . $DateTime) }); "Date: " . $DateTime) });
} else={
$LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \
[ / caps-man access-list get $AccessList comment ]) false;
} }
} }

View file

@ -31,9 +31,21 @@ $ScriptLock $0 false 10;
:local PlaceBefore ([ / interface wireless access-list find where comment="--- collected above ---" disabled ]->0); :local PlaceBefore ([ / interface wireless access-list find where comment="--- collected above ---" disabled ]->0);
:foreach RegTbl in=[ / interface wireless registration-table find ] do={ :foreach RegTbl in=[ / interface wireless registration-table find ] do={
:local Mac [ / interface wireless registration-table get $RegTbl mac-address ]; :local Mac;
:local AccessList ([ / interface wireless access-list find where mac-address=$Mac ]->0); :local AccessList;
:if ([ :len $AccessList ] = 0) do={ :do {
:set Mac [ / interface wireless registration-table get $RegTbl mac-address ];
:set AccessList ([ / interface wireless 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: " . \
[ / interface wireless access-list get $AccessList comment ]) false;
}
:if ([ :typeof $Mac ] = "str" && [ :len $AccessList ] = 0) do={
:local Address "no dhcp lease"; :local Address "no dhcp lease";
:local DnsName "no dhcp lease"; :local DnsName "no dhcp lease";
:local HostName "no dhcp lease"; :local HostName "no dhcp lease";
@ -70,8 +82,5 @@ $ScriptLock $0 false 10;
"Address: " . $Address . "\n" . \ "Address: " . $Address . "\n" . \
"DNS name: " . $DnsName . "\n" . \ "DNS name: " . $DnsName . "\n" . \
"Date: " . $DateTime) }); "Date: " . $DateTime) });
} else={
$LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \
[ / interface wireless access-list get $AccessList comment ]) false;
} }
} }

View file

@ -32,9 +32,21 @@ $ScriptLock $0 false 10;
:local PlaceBefore ([ / %PATH% access-list find where comment="--- collected above ---" disabled ]->0); :local PlaceBefore ([ / %PATH% access-list find where comment="--- collected above ---" disabled ]->0);
:foreach RegTbl in=[ / %PATH% registration-table find ] do={ :foreach RegTbl in=[ / %PATH% registration-table find ] do={
:local Mac [ / %PATH% registration-table get $RegTbl mac-address ]; :local Mac;
:local AccessList ([ / %PATH% access-list find where mac-address=$Mac ]->0); :local AccessList;
:if ([ :len $AccessList ] = 0) do={ :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 Address "no dhcp lease";
:local DnsName "no dhcp lease"; :local DnsName "no dhcp lease";
:local HostName "no dhcp lease"; :local HostName "no dhcp lease";
@ -72,8 +84,5 @@ $ScriptLock $0 false 10;
"Address: " . $Address . "\n" . \ "Address: " . $Address . "\n" . \
"DNS name: " . $DnsName . "\n" . \ "DNS name: " . $DnsName . "\n" . \
"Date: " . $DateTime) }); "Date: " . $DateTime) });
} else={
$LogPrintExit2 debug $0 ("MAC address " . $Mac . " already known: " . \
[ / %PATH% access-list get $AccessList comment ]) false;
} }
} }