towerops/lib/towerops/alerts/alert.ex
Graham McIntire 0a4482f974
feat: add 5 new vendor modules and fix dialyzer issues
Vendor modules added:
- Aviat (WTM microwave radios)
- Aruba (wireless controllers and APs)
- CiscoWLC (Cisco wireless LAN controllers)
- Teltonika (RUTOS LTE routers)
- Sub10 (mmWave backhaul radios)

Dialyzer fixes:
- Fix unknown type Devices.t/0 in alert.ex and device.ex
- Fix unmatched_return warnings across multiple files
- Add :exq to PLT for Exq function detection
- Remove dead code in base.ex, dynamic.ex, vendor.ex
- Fix Device.t() type spec to allow nil name field

Tests: 1437 tests, 0 failures
Dialyzer: 0 errors
Credo: no issues
2026-01-22 09:34:50 -06:00

65 lines
1.8 KiB
Elixir

defmodule Towerops.Alerts.Alert do
@moduledoc """
Alert schema for device monitoring alerts.
Tracks device_up, device_down, and sensor threshold alerts with
acknowledgement status and auto-resolution.
"""
use Ecto.Schema
import Ecto.Changeset
alias Ecto.Association.NotLoaded
alias Towerops.Accounts.User
alias Towerops.Devices.Device
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "alerts" do
field :alert_type, Ecto.Enum, values: [:device_down, :device_up]
field :triggered_at, :utc_datetime
field :acknowledged_at, :utc_datetime
field :resolved_at, :utc_datetime
field :email_sent_at, :utc_datetime
field :message, :string
belongs_to :device, Device
belongs_to :acknowledged_by, User
timestamps(type: :utc_datetime)
end
@type t :: %__MODULE__{
id: Ecto.UUID.t(),
alert_type: :device_down | :device_up,
triggered_at: DateTime.t(),
acknowledged_at: DateTime.t() | nil,
resolved_at: DateTime.t() | nil,
email_sent_at: DateTime.t() | nil,
message: String.t() | nil,
device_id: Ecto.UUID.t(),
device: NotLoaded.t() | Device.t(),
acknowledged_by_id: Ecto.UUID.t() | nil,
acknowledged_by: NotLoaded.t() | User.t() | nil,
inserted_at: DateTime.t(),
updated_at: DateTime.t()
}
@doc false
def changeset(alert, attrs) do
alert
|> cast(attrs, [
:device_id,
:alert_type,
:triggered_at,
:acknowledged_at,
:acknowledged_by_id,
:resolved_at,
:email_sent_at,
:message
])
|> validate_required([:device_id, :alert_type, :triggered_at])
|> foreign_key_constraint(:device_id)
|> foreign_key_constraint(:acknowledged_by_id)
end
end