towerops/lib/towerops/snmp/transceiver_reading.ex

60 lines
1.7 KiB
Elixir

defmodule Towerops.Snmp.TransceiverReading do
@moduledoc """
SNMP transceiver DOM (Digital Optical Monitoring) reading schema.
Stores time-series optical power and diagnostic metrics for transceivers.
Includes standard DOM parameters: Rx/Tx power, bias current, temperature, voltage.
Readings are typically polled every 60 seconds for transceivers with DOM support.
"""
use Ecto.Schema
import Ecto.Changeset
alias Ecto.Association.NotLoaded
alias Towerops.Snmp.Transceiver
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "snmp_transceiver_readings" do
field :rx_power_dbm, :float
field :tx_power_dbm, :float
field :bias_current_ma, :float
field :temperature_celsius, :float
field :voltage_v, :float
field :measured_at, :utc_datetime
belongs_to :transceiver, Transceiver
timestamps(type: :utc_datetime)
end
@type t :: %__MODULE__{
id: Ecto.UUID.t(),
rx_power_dbm: float() | nil,
tx_power_dbm: float() | nil,
bias_current_ma: float() | nil,
temperature_celsius: float() | nil,
voltage_v: float() | nil,
measured_at: DateTime.t(),
transceiver_id: Ecto.UUID.t(),
transceiver: NotLoaded.t() | Transceiver.t(),
inserted_at: DateTime.t(),
updated_at: DateTime.t()
}
@doc false
def changeset(reading, attrs) do
reading
|> cast(attrs, [
:transceiver_id,
:rx_power_dbm,
:tx_power_dbm,
:bias_current_ma,
:temperature_celsius,
:voltage_v,
:measured_at
])
|> validate_required([:transceiver_id, :measured_at])
|> foreign_key_constraint(:transceiver_id)
end
end