dhcp-to-dns: properly handle vanished lease

This commit is contained in:
Christian Hesse 2021-06-29 15:24:23 +02:00
parent 9c9fb46e4a
commit 23daea2354

View file

@ -52,7 +52,14 @@ $ScriptLock $0 false 10;
} }
:foreach Lease in=[ / ip dhcp-server lease find where status=bound ] do={ :foreach Lease in=[ / ip dhcp-server lease find where status=bound ] do={
:local LeaseVal [ / ip dhcp-server lease get $Lease ]; :local LeaseVal;
:do {
:set LeaseVal [ / ip dhcp-server lease get $Lease ];
} on-error={
$LogPrintExit2 debug $0 ("A lease just vanished, ignoring.") false;
}
:if ([ :typeof $LeaseVal ] = "array") do={
:local Comment ($CommentPrefix . $LeaseVal->"mac-address"); :local Comment ($CommentPrefix . $LeaseVal->"mac-address");
:local HostName [ $IfThenElse ([ :len ($LeaseVal->"host-name") ] = 0) \ :local HostName [ $IfThenElse ([ :len ($LeaseVal->"host-name") ] = 0) \
[ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ] \ [ $CharacterReplace ($LeaseVal->"mac-address") ":" "-" ] \
@ -82,4 +89,5 @@ $ScriptLock $0 false 10;
$LogPrintExit2 info $0 ("Adding new DNS entry for " . $Fqdn . ", address is " . $LeaseVal->"address" . ".") false; $LogPrintExit2 info $0 ("Adding new DNS entry for " . $Fqdn . ", address is " . $LeaseVal->"address" . ".") false;
/ ip dns static add name=$Fqdn address=($LeaseVal->"address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore; / ip dns static add name=$Fqdn address=($LeaseVal->"address") ttl=$Ttl comment=$Comment place-before=$PlaceBefore;
} }
}
} }