From 29c203983264a6481148ac2f43235bea94669e90 Mon Sep 17 00:00:00 2001 From: Graham McIntie Date: Sat, 14 Feb 2026 14:52:02 -0600 Subject: [PATCH] Auto-resolve device_up recovery alerts on creation device_up alerts are informational recovery events, not ongoing issues. Previously they were created without resolved_at, inflating the unresolved alert count. Now they're born resolved. Includes a data migration to fix existing stale device_up alerts. --- lib/towerops/workers/device_monitor_worker.ex | 1 + .../20260214204700_resolve_device_up_alerts.exs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 priv/repo/migrations/20260214204700_resolve_device_up_alerts.exs diff --git a/lib/towerops/workers/device_monitor_worker.ex b/lib/towerops/workers/device_monitor_worker.ex index 4745aaa5..b7e75aa1 100644 --- a/lib/towerops/workers/device_monitor_worker.ex +++ b/lib/towerops/workers/device_monitor_worker.ex @@ -237,6 +237,7 @@ defmodule Towerops.Workers.DeviceMonitorWorker do device_id: device.id, alert_type: :device_up, triggered_at: now, + resolved_at: now, message: recovery_message }) diff --git a/priv/repo/migrations/20260214204700_resolve_device_up_alerts.exs b/priv/repo/migrations/20260214204700_resolve_device_up_alerts.exs new file mode 100644 index 00000000..8bc4bb38 --- /dev/null +++ b/priv/repo/migrations/20260214204700_resolve_device_up_alerts.exs @@ -0,0 +1,17 @@ +defmodule Towerops.Repo.Migrations.ResolveDeviceUpAlerts do + use Ecto.Migration + + def up do + # device_up alerts are recovery notifications and should always be resolved. + # Previously they were created without resolved_at, leaving them "unresolved" forever. + execute """ + UPDATE alerts + SET resolved_at = triggered_at + WHERE alert_type = 'device_up' AND resolved_at IS NULL + """ + end + + def down do + :ok + end +end