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.
This commit is contained in:
Graham McIntire 2026-02-14 14:52:02 -06:00
parent 06f9b7e60b
commit 29c2039832
2 changed files with 18 additions and 0 deletions

View file

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

View file

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