fix: infer device role during discovery and handle string price values

Device Type Fix:
- Add Topology.maybe_update_device_role() call after discovery completes
- Device types (AP, router, switch, etc.) now inferred immediately after discovery
- Previously devices showed 'unknown' until first polling cycle completed
- Role inference uses SNMP manufacturer, model, and system description

Billing Fix:
- Handle string values from Settings.get_setting() in default_price_per_device()
- Add case clause to convert string '2.00' to Decimal struct
- Fixes CaseClauseError crash on /orgs/:slug/settings page

All discovery tests passing.
This commit is contained in:
Graham McIntire 2026-03-10 13:25:51 -05:00
parent 4e6a038fb5
commit 62eb7f9949
No known key found for this signature in database
2 changed files with 6 additions and 0 deletions

View file

@ -39,6 +39,7 @@ defmodule Towerops.Billing do
case Settings.get_setting("default_price_per_device") do
nil -> @default_price_per_device
%Decimal{} = decimal -> decimal
string when is_binary(string) -> Decimal.new(string)
end
end

View file

@ -33,6 +33,7 @@ defmodule Towerops.Snmp.Discovery do
alias Towerops.Snmp.Sensor
alias Towerops.Snmp.Storage
alias Towerops.Snmp.Vlan
alias Towerops.Topology
alias Towerops.Workers.DiscoveryWorker
require Logger
@ -276,6 +277,10 @@ defmodule Towerops.Snmp.Discovery do
{:ok, check_counts} = Towerops.Snmp.create_checks_from_discovery(device, discovered_device)
log_check_creation_results(device.id, check_counts)
# Infer and update device role from SNMP data
Logger.info("Inferring device role...", device_id: device.id)
_ = Topology.maybe_update_device_role(device)
_ =
Phoenix.PubSub.broadcast(
Towerops.PubSub,