fix: filter out ARP entries with empty MAC addresses from SNMP

- Added guard clause to return nil for empty binary MAC addresses
- Filter rejects entries with nil IP or MAC addresses
- Prevents 'can't be blank' validation errors on upsert
- Root cause: some SNMP devices return incomplete ARP entries
This commit is contained in:
Graham McIntire 2026-03-10 15:33:52 -05:00
parent 7525bfd9a3
commit 232915e3e4
No known key found for this signature in database

View file

@ -46,7 +46,7 @@ defmodule Towerops.Snmp.ArpDiscovery do
last_seen_at: DateTime.truncate(DateTime.utc_now(), :second)
}
end)
|> Enum.reject(&is_nil(&1.ip_address))
|> Enum.reject(&(is_nil(&1.ip_address) or is_nil(&1.mac_address)))
{:ok, arp_entries}
end
@ -106,6 +106,11 @@ defmodule Towerops.Snmp.ArpDiscovery do
end
# Format MAC address from binary to colon-separated hex
defp format_mac_address(value) when is_binary(value) and byte_size(value) == 0 do
# Empty binary - SNMP returned blank MAC address
nil
end
defp format_mac_address(value) when is_binary(value) and byte_size(value) == 6 do
value
|> :binary.bin_to_list()