From 26e5d2051095e7b867055224e34c673f9bfce7c8 Mon Sep 17 00:00:00 2001 From: mayor Date: Fri, 6 Feb 2026 11:26:00 -0600 Subject: [PATCH] fix: Add device_id to interfaces for neighbor discovery in agent polling Fixes KeyError when processing neighbor discovery during agent polling. NeighborDiscovery.discover_neighbors/2 requires interfaces to have a :device_id field for building neighbor records, but interfaces from the database only have :snmp_device_id. Solution matches the approach in DevicePollerWorker which adds device_id to interfaces before calling discover_neighbors. --- lib/towerops_web/channels/agent_channel.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/towerops_web/channels/agent_channel.ex b/lib/towerops_web/channels/agent_channel.ex index 8dd85260..19dc67b3 100644 --- a/lib/towerops_web/channels/agent_channel.ex +++ b/lib/towerops_web/channels/agent_channel.ex @@ -951,8 +951,11 @@ defmodule ToweropsWeb.AgentChannel do # Fetch interfaces once for reuse across multiple operations interfaces = Towerops.Snmp.list_interfaces(device.snmp_device.id) + # Add device_id to interfaces for neighbor discovery (required by build_neighbor_record) + interfaces_with_device_id = Enum.map(interfaces, &Map.put(&1, :device_id, device.id)) + # Process neighbors (LLDP/CDP) - case NeighborDiscovery.discover_neighbors(client_opts, interfaces) do + case NeighborDiscovery.discover_neighbors(client_opts, interfaces_with_device_id) do {:ok, neighbors} when neighbors != [] -> Towerops.Snmp.Discovery.save_neighbors(device.id, neighbors)