From e026930f2558c68640022effd8a09fe11781093b Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 10 Mar 2026 15:04:28 -0500 Subject: [PATCH] logging fix and some other codex fixes --- .gitignore | 1 + lib/towerops/snmp.ex | 18 +++++++++-- lib/towerops_web/live/agent_live/index.ex | 6 ---- lib/towerops_web/live/alert_live/index.ex | 5 ---- .../live/components/status_title_component.ex | 30 +------------------ lib/towerops_web/live/dashboard_live.ex | 5 ---- lib/towerops_web/live/device_live/index.ex | 6 ---- lib/towerops_web/live/device_live/show.ex | 6 ---- lib/towerops_web/router.ex | 2 ++ lib/towerops_web/user_auth.ex | 29 ++++++++++++++++-- test/towerops_web/live/site_live_test.exs | 29 ++++++++++++++++++ 11 files changed, 74 insertions(+), 63 deletions(-) diff --git a/.gitignore b/.gitignore index 7cc9b11d..581c6c48 100644 --- a/.gitignore +++ b/.gitignore @@ -92,6 +92,7 @@ profiles.json .runtime/ .claude/ .beads/ +.agents/ .logs/ .direnv/ diff --git a/lib/towerops/snmp.ex b/lib/towerops/snmp.ex index ad7798d8..1f21c526 100644 --- a/lib/towerops/snmp.ex +++ b/lib/towerops/snmp.ex @@ -1906,10 +1906,22 @@ defmodule Towerops.Snmp do end) |> tap(fn {_s, errors, error_samples} -> if errors > 0 do - Logger.warning("#{errors} ARP upsert failures for device #{device_id}", + samples_text = + case Enum.reverse(error_samples) do + [] -> + "" + + samples -> + "\nSample errors:\n" <> + Enum.map_join(samples, "\n", fn sample -> + " - IP: #{sample.ip}, MAC: #{sample.mac}, errors: #{inspect(sample.errors)}" + end) + end + + Logger.warning( + "#{errors} ARP upsert failures for device #{device_id}#{samples_text}", device_id: device_id, - error_count: errors, - sample_errors: Enum.reverse(error_samples) + error_count: errors ) end end) diff --git a/lib/towerops_web/live/agent_live/index.ex b/lib/towerops_web/live/agent_live/index.ex index dac3c101..14d48cb8 100644 --- a/lib/towerops_web/live/agent_live/index.ex +++ b/lib/towerops_web/live/agent_live/index.ex @@ -398,12 +398,6 @@ defmodule ToweropsWeb.AgentLive.Index do {:noreply, maybe_update_agent(socket, agent_token_id, organization_id)} end - # Handled by StatusTitleComponent in layout - ignore to prevent crashes - @impl true - def handle_info({:alert_changed, _org_id}, socket) do - {:noreply, socket} - end - @impl true def handle_info({:agents_stale, _stale_agents}, socket) do {:noreply, reload_agent_data(socket)} diff --git a/lib/towerops_web/live/alert_live/index.ex b/lib/towerops_web/live/alert_live/index.ex index 3df8c9e5..96dac9d9 100644 --- a/lib/towerops_web/live/alert_live/index.ex +++ b/lib/towerops_web/live/alert_live/index.ex @@ -186,11 +186,6 @@ defmodule ToweropsWeb.AlertLive.Index do {:noreply, load_alerts(socket, socket.assigns.current_scope.organization.id)} end - @impl true - def handle_info({:alert_changed, _org_id}, socket) do - {:noreply, load_alerts(socket, socket.assigns.current_scope.organization.id)} - end - defp load_alerts(socket, organization_id) do all_alerts = Alerts.list_organization_alerts(organization_id, %{"limit" => 500}) diff --git a/lib/towerops_web/live/components/status_title_component.ex b/lib/towerops_web/live/components/status_title_component.ex index fbd47c5a..7eb3899a 100644 --- a/lib/towerops_web/live/components/status_title_component.ex +++ b/lib/towerops_web/live/components/status_title_component.ex @@ -1,37 +1,9 @@ defmodule ToweropsWeb.Live.Components.StatusTitleComponent do @moduledoc """ - LiveComponent that subscribes to organization alert changes and updates the page title emoji. + LiveComponent that renders the browser-title status hook target. """ use ToweropsWeb, :live_component - alias ToweropsWeb.Helpers.StatusHelpers - - def mount(socket) do - {:ok, socket} - end - - def update(%{organization_id: org_id}, socket) do - if connected?(socket) do - Phoenix.PubSub.subscribe(Towerops.PubSub, "organization:#{org_id}:alerts") - end - - {:ok, assign(socket, :organization_id, org_id)} - end - - def handle_info({:alert_changed, _org_id}, socket) do - # Get the organization from the parent socket - org_id = socket.assigns.organization_id - organization = Towerops.Organizations.get_organization!(org_id) - - if organization do - emoji = StatusHelpers.status_emoji(organization) - # Push event to JavaScript hook to update the browser title - {:noreply, push_event(socket, "update_status_emoji", %{emoji: emoji})} - else - {:noreply, socket} - end - end - def render(assigns) do ~H"""