diff --git a/lib/towerops/snmp/poller_worker.ex b/lib/towerops/snmp/poller_worker.ex index 6c5afa3e..f4419ead 100644 --- a/lib/towerops/snmp/poller_worker.ex +++ b/lib/towerops/snmp/poller_worker.ex @@ -55,7 +55,7 @@ defmodule Towerops.Snmp.PollerWorker do # Get the device to check if it has sensors/interfaces device = Snmp.get_device_with_associations(equipment_id) - if device && (length(device.sensors) > 0 || length(device.interfaces) > 0) do + if device && (device.sensors != [] || device.interfaces != []) do # Perform immediate poll when starting send(self(), :poll_data) end @@ -416,7 +416,7 @@ defmodule Towerops.Snmp.PollerWorker do end # If there are changes, broadcast events and update interface - if length(changes) > 0 do + if changes != [] do # Broadcast all events via PubSub Enum.each(changes, fn {:event, event_attrs} -> Phoenix.PubSub.broadcast( diff --git a/lib/towerops/snmp/profiles/mikrotik.ex b/lib/towerops/snmp/profiles/mikrotik.ex index 5b79e236..3bab59e2 100644 --- a/lib/towerops/snmp/profiles/mikrotik.ex +++ b/lib/towerops/snmp/profiles/mikrotik.ex @@ -106,12 +106,12 @@ defmodule Towerops.Snmp.Profiles.Mikrotik do all_sensors = health_sensors ++ resource_sensors ++ entity_sensors - if length(all_sensors) > 0 do - Logger.debug("Discovered #{length(all_sensors)} MikroTik sensors") - {:ok, all_sensors} - else + if all_sensors == [] do Logger.warning("No MikroTik sensors found") {:ok, []} + else + Logger.debug("Discovered #{length(all_sensors)} MikroTik sensors") + {:ok, all_sensors} end end diff --git a/lib/towerops/snmp/profiles/net_snmp.ex b/lib/towerops/snmp/profiles/net_snmp.ex index f8ff4cf1..1b1930ae 100644 --- a/lib/towerops/snmp/profiles/net_snmp.ex +++ b/lib/towerops/snmp/profiles/net_snmp.ex @@ -65,12 +65,12 @@ defmodule Towerops.Snmp.Profiles.NetSnmp do all_sensors = lm_sensors ++ ucd_sensors - if length(all_sensors) > 0 do - {:ok, all_sensors} - else + if all_sensors == [] do # Fall back to standard ENTITY-SENSOR-MIB Logger.debug("Net-SNMP specific sensors not available, using standard discovery") Base.discover_sensors(client_opts) + else + {:ok, all_sensors} end end diff --git a/lib/towerops_web/components/core_components.ex b/lib/towerops_web/components/core_components.ex index d8dd3d53..4003025d 100644 --- a/lib/towerops_web/components/core_components.ex +++ b/lib/towerops_web/components/core_components.ex @@ -25,6 +25,7 @@ defmodule ToweropsWeb.CoreComponents do use Phoenix.Component use Gettext, backend: ToweropsWeb.Gettext + alias Phoenix.HTML.Form alias Phoenix.HTML.FormField alias Phoenix.LiveView.JS @@ -247,7 +248,7 @@ defmodule ToweropsWeb.CoreComponents do def input(%{type: "checkbox"} = assigns) do assigns = assign_new(assigns, :checked, fn -> - Phoenix.HTML.Form.normalize_value("checkbox", assigns[:value]) + Form.normalize_value("checkbox", assigns[:value]) end) ~H""" diff --git a/lib/towerops_web/live/equipment_live/index.ex b/lib/towerops_web/live/equipment_live/index.ex index c985b388..ef145dc2 100644 --- a/lib/towerops_web/live/equipment_live/index.ex +++ b/lib/towerops_web/live/equipment_live/index.ex @@ -15,7 +15,7 @@ defmodule ToweropsWeb.EquipmentLive.Index do socket |> assign(:page_title, "Equipment") |> assign(:equipment, equipment) - |> assign(:has_sites, length(sites) > 0)} + |> assign(:has_sites, sites != [])} end @impl true diff --git a/test/integration/snmp_integration_test.exs b/test/integration/snmp_integration_test.exs index d1ee59a4..4e013d6b 100644 --- a/test/integration/snmp_integration_test.exs +++ b/test/integration/snmp_integration_test.exs @@ -83,11 +83,11 @@ defmodule Towerops.Integration.SnmpIntegrationTest do # Discover interfaces {:ok, interfaces} = Mikrotik.discover_interfaces(@test_device_opts) - assert length(interfaces) > 0 + refute Enum.empty?(interfaces) # Discover sensors {:ok, sensors} = Mikrotik.discover_sensors(@test_device_opts) - assert length(sensors) > 0 + refute Enum.empty?(sensors) # Identify device device_info = Mikrotik.identify_device(system_info) @@ -134,7 +134,7 @@ defmodule Towerops.Integration.SnmpIntegrationTest do Process.sleep(200) alerts = Towerops.Alerts.list_equipment_alerts(equipment.id) - assert length(alerts) > 0 + refute Enum.empty?(alerts) alert = hd(alerts) assert alert.alert_type == :equipment_down diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index bfe1119c..252d1ef8 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -17,6 +17,8 @@ defmodule ToweropsWeb.ConnCase do use ExUnit.CaseTemplate + alias Towerops.Accounts.Scope + using do quote do use ToweropsWeb, :verified_routes @@ -46,7 +48,7 @@ defmodule ToweropsWeb.ConnCase do """ def register_and_log_in_user(%{conn: conn} = context) do user = Towerops.AccountsFixtures.user_fixture() - scope = Towerops.Accounts.Scope.for_user(user) + scope = Scope.for_user(user) opts = context diff --git a/test/towerops/monitoring/equipment_monitor_test.exs b/test/towerops/monitoring/equipment_monitor_test.exs index 394e2d76..15677065 100644 --- a/test/towerops/monitoring/equipment_monitor_test.exs +++ b/test/towerops/monitoring/equipment_monitor_test.exs @@ -67,7 +67,7 @@ defmodule Towerops.Monitoring.EquipmentMonitorTest do # Should have created a monitoring check checks = Monitoring.list_equipment_checks(equipment.id) - assert length(checks) > 0 + refute Enum.empty?(checks) end end @@ -131,7 +131,7 @@ defmodule Towerops.Monitoring.EquipmentMonitorTest do # Should create an alert (no need to sleep since test env doesn't send emails) alerts = Alerts.list_equipment_alerts(equipment.id) - assert length(alerts) > 0 + refute Enum.empty?(alerts) alert = hd(alerts) assert alert.alert_type == :equipment_down @@ -158,7 +158,7 @@ defmodule Towerops.Monitoring.EquipmentMonitorTest do # Should create recovery alert alerts = Alerts.list_equipment_alerts(equipment.id, 10) up_alerts = Enum.filter(alerts, &(&1.alert_type == :equipment_up)) - assert length(up_alerts) > 0 + refute Enum.empty?(up_alerts) end test "does not create duplicate down alerts", %{equipment: equipment} do diff --git a/test/towerops_web/live/equipment_live_test.exs b/test/towerops_web/live/equipment_live_test.exs index 5a9526be..2bdc1929 100644 --- a/test/towerops_web/live/equipment_live_test.exs +++ b/test/towerops_web/live/equipment_live_test.exs @@ -134,7 +134,7 @@ defmodule ToweropsWeb.EquipmentLiveTest do # Verify equipment was created equipment_list = Towerops.Equipment.list_organization_equipment(organization.id) - assert length(equipment_list) > 0 + refute Enum.empty?(equipment_list) new_equipment = Enum.find(equipment_list, &(&1.name == "New Router")) assert new_equipment