From 541ab7e7d69abf97d7faa01ee19345236f95be1a Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 17 Jan 2026 15:13:56 -0600 Subject: [PATCH] more renames --- TODOS.md | 3 +++ lib/towerops/agents/stats.ex | 8 ++++---- lib/towerops/snmp.ex | 6 +++--- lib/towerops/snmp/discovery.ex | 12 ++++++------ lib/towerops_web/channels/agent_channel.ex | 2 +- lib/towerops_web/live/agent_live/index.ex | 4 ++-- lib/towerops_web/live/device_live/form.ex | 6 +++--- lib/towerops_web/live/org/settings_live.ex | 2 +- test/towerops/agents/stats_test.exs | 16 ++++++++-------- test/towerops/snmp/discovery_test.exs | 14 +++++++------- 10 files changed, 38 insertions(+), 35 deletions(-) diff --git a/TODOS.md b/TODOS.md index dd9037e2..a8630b15 100644 --- a/TODOS.md +++ b/TODOS.md @@ -3,3 +3,6 @@ * When adding a new device, allow the community string to be empty so it will inherit from the parent * add and track ICMP pings for each device. it should also put a latency graph on the device page that links to the universal graph like the other graphs * when adding a new device, make it a tab selector to show the default SNMP & ICMP or ICMP only +* add valkey as a k8s sidecar +* add the latest exq to the web app +* set up any jobs that need to be run in the background to use exq diff --git a/lib/towerops/agents/stats.ex b/lib/towerops/agents/stats.ex index 5418e58c..6dbfb805 100644 --- a/lib/towerops/agents/stats.ex +++ b/lib/towerops/agents/stats.ex @@ -82,7 +82,7 @@ defmodule Towerops.Agents.Stats do ## Examples - iex> get_equipment_assignment_breakdown(org_id) + iex> get_device_assignment_breakdown(org_id) %{ direct: 50, site: 30, @@ -90,7 +90,7 @@ defmodule Towerops.Agents.Stats do cloud: 5 } """ - def get_equipment_assignment_breakdown(organization_id) do + def get_device_assignment_breakdown(organization_id) do # Use a single SQL query with CASE to determine assignment source # device into memory and calling get_effective_agent_token_with_source results = @@ -266,12 +266,12 @@ defmodule Towerops.Agents.Stats do ## Examples - iex> get_unmonitored_equipment(org_id) + iex> get_unmonitored_devices(org_id) [ %{id: "uuid", name: "Switch-01", site_name: "DC1"} ] """ - def get_unmonitored_equipment(organization_id) do + def get_unmonitored_devices(organization_id) do # device has no agent assigned # device into memory Repo.all( diff --git a/lib/towerops/snmp.ex b/lib/towerops/snmp.ex index c567a3dd..523c1cfa 100644 --- a/lib/towerops/snmp.ex +++ b/lib/towerops/snmp.ex @@ -50,11 +50,11 @@ defmodule Towerops.Snmp do ## Examples - iex> discover_equipment(device) + iex> discover_device(device) {:ok, %Device{}} """ - def discover_equipment(%DeviceSchema{} = device) do - Discovery.discover_equipment(device) + def discover_device(%DeviceSchema{} = device) do + Discovery.discover_device(device) end @doc """ diff --git a/lib/towerops/snmp/discovery.ex b/lib/towerops/snmp/discovery.ex index f1073881..7bf23d44 100644 --- a/lib/towerops/snmp/discovery.ex +++ b/lib/towerops/snmp/discovery.ex @@ -83,19 +83,19 @@ defmodule Towerops.Snmp.Discovery do } @doc """ - Runs discovery for a single piece of device. + Runs discovery for a single device. Returns {:ok, device} or {:error, reason}. ## Examples - iex> discover_equipment(device) + iex> discover_device(device) {:ok, %Device{manufacturer: "Cisco", model: "C2960"}} - iex> discover_equipment(device_without_snmp) + iex> discover_device(device_without_snmp) {:error, :snmp_not_enabled} """ - @spec discover_equipment(DeviceSchema.t()) :: {:ok, Device.t()} | {:error, term()} - def discover_equipment(%DeviceSchema{} = device) do + @spec discover_device(DeviceSchema.t()) :: {:ok, Device.t()} | {:error, term()} + def discover_device(%DeviceSchema{} = device) do if device.snmp_enabled do Logger.info("Starting SNMP discovery for device: #{device.name} (#{device.ip_address})") @@ -149,7 +149,7 @@ defmodule Towerops.Snmp.Discovery do results = device_list |> Task.async_stream( - &discover_equipment/1, + &discover_device/1, max_concurrency: 5, timeout: 60_000, on_timeout: :kill_task diff --git a/lib/towerops_web/channels/agent_channel.ex b/lib/towerops_web/channels/agent_channel.ex index f594253e..726bed22 100644 --- a/lib/towerops_web/channels/agent_channel.ex +++ b/lib/towerops_web/channels/agent_channel.ex @@ -318,7 +318,7 @@ defmodule ToweropsWeb.AgentChannel do Logger.info("Discovery results received for #{device.name}, triggering full discovery") Task.start(fn -> - case Discovery.discover_equipment(device) do + case Discovery.discover_device(device) do {:ok, _device} -> Logger.info("Full discovery completed for #{device.name}") diff --git a/lib/towerops_web/live/agent_live/index.ex b/lib/towerops_web/live/agent_live/index.ex index 49a79bc3..82e484a8 100644 --- a/lib/towerops_web/live/agent_live/index.ex +++ b/lib/towerops_web/live/agent_live/index.ex @@ -22,7 +22,7 @@ defmodule ToweropsWeb.AgentLive.Index do # Get organization-wide agent health statistics agent_health_stats = Stats.get_organization_agent_health(organization.id) - assignment_breakdown = Stats.get_equipment_assignment_breakdown(organization.id) + assignment_breakdown = Stats.get_device_assignment_breakdown(organization.id) offline_agents = Stats.get_offline_agents(organization.id) # Get agent image URL from config or use default @@ -71,7 +71,7 @@ defmodule ToweropsWeb.AgentLive.Index do # Refresh health statistics agent_health_stats = Stats.get_organization_agent_health(organization.id) - assignment_breakdown = Stats.get_equipment_assignment_breakdown(organization.id) + assignment_breakdown = Stats.get_device_assignment_breakdown(organization.id) offline_agents = Stats.get_offline_agents(organization.id) {:noreply, diff --git a/lib/towerops_web/live/device_live/form.ex b/lib/towerops_web/live/device_live/form.ex index 8bc170a5..28e27a02 100644 --- a/lib/towerops_web/live/device_live/form.ex +++ b/lib/towerops_web/live/device_live/form.ex @@ -157,7 +157,7 @@ defmodule ToweropsWeb.DeviceLive.Form do # Run discovery in background _ = Task.start(fn -> - Snmp.discover_equipment(device) + Snmp.discover_device(device) end) {:noreply, put_flash(socket, :info, "Discovery started...")} @@ -214,7 +214,7 @@ defmodule ToweropsWeb.DeviceLive.Form do defp handle_device_creation(device) do if device.snmp_enabled do - _ = Task.start(fn -> Snmp.discover_equipment(device) end) + _ = Task.start(fn -> Snmp.discover_device(device) end) "Device created successfully. SNMP discovery started in background." else "Device created successfully" @@ -223,7 +223,7 @@ defmodule ToweropsWeb.DeviceLive.Form do defp handle_device_update(old_device, device) do if should_trigger_snmp_discovery?(old_device, device) do - _ = Task.start(fn -> Snmp.discover_equipment(device) end) + _ = Task.start(fn -> Snmp.discover_device(device) end) "Device updated successfully. SNMP discovery started in background." else "Device updated successfully" diff --git a/lib/towerops_web/live/org/settings_live.ex b/lib/towerops_web/live/org/settings_live.ex index 62a23144..77822760 100644 --- a/lib/towerops_web/live/org/settings_live.ex +++ b/lib/towerops_web/live/org/settings_live.ex @@ -11,7 +11,7 @@ defmodule ToweropsWeb.Org.SettingsLive do available_agents = Agents.list_organization_agent_tokens(organization.id) # Get assignment breakdown to show impact - assignment_breakdown = Agents.Stats.get_equipment_assignment_breakdown(organization.id) + assignment_breakdown = Agents.Stats.get_device_assignment_breakdown(organization.id) changeset = Organizations.change_organization(organization) diff --git a/test/towerops/agents/stats_test.exs b/test/towerops/agents/stats_test.exs index c4c378bd..0c43f253 100644 --- a/test/towerops/agents/stats_test.exs +++ b/test/towerops/agents/stats_test.exs @@ -98,12 +98,12 @@ defmodule Towerops.Agents.StatsTest do end end - describe "get_equipment_assignment_breakdown/1" do + describe "get_device_assignment_breakdown/1" do test "returns zero counts for organization with no devices" do user = user_fixture() org = organization_fixture(user.id) - breakdown = Stats.get_equipment_assignment_breakdown(org.id) + breakdown = Stats.get_device_assignment_breakdown(org.id) assert breakdown == %{direct: 0, site: 0, organization: 0, cloud: 0} end @@ -138,7 +138,7 @@ defmodule Towerops.Agents.StatsTest do snmp_version: "2c" }) - breakdown = Stats.get_equipment_assignment_breakdown(org.id) + breakdown = Stats.get_device_assignment_breakdown(org.id) assert breakdown.direct == 1 assert breakdown.cloud == 1 @@ -265,7 +265,7 @@ defmodule Towerops.Agents.StatsTest do end end - describe "get_unmonitored_equipment/1" do + describe "get_unmonitored_devices/1" do test "returns empty list when all devices has agents" do user = user_fixture() org = organization_fixture(user.id) @@ -285,7 +285,7 @@ defmodule Towerops.Agents.StatsTest do {:ok, _assignment} = Agents.assign_device_to_agent(agent_token.id, device.id) - unmonitored = Stats.get_unmonitored_equipment(org.id) + unmonitored = Stats.get_unmonitored_devices(org.id) assert unmonitored == [] end @@ -306,7 +306,7 @@ defmodule Towerops.Agents.StatsTest do monitoring_enabled: true }) - unmonitored = Stats.get_unmonitored_equipment(org.id) + unmonitored = Stats.get_unmonitored_devices(org.id) assert length(unmonitored) == 1 eq = hd(unmonitored) @@ -330,7 +330,7 @@ defmodule Towerops.Agents.StatsTest do monitoring_enabled: true }) - unmonitored = Stats.get_unmonitored_equipment(org.id) + unmonitored = Stats.get_unmonitored_devices(org.id) assert unmonitored == [] end @@ -351,7 +351,7 @@ defmodule Towerops.Agents.StatsTest do monitoring_enabled: false }) - unmonitored = Stats.get_unmonitored_equipment(org.id) + unmonitored = Stats.get_unmonitored_devices(org.id) assert unmonitored == [] end diff --git a/test/towerops/snmp/discovery_test.exs b/test/towerops/snmp/discovery_test.exs index 95f6e831..83ddf65b 100644 --- a/test/towerops/snmp/discovery_test.exs +++ b/test/towerops/snmp/discovery_test.exs @@ -26,7 +26,7 @@ defmodule Towerops.Snmp.DiscoveryTest do %{organization: organization, site: site} end - describe "discover_equipment/1" do + describe "discover_device/1" do test "returns error when SNMP is not enabled", %{site: site} do {:ok, device} = Towerops.Devices.create_device(%{ @@ -36,7 +36,7 @@ defmodule Towerops.Snmp.DiscoveryTest do snmp_enabled: false }) - assert {:error, :snmp_not_enabled} = Discovery.discover_equipment(device) + assert {:error, :snmp_not_enabled} = Discovery.discover_device(device) end test "successfully discovers MikroTik device", %{site: site} do @@ -147,7 +147,7 @@ defmodule Towerops.Snmp.DiscoveryTest do end end) - assert {:ok, device} = Discovery.discover_equipment(device) + assert {:ok, device} = Discovery.discover_device(device) assert device.manufacturer == "MikroTik" assert device.model == "RB750" @@ -213,7 +213,7 @@ defmodule Towerops.Snmp.DiscoveryTest do {:ok, []} end) - assert {:ok, device} = Discovery.discover_equipment(device) + assert {:ok, device} = Discovery.discover_device(device) assert device.manufacturer == "Cisco" assert device.model == "C2960" @@ -237,7 +237,7 @@ defmodule Towerops.Snmp.DiscoveryTest do {:error, :timeout} end) - assert {:error, :timeout} = Discovery.discover_equipment(device) + assert {:error, :timeout} = Discovery.discover_device(device) end test "handles partial discovery failure gracefully", %{site: site} do @@ -293,7 +293,7 @@ defmodule Towerops.Snmp.DiscoveryTest do end) # Should succeed even with failed interface/sensor discovery - assert {:ok, device} = Discovery.discover_equipment(device) + assert {:ok, device} = Discovery.discover_device(device) assert device.manufacturer == "Unknown" @@ -357,7 +357,7 @@ defmodule Towerops.Snmp.DiscoveryTest do {:ok, []} end) - assert {:ok, updated_device} = Discovery.discover_equipment(device) + assert {:ok, updated_device} = Discovery.discover_device(device) # Should be same device, updated assert updated_device.id == initial_device.id