diff --git a/lib/towerops_web/live/equipment_live/form.ex b/lib/towerops_web/live/equipment_live/form.ex index 2147ec44..89f5bcb8 100644 --- a/lib/towerops_web/live/equipment_live/form.ex +++ b/lib/towerops_web/live/equipment_live/form.ex @@ -98,12 +98,18 @@ defmodule ToweropsWeb.EquipmentLive.Form do equipment_with_agent = Map.put(equipment, :agent_token_id, agent_token_id) changeset = Equipment.change_equipment(equipment, %{}) + # Get effective SNMP configuration and source + snmp_config = Equipment.get_snmp_config(equipment) + socket |> assign(:page_title, "Edit Equipment") |> assign(:equipment, equipment_with_agent) |> assign(:form, to_form(changeset)) |> assign(:agent_source, agent_source) |> assign(:effective_agent_name, effective_agent_name) + |> assign(:snmp_config_source, snmp_config.source) + |> assign(:effective_snmp_version, snmp_config.version) + |> assign(:effective_snmp_community, snmp_config.community || "(not set)") end @impl true diff --git a/lib/towerops_web/live/equipment_live/form.html.heex b/lib/towerops_web/live/equipment_live/form.html.heex index c18f445d..bf127462 100644 --- a/lib/towerops_web/live/equipment_live/form.html.heex +++ b/lib/towerops_web/live/equipment_live/form.html.heex @@ -107,8 +107,7 @@ field={@form[:snmp_version]} type="select" label="SNMP Version" - required - value={@form[:snmp_version].value || "2c"} + prompt="Inherit from site/organization" options={[{"SNMPv1", "1"}, {"SNMPv2c", "2c"}]} /> @@ -116,10 +115,35 @@ field={@form[:snmp_community]} type="text" label="Community String" - required + placeholder="Leave blank to inherit from site/organization" autocomplete="off" /> + <%= if @live_action == :edit and Map.has_key?(assigns, :snmp_config_source) do %> + <%= case @snmp_config_source do %> + <% :equipment -> %> +
+ <.icon name="hero-exclamation-triangle" class="h-4 w-4" /> + Overriding site/organization SNMP defaults +
+ <% :site -> %> ++ <.icon name="hero-building-office" class="h-4 w-4" /> + Inherited from site (v{@effective_snmp_version}, community: {@effective_snmp_community}) +
+ <% :organization -> %> ++ <.icon name="hero-building-office-2" class="h-4 w-4" /> + Inherited from organization (v{@effective_snmp_version}, community: {@effective_snmp_community}) +
+ <% :default -> %> ++ <.icon name="hero-information-circle" class="h-4 w-4" /> + Using default (v2c, no community set - configure at organization or site level) +
+ <% end %> + <% end %> + <.input field={@form[:snmp_port]} type="number" diff --git a/lib/towerops_web/live/org/settings_live.html.heex b/lib/towerops_web/live/org/settings_live.html.heex index 354a1376..aebd635b 100644 --- a/lib/towerops_web/live/org/settings_live.html.heex +++ b/lib/towerops_web/live/org/settings_live.html.heex @@ -23,6 +23,33 @@ <.form for={@form} id="organization-form" phx-change="validate" phx-submit="save"> <.input field={@form[:name]} type="text" label="Organization Name" required /> ++ Set default SNMP settings for all devices in this organization. These can be overridden at the site or equipment level. +
+ + <.input + field={@form[:snmp_version]} + type="select" + label="SNMP Version" + prompt="Select SNMP version" + options={[{"SNMP v1", "1"}, {"SNMP v2c", "2c"}, {"SNMP v3", "3"}]} + /> + + <.input + field={@form[:snmp_community]} + type="text" + label="SNMP Community String" + placeholder="e.g., public" + /> + ++ <.icon name="hero-information-circle" class="h-4 w-4 inline" /> + SNMP configuration hierarchy: Equipment > Site > Organization +
++ Override organization SNMP defaults for all equipment at this site. Leave blank to inherit from organization. +
+ + <.input + field={@form[:snmp_version]} + type="select" + label="SNMP Version" + prompt="Inherit from organization" + options={[{"SNMP v1", "1"}, {"SNMP v2c", "2c"}, {"SNMP v3", "3"}]} + /> + + <.input + field={@form[:snmp_community]} + type="text" + label="SNMP Community String" + placeholder="Leave blank to inherit from organization" + /> +