fix: remove double SNMP connect and use JoinHostPort for DNS server

- LLDP: remove redundant client.Connect() since newSnmpConn already connects
- DNS check: use net.JoinHostPort for IPv6-safe DNS server addressing
This commit is contained in:
Graham McIntire 2026-03-05 12:29:02 -06:00
parent 7606c0aa6c
commit b4f3dabe8d
No known key found for this signature in database
2 changed files with 2 additions and 7 deletions

View file

@ -189,7 +189,7 @@ func executeDNSCheck(ctx context.Context, config *pb.DnsCheckConfig, timeoutMs u
PreferGo: true,
Dial: func(ctx context.Context, network, address string) (net.Conn, error) {
d := net.Dialer{Timeout: timeout}
return d.DialContext(ctx, "udp", config.Server+":53")
return d.DialContext(ctx, "udp", net.JoinHostPort(config.Server, "53"))
},
}
}

View file

@ -36,7 +36,7 @@ func executeLldpTopologyJob(ctx context.Context, job *pb.AgentJob, resultCh chan
snmpDev := job.SnmpDevice
client, err := newSnmpConn(snmpDev)
if err != nil {
slog.Error("failed to create SNMP client for LLDP", "job_id", jobID, "device_id", deviceID, "error", err)
slog.Error("failed to connect SNMP for LLDP", "job_id", jobID, "device_id", deviceID, "error", err)
return
}
defer func() {
@ -45,11 +45,6 @@ func executeLldpTopologyJob(ctx context.Context, job *pb.AgentJob, resultCh chan
}
}()
if err := client.Connect(); err != nil {
slog.Error("SNMP connect failed for LLDP", "job_id", jobID, "device_id", deviceID, "error", err)
return
}
result, err := discoverLldpNeighbors(client, deviceID, jobID)
if err != nil {
slog.Error("LLDP discovery failed", "job_id", jobID, "device_id", deviceID, "error", err)