fix: handle nil SNMP community string in discovery logging

- Check if community string is nil before slicing
- Display '(none)' instead of crashing with FunctionClauseError
- Fixes discovery crashes when community string is not set

Error was: String.slice(nil, 0..3) causing discovery tasks to fail
This commit is contained in:
Graham McIntire 2026-03-10 13:57:49 -05:00
parent bdbe809bab
commit a52f5a8644
No known key found for this signature in database

View file

@ -181,12 +181,18 @@ defmodule Towerops.Snmp.DeferredDiscovery do
port = Keyword.get(client_opts, :port, 161)
adapter = Keyword.get(client_opts, :adapter, "Real SNMP")
# Safely format community string (may be nil)
community_display =
if community && String.length(community) > 0,
do: String.slice(community, 0..3) <> "***",
else: "(none)"
Logger.warning(
"Device #{ip} categorized as unresponsive - SNMP GET failed",
ip: ip,
port: port,
version: version,
community: String.slice(community, 0..3) <> "***",
community: community_display,
adapter: inspect(adapter),
error: inspect(reason)
)