Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion fixtures/test/appl_db_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@
"LLDP_ENTRY_TABLE:Ethernet88": {
"lldp_rem_chassis_id": "74:86:e2:6d:df:a5",
"lldp_rem_man_addr": "192.168.240.123",
"lldp_rem_port_desc": "Ethernet88",
"lldp_rem_port_id": "hundredGigE1/23",
"lldp_rem_port_id_subtype": "7",
"lldp_rem_sys_name": "net-tor-lab001.lau1"
},
"LLDP_ENTRY_TABLE:eth0": {
"lldp_rem_chassis_id": "00:11:22:33:44:55",
"lldp_rem_man_addr": "192.168.240.1",
"lldp_rem_port_id": "mgmt0",
"lldp_rem_port_desc": "ge-0/0/15.0",
"lldp_rem_port_id": "535",
"lldp_rem_port_id_subtype": "7",
"lldp_rem_sys_name": "oob-switch01"
},
"LLDP_ENTRY_TABLE:Ethernet0": {
Expand Down
4 changes: 2 additions & 2 deletions internal/collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ func TestLldpCollector(t *testing.T) {
`

neighborExpected := `
sonic_lldp_neighbor_info{local_interface="Ethernet88",local_role="frontpanel",remote_chassis_id="74:86:e2:6d:df:a5",remote_mgmt_ip="192.168.240.123",remote_port_id="hundredGigE1/23",remote_system_name="net-tor-lab001.lau1"} 1
sonic_lldp_neighbor_info{local_interface="eth0",local_role="management",remote_chassis_id="00:11:22:33:44:55",remote_mgmt_ip="192.168.240.1",remote_port_id="mgmt0",remote_system_name="oob-switch01"} 1
sonic_lldp_neighbor_info{local_interface="Ethernet88",local_role="frontpanel",remote_chassis_id="74:86:e2:6d:df:a5",remote_mgmt_ip="192.168.240.123",remote_port_desc="Ethernet88",remote_port_display="Ethernet88",remote_port_id="hundredGigE1/23",remote_port_id_subtype="7",remote_system_name="net-tor-lab001.lau1"} 1
sonic_lldp_neighbor_info{local_interface="eth0",local_role="management",remote_chassis_id="00:11:22:33:44:55",remote_mgmt_ip="192.168.240.1",remote_port_desc="ge-0/0/15.0",remote_port_display="ge-0/0/15.0",remote_port_id="535",remote_port_id_subtype="7",remote_system_name="oob-switch01"} 1
`

if err := testutil.CollectAndCompare(lldpCollector, strings.NewReader(neighborMetadata+neighborExpected), "sonic_lldp_neighbor_info"); err != nil {
Expand Down
24 changes: 22 additions & 2 deletions internal/collector/lldp_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewLldpCollector(logger *slog.Logger) *lldpCollector {

collector := &lldpCollector{
lldpNeighborInfo: prometheus.NewDesc(prometheus.BuildFQName(namespace, subsystem, "neighbor_info"),
"Non-numeric data about LLDP neighbor, value is always 1", []string{"local_interface", "local_role", "remote_system_name", "remote_port_id", "remote_chassis_id", "remote_mgmt_ip"}, nil),
"Non-numeric data about LLDP neighbor, value is always 1", []string{"local_interface", "local_role", "remote_system_name", "remote_port_id", "remote_port_desc", "remote_port_id_subtype", "remote_port_display", "remote_chassis_id", "remote_mgmt_ip"}, nil),
lldpNeighbors: prometheus.NewDesc(prometheus.BuildFQName(namespace, subsystem, "neighbors"),
"Number of LLDP neighbors exported", nil, nil),
scrapeDuration: prometheus.NewDesc(prometheus.BuildFQName(namespace, subsystem, "scrape_duration_seconds"),
Expand Down Expand Up @@ -202,10 +202,13 @@ func (collector *lldpCollector) scrapeMetrics(ctx context.Context) ([]prometheus

remoteSystemName := lldpData["lldp_rem_sys_name"]
remotePortID := lldpData["lldp_rem_port_id"]
remotePortDesc := lldpData["lldp_rem_port_desc"]
remotePortIDSubtype := lldpData["lldp_rem_port_id_subtype"]
remotePortDisplay := resolvedRemotePortDisplay(remotePortID, remotePortDesc, remotePortIDSubtype)
remoteChassisID := lldpData["lldp_rem_chassis_id"]
remoteMgmtIP := lldpData["lldp_rem_man_addr"]

if remoteSystemName == "" && remotePortID == "" && remoteChassisID == "" && remoteMgmtIP == "" {
if remoteSystemName == "" && remotePortID == "" && remotePortDesc == "" && remoteChassisID == "" && remoteMgmtIP == "" {
skippedEntries++
continue
}
Expand All @@ -223,6 +226,9 @@ func (collector *lldpCollector) scrapeMetrics(ctx context.Context) ([]prometheus
localRole,
remoteSystemName,
remotePortID,
remotePortDesc,
remotePortIDSubtype,
remotePortDisplay,
remoteChassisID,
remoteMgmtIP,
))
Expand Down Expand Up @@ -297,3 +303,17 @@ func parseIntEnv(logger *slog.Logger, key string, defaultValue int) int {

return parsedValue
}

func resolvedRemotePortDisplay(remotePortID, remotePortDesc, remotePortIDSubtype string) string {
subtype := strings.ToLower(strings.TrimSpace(remotePortIDSubtype))

if remotePortDesc != "" && (subtype == "7" || subtype == "local" || subtype == "3" || subtype == "mac") {
return remotePortDesc
}

if remotePortID != "" {
return remotePortID
}

return remotePortDesc
}
Loading