diff --git a/TODOS.md b/TODOS.md index 203be4f3..38059f66 100644 --- a/TODOS.md +++ b/TODOS.md @@ -1,6 +1,5 @@ # In Progress / Pending -* 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 @@ -13,3 +12,4 @@ * ~~change "revoke" agent to delete and have it actually delete the agent and ensure it's removed from everything it's been assigned and change them to cloud polling if they were previously set to that agent being deleted~~ * ~~add ability to rename an agent in a new edit page~~ * ~~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~~ diff --git a/lib/towerops_web/live/device_live/form.ex b/lib/towerops_web/live/device_live/form.ex index 821e0d2b..b3d4876b 100644 --- a/lib/towerops_web/live/device_live/form.ex +++ b/lib/towerops_web/live/device_live/form.ex @@ -67,6 +67,7 @@ defmodule ToweropsWeb.DeviceLive.Form do |> assign(:page_title, "New Device") |> assign(:device, %DeviceSchema{}) |> assign(:form, to_form(changeset)) + |> assign(:monitoring_mode, "snmp_and_icmp") end defp apply_action(socket, :edit, %{"id" => id}) do @@ -101,6 +102,9 @@ defmodule ToweropsWeb.DeviceLive.Form do # Get effective SNMP configuration and source snmp_config = Devices.get_snmp_config(device) + # Determine monitoring mode based on current snmp_enabled value + monitoring_mode = if device.snmp_enabled, do: "snmp_and_icmp", else: "icmp_only" + socket |> assign(:page_title, "Edit Device") |> assign(:device, device_with_agent) @@ -110,6 +114,30 @@ defmodule ToweropsWeb.DeviceLive.Form do |> assign(:snmp_config_source, snmp_config.source) |> assign(:effective_snmp_version, snmp_config.version) |> assign(:effective_snmp_community, snmp_config.community || "(not set)") + |> assign(:monitoring_mode, monitoring_mode) + end + + @impl true + def handle_event("switch_monitoring_mode", %{"mode" => mode}, socket) do + # Update snmp_enabled based on the selected mode + snmp_enabled = mode == "snmp_and_icmp" + + # Get current form params + current_params = socket.assigns.form.params + + # Update params with new snmp_enabled value + updated_params = Map.put(current_params, "snmp_enabled", snmp_enabled) + + # Create new changeset with updated params + changeset = + socket.assigns.device + |> Devices.change_device(updated_params) + |> Map.put(:action, :validate) + + socket + |> assign(:monitoring_mode, mode) + |> assign(:form, to_form(changeset)) + |> then(&{:noreply, &1}) end @impl true @@ -143,8 +171,21 @@ defmodule ToweropsWeb.DeviceLive.Form do @impl true def handle_event("test_snmp", _params, socket) do - snmp_config = extract_snmp_config(socket.assigns.form, socket.assigns) - result = test_snmp_connection(snmp_config) + # Check if an agent is assigned + agent_token_id = socket.assigns.form.params["agent_token_id"] + + result = + if agent_token_id && agent_token_id != "" do + # Agent is configured - can't test directly from web server + %{ + success: true, + message: "SNMP configuration saved. Connection will be tested by the assigned agent during next polling cycle." + } + else + # No agent configured - test directly from web server + snmp_config = extract_snmp_config(socket.assigns.form, socket.assigns) + test_snmp_connection(snmp_config) + end {:noreply, assign(socket, :snmp_test_result, result)} end @@ -171,6 +212,10 @@ defmodule ToweropsWeb.DeviceLive.Form do agent_token_id = Map.get(device_params, "agent_token_id") device_params = Map.delete(device_params, "agent_token_id") + # Add snmp_enabled based on monitoring mode + snmp_enabled = socket.assigns.monitoring_mode == "snmp_and_icmp" + device_params = Map.put(device_params, "snmp_enabled", snmp_enabled) + case Devices.create_device(device_params) do {:ok, device} -> # Handle agent assignment after device creation @@ -195,6 +240,10 @@ defmodule ToweropsWeb.DeviceLive.Form do agent_token_id = Map.get(device_params, "agent_token_id") device_params = Map.delete(device_params, "agent_token_id") + # Add snmp_enabled based on monitoring mode + snmp_enabled = socket.assigns.monitoring_mode == "snmp_and_icmp" + device_params = Map.put(device_params, "snmp_enabled", snmp_enabled) + case Devices.update_device(old_device, device_params) do {:ok, device} -> # device update diff --git a/lib/towerops_web/live/device_live/form.html.heex b/lib/towerops_web/live/device_live/form.html.heex index 2a5fc262..1bf73274 100644 --- a/lib/towerops_web/live/device_live/form.html.heex +++ b/lib/towerops_web/live/device_live/form.html.heex @@ -92,15 +92,56 @@ <% end %>
- Enable SNMP to discover device details, monitor sensors, and track interface statistics. -
- - <.input field={@form[:snmp_enabled]} type="checkbox" label="Enable SNMP Monitoring" /> ++ Monitor device availability with ICMP pings and collect detailed information via SNMP + (interfaces, sensors, system info). +
+ <% else %> +Monitor device availability with ICMP pings only (no SNMP discovery).
+ <% end %> +