Trigger immediate poll after SNMP discovery completes

This commit is contained in:
Graham McIntire 2026-01-05 12:46:25 -06:00
parent 62689ea939
commit 8f7ed19d34
No known key found for this signature in database

View file

@ -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)