From 08360bafbb933bb05583fe409752e53e1078f918 Mon Sep 17 00:00:00 2001 From: Alexander Daichendt Date: Sat, 8 Apr 2023 11:17:23 +0200 Subject: [PATCH] fix: lshw crashes due to duplicate logical name --- netbox_agent/lshw.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/netbox_agent/lshw.py b/netbox_agent/lshw.py index 15ac086..e88993c 100644 --- a/netbox_agent/lshw.py +++ b/netbox_agent/lshw.py @@ -72,9 +72,17 @@ class LSHW(): # Some interfaces do not have device (logical) name (eth0, for # instance), such as not connected network mezzanine cards in blade # servers. In such situations, the card will be named `unknown[0-9]`. - unkn_intfs = [ - i for i in self.interfaces if i["name"].startswith("unknown") - ] + unkn_intfs = [] + for i in self.interfaces: + # newer versions of lshw can return a list of names, see issue #227 + if not isinstance(i["name"], list): + if i["name"].startswith("unknown"): + unkn_intfs.push(i) + else: + for j in i["name"]: + if j.startswith("unknown"): + unkn_intfs.push(j) + unkn_name = "unknown{}".format(len(unkn_intfs)) self.interfaces.append({ "name": obj.get("logicalname", unkn_name),