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:
parent
bdbe809bab
commit
a52f5a8644
1 changed files with 7 additions and 1 deletions
|
|
@ -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)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue