From 980271b6762233ed29f5cb42c465d24a1cdeb587 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 25 Sep 2025 14:58:50 +0000 Subject: [PATCH] feat: add interface description mapping for snmp discovery --- snmp-discovery/mapping/mappers.go | 7 +++++++ snmp-discovery/mapping/mappers_test.go | 13 +++++++++++++ snmp-discovery/policy/mapping.yaml | 3 +++ 3 files changed, 23 insertions(+) diff --git a/snmp-discovery/mapping/mappers.go b/snmp-discovery/mapping/mappers.go index baf3f1c..6103bf2 100644 --- a/snmp-discovery/mapping/mappers.go +++ b/snmp-discovery/mapping/mappers.go @@ -266,6 +266,13 @@ func (m *InterfaceMapper) Map(values map[ObjectIDIndex]*ObjectIDValue, mappingEn case "name": interfaceEntity.Name = &value.Value fieldFound = true + case "description": + description := strings.TrimRight(value.Value, " \t\n\r") + if len(description) > 200 { + description = description[:197] + "..." + } + interfaceEntity.Description = &description + fieldFound = true case "type": defaultType := "" if defaults != nil && defaults.Interface.Type != "" { diff --git a/snmp-discovery/mapping/mappers_test.go b/snmp-discovery/mapping/mappers_test.go index 0801b12..97fe56e 100644 --- a/snmp-discovery/mapping/mappers_test.go +++ b/snmp-discovery/mapping/mappers_test.go @@ -388,6 +388,13 @@ func TestInterfaceMapper_Map(t *testing.T) { Value: "1", Type: mapping.Integer, }, + "1.3.6.1.2.1.31.1.1.1.18.1": { + OID: "1.3.6.1.2.1.31.1.1.1.18.1", + Index: "1", + Parent: "1.3.6.1.2.1.31.1.1.1.18", + Value: "uplink interface", + Type: mapping.OctetString, + }, }, mappingEntry: &mapping.Entry{ OID: "1.3.6.1.2.1.2.2.1.1", @@ -424,6 +431,11 @@ func TestInterfaceMapper_Map(t *testing.T) { Entity: "interface", Field: "adminStatus", }, + { + OID: "1.3.6.1.2.1.31.1.1.1.18", + Entity: "interface", + Field: "description", + }, }, }, defaults: nil, @@ -433,6 +445,7 @@ func TestInterfaceMapper_Map(t *testing.T) { Mtu: int64Ptr(1500), PrimaryMacAddress: &diode.MACAddress{MacAddress: mapping.StringPtr("00:11:22:33:44:55")}, Enabled: boolPtr(true), + Description: mapping.StringPtr("uplink interface"), }, expectError: false, }, diff --git a/snmp-discovery/policy/mapping.yaml b/snmp-discovery/policy/mapping.yaml index e562c01..f3b06ed 100644 --- a/snmp-discovery/policy/mapping.yaml +++ b/snmp-discovery/policy/mapping.yaml @@ -23,6 +23,9 @@ entries: - oid: ".1.3.6.1.2.1.2.2.1.7" entity: "interface" field: "adminStatus" + - oid: ".1.3.6.1.2.1.31.1.1.1.18" + entity: "interface" + field: "description" # IP Address mappings - oid: ".1.3.6.1.2.1.4.20.1"