From 29bd136ceaf97ede7612c555e6bc3a0e4f4e6d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D1=83=D1=86=D0=B5=D0=BD=D0=BA=D0=BE=20=D0=90=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=B5=D0=B9=20=D0=90=D0=BD=D0=B0=D1=82=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B5=D0=B2=D0=B8=D1=87?= Date: Fri, 10 Apr 2026 14:58:17 +1000 Subject: [PATCH] =?UTF-8?q?fix(snmp):=20OCTET=20STRING=20=D0=B8=D0=B7=206?= =?UTF-8?q?=20=D0=B1=D0=B0=D0=B9=D1=82=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BA=D0=B0=D0=BA=20MAC=20(aa?= =?UTF-8?q?:bb:...),=20=D0=BD=D0=B5=200x...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- internal/scans/runner.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/internal/scans/runner.go b/internal/scans/runner.go index 4f359eb..83a1fbb 100644 --- a/internal/scans/runner.go +++ b/internal/scans/runner.go @@ -203,19 +203,27 @@ func probeSNMPAndLLDP(ip, community string, checkedAt time.Time, timeoutMS int) return out, probeLLDP(client, ip, checkedAt) } +// snmpBytesToDisplay строка для OCTET STRING SNMP: UTF-8 текст, иначе MAC (6 байт) или 0x+hex. +func snmpBytesToDisplay(b []byte) string { + if len(b) == 0 { + return "" + } + if utf8.Valid(b) { + s := strings.TrimSpace(string(b)) + if s != "" { + return s + } + } + // LLDP chassis/port id часто — MAC из 6 байт (не UTF-8). + if len(b) == 6 { + return fmt.Sprintf("%02x:%02x:%02x:%02x:%02x:%02x", b[0], b[1], b[2], b[3], b[4], b[5]) + } + return "0x" + hex.EncodeToString(b) +} + func snmpValueToString(v any) string { if b, ok := v.([]byte); ok { - if len(b) == 0 { - return "" - } - if utf8.Valid(b) { - s := strings.TrimSpace(string(b)) - if s != "" { - return s - } - } - // Chassis ID / port ID в LLDP часто приходят как OCTET STRING (MAC и т.д.) — не UTF-8 - return "0x" + hex.EncodeToString(b) + return snmpBytesToDisplay(b) } return strings.TrimSpace(fmt.Sprint(v)) }