UniFi Network API (v1) — alarms.
Returns active and archived alarms — the entries that show in the controller dashboard's "Alerts" pane: gateway down, AP disconnected, IDS detection, threshold crossings, etc.
Requires cookie + CSRF authentication. See UnifiApi.Auth.Cookie.
Alarm fields
_id,key,time,datetime,site_idarchived— booleanmsg— human-readable descriptionsubsystem—"wlan","lan","wan","vpn","system","ips","alarm"severity—"info","warn","critical"- For IPS alarms:
app_proto,catname,dest_ip,src_ip,proto,signature,usgip(gateway IP),inner_alert_action
Note: Like
Events, the field set comes from community/unpoller documentation rather than first-party schema. File an issue if your controller returns extra or differently-shaped fields.
Summary
Functions
Marks an alarm as archived.
Lists alarms for a site.
Returns a lazy stream that auto-paginates alarms via _start / _limit.
Functions
@spec archive(Req.Request.t(), String.t(), String.t()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Marks an alarm as archived.
Examples
{:ok, _} = UnifiApi.Network.Alarms.archive(client, "default", alarm_id)
@spec list(Req.Request.t(), String.t(), keyword()) :: {:ok, term()} | {:error, UnifiApi.Error.t()}
Lists alarms for a site.
Options
:archived—truereturns only archived alarms;falsereturns only active ones;nil(default) returns both.:limit—_limit=Nserver-side cap.:start—_start=Npagination offset.
Examples
# All active alarms
{:ok, alarms} = UnifiApi.Network.Alarms.list(client, "default", archived: false)
# Just IPS detections
{:ok, alarms} = UnifiApi.Network.Alarms.list(client, "default")
Enum.filter(alarms, &(&1["subsystem"] == "ips"))
@spec stream(Req.Request.t(), String.t(), keyword()) :: Enumerable.t()
Returns a lazy stream that auto-paginates alarms via _start / _limit.
Error contract
A mid-stream error does not raise by default: the stream halts and
yields {:error, %UnifiApi.StreamError{}, last_start} as its final element,
so the enumerable is heterogeneous and Enum.map(stream, & &1["key"])
crashes on a transient 500. Match the tail:
items = Enum.to_list(stream)
case List.last(items) do
{:error, error, cursor} -> {:error, error, cursor}
_ -> {:ok, items}
endPass raise_errors: true to raise UnifiApi.StreamError instead.
Options
:archived—truefor archived only,falsefor active only.:limit— page size (default 500).:max_pages— halt after this many successful pages (default: unbounded).:max_items— halt once this many alarms have been yielded; the final page is truncated to fit (default: unbounded).:raise_errors— whentrue, raiseUnifiApi.StreamErroron a mid-stream error instead of yielding{:error, reason, last_start}as the final element (default:false).
:max_pages, :max_items and :raise_errors are forwarded verbatim
to UnifiApi.Client.stream_v1/3 and behave exactly as they do in
UnifiApi.Client.stream/3. Any other key raises ArgumentError.
Examples
# At most 50 active alarms, however many pages that takes
UnifiApi.Network.Alarms.stream(authed, "default", archived: false, max_items: 50)
|> Enum.to_list()