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
57 lines
1.6 KiB
Elixir
57 lines
1.6 KiB
Elixir
defmodule ToweropsWeb.DeviceLive.Index do
|
|
@moduledoc false
|
|
use ToweropsWeb, :live_view
|
|
|
|
alias Towerops.Devices
|
|
alias Towerops.Sites
|
|
alias Towerops.Snmp
|
|
alias Towerops.Workers.DiscoveryWorker
|
|
|
|
@impl true
|
|
def mount(_params, _session, socket) do
|
|
organization = socket.assigns.current_organization
|
|
device = Devices.list_organization_devices(organization.id)
|
|
sites = Sites.list_organization_sites(organization.id)
|
|
|
|
{:ok,
|
|
socket
|
|
|> assign(:page_title, "Devices")
|
|
|> assign(:device, device)
|
|
|> assign(:has_sites, sites != [])}
|
|
end
|
|
|
|
@impl true
|
|
def handle_params(params, _url, socket) do
|
|
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
|
end
|
|
|
|
defp apply_action(socket, :index, _params) do
|
|
socket
|
|
end
|
|
|
|
@impl true
|
|
def handle_event("force_rediscover_all", _params, socket) do
|
|
devices = socket.assigns.device
|
|
snmp_devices = Enum.filter(devices, & &1.snmp_enabled)
|
|
|
|
if Enum.empty?(snmp_devices) do
|
|
{:noreply, put_flash(socket, :error, "No SNMP-enabled devices found")}
|
|
else
|
|
Enum.each(snmp_devices, fn device ->
|
|
enqueue_discovery(device.id)
|
|
end)
|
|
|
|
count = length(snmp_devices)
|
|
|
|
{:noreply, put_flash(socket, :info, "Discovery started for #{count} device#{if count == 1, do: "", else: "s"}")}
|
|
end
|
|
end
|
|
|
|
defp enqueue_discovery(device_id) do
|
|
if Application.get_env(:towerops, :env) == :test do
|
|
_ = Task.start(fn -> Snmp.discover_device(Devices.get_device!(device_id)) end)
|
|
else
|
|
{:ok, _job} = Exq.enqueue(Exq, "discovery", DiscoveryWorker, [device_id])
|
|
end
|
|
end
|
|
end
|