From 8f7ed19d34d2dd12c24af0c0bfe2039d5624556a Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 5 Jan 2026 12:46:25 -0600 Subject: [PATCH] Trigger immediate poll after SNMP discovery completes --- lib/towerops/snmp/poller_worker.ex | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/towerops/snmp/poller_worker.ex b/lib/towerops/snmp/poller_worker.ex index 8f8b4527..402aa4d4 100644 --- a/lib/towerops/snmp/poller_worker.ex +++ b/lib/towerops/snmp/poller_worker.ex @@ -48,6 +48,9 @@ defmodule Towerops.Snmp.PollerWorker do def init(equipment_id) do equipment = Equipment.get_equipment!(equipment_id) + # Subscribe to discovery completion events for this equipment + Phoenix.PubSub.subscribe(Towerops.PubSub, "equipment:#{equipment_id}") + if equipment.snmp_enabled do # Get the device to check if it has sensors/interfaces device = Snmp.get_device_with_associations(equipment_id) @@ -67,6 +70,14 @@ defmodule Towerops.Snmp.PollerWorker do {:noreply, state} end + @impl true + def handle_info({:discovery_completed, _equipment_id}, state) do + Logger.info("Discovery completed, triggering immediate poll") + # Trigger immediate poll after discovery + send(self(), :poll_data) + {:noreply, state} + end + @impl true def handle_cast(:poll_now, state) do _ = perform_poll(state.equipment_id)