From 9999e5901866ca87e8c0415f464d1d9faf7091a4 Mon Sep 17 00:00:00 2001 From: sebastien-coavoux <60757725+sebastien-coavoux@users.noreply.github.com> Date: Tue, 2 May 2023 04:42:53 -0400 Subject: [PATCH] Treat Bits as OctetString (#870) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sébastien Coavoux --- collector/collector.go | 2 +- collector/collector_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/collector/collector.go b/collector/collector.go index 1c8366a1..f2f09956 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -725,7 +725,7 @@ func pduValueAsString(pdu *gosnmp.SnmpPDU, typ string) string { // DisplayString. return pdu.Value.(string) case []byte: - if typ == "" { + if typ == "" || typ == "Bits" { typ = "OctetString" } // Reuse the OID index parsing code. diff --git a/collector/collector_test.go b/collector/collector_test.go index a55bc7b0..c424d8a9 100644 --- a/collector/collector_test.go +++ b/collector/collector_test.go @@ -701,6 +701,11 @@ func TestPduValueAsString(t *testing.T) { typ: "InetAddressIPv6", result: "0102:0304:0506:0708:090A:0B0C:0D0E:0F10", }, + { + pdu: &gosnmp.SnmpPDU{Value: []byte{2, 0}}, + typ: "Bits", + result: "0x0200", + }, { pdu: &gosnmp.SnmpPDU{Value: nil}, result: "",