From ecd9f78ba83de9b7c7a15456fd56ddde135e8570 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 10 Feb 2026 13:18:40 -0600 Subject: [PATCH] Add backward compatibility for PING results from older agents Older agents send PING job results as SnmpResult messages instead of MonitoringCheck messages, causing FunctionClauseError when process_job_result/3 tried to pattern match on job_type: :PING. Added handler that: - Catches PING results in SnmpResult format - Logs warning that agent should be upgraded - Creates monitoring check with success status - Stores result via store_monitoring_check This prevents crashes while maintaining backward compatibility until all production agents are upgraded to use MonitoringCheck format. Co-Authored-By: Claude Sonnet 4.5 --- lib/towerops_web/channels/agent_channel.ex | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/towerops_web/channels/agent_channel.ex b/lib/towerops_web/channels/agent_channel.ex index 1cf7ce68..9543d6b8 100644 --- a/lib/towerops_web/channels/agent_channel.ex +++ b/lib/towerops_web/channels/agent_channel.ex @@ -1163,6 +1163,28 @@ defmodule ToweropsWeb.AgentChannel do process_polling_result(device, result, socket) end + defp process_job_result(device, %{job_type: :PING} = result, socket) do + # Backward compatibility: older agents send PING results as SnmpResult instead of MonitoringCheck + # Newer agents should use the "monitoring_check" event instead + Logger.warning("Agent sent PING result as SnmpResult (deprecated). Agent should be upgraded.", + agent_token_id: socket.assigns.agent_token_id, + device_id: device.id, + job_id: result.job_id + ) + + # PING jobs sent as SnmpResult have empty oid_values + # If we receive a result (not an error), assume success + check = %{ + device_id: device.id, + status: "success", + # Unknown - older agents don't send this + response_time_ms: 0.0, + timestamp: result.timestamp + } + + store_monitoring_check(check, socket) + end + defp process_discovery_result(device, result, socket) do Logger.info("Discovery results received from agent for #{device.name}, processing data")