From 6717b43cc985f363fe309085a81b112a7df9a3e2 Mon Sep 17 00:00:00 2001 From: ChrNic Date: Mon, 4 Apr 2022 09:05:42 +0200 Subject: [PATCH 1/6] Solves if raidcard have no discs --- netbox_agent/raid/hp.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/netbox_agent/raid/hp.py b/netbox_agent/raid/hp.py index 82d3c06..a5cc723 100644 --- a/netbox_agent/raid/hp.py +++ b/netbox_agent/raid/hp.py @@ -10,7 +10,6 @@ REGEXP_CONTROLLER_HP = re.compile(r'Smart Array ([a-zA-Z0-9- ]+) in Slot ([0-9]+ class HPRaidControllerError(Exception): pass - def ssacli(sub_command): command = ["ssacli"] command.extend(sub_command.split()) @@ -21,16 +20,19 @@ def ssacli(sub_command): ) p.wait() stdout = p.stdout.read().decode("utf-8") - if p.returncode != 0: + if p.returncode == 1 and stdout.find('does not have any physical') == -1: mesg = "Failed to execute command '{}':\n{}".format( " ".join(command), stdout ) raise HPRaidControllerError(mesg) - lines = stdout.split('\n') - lines = list(filter(None, lines)) + else: + if stdout.find('does not have any physical') != -1: + return list() + else: + lines = stdout.split('\n') + lines = list(filter(None, lines)) return lines - def _parse_ctrl_output(lines): controllers = {} current_ctrl = None -- 2.47.2 From 2f23844dfda599500b9d7fe5bea3b36e05215a5f Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Mon, 4 Apr 2022 10:51:18 +0200 Subject: [PATCH 2/6] fix: hp raid, prevent us to miss some errors when matching only returncode 1 Signed-off-by: Cyril Levis --- netbox_agent/raid/hp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox_agent/raid/hp.py b/netbox_agent/raid/hp.py index a5cc723..c8e0df8 100644 --- a/netbox_agent/raid/hp.py +++ b/netbox_agent/raid/hp.py @@ -20,13 +20,13 @@ def ssacli(sub_command): ) p.wait() stdout = p.stdout.read().decode("utf-8") - if p.returncode == 1 and stdout.find('does not have any physical') == -1: + if p.returncode != 0 and 'does not have any physical' not in stdout: mesg = "Failed to execute command '{}':\n{}".format( " ".join(command), stdout ) raise HPRaidControllerError(mesg) else: - if stdout.find('does not have any physical') != -1: + if 'does not have any physical' in stdout: return list() else: lines = stdout.split('\n') -- 2.47.2 From be770a947a85d29c832a063d08a23bc484f15dbc Mon Sep 17 00:00:00 2001 From: illes Date: Mon, 20 Jun 2022 13:13:31 +0200 Subject: [PATCH 3/6] Fix for missing mgmt-ip in LLDP output (#225) --- netbox_agent/lldp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_agent/lldp.py b/netbox_agent/lldp.py index 51083f5..7b991d5 100644 --- a/netbox_agent/lldp.py +++ b/netbox_agent/lldp.py @@ -53,7 +53,7 @@ class LLDP(): # lldp.eth0.chassis.mgmt-ip=100.66.7.222 if self.data['lldp'].get(interface) is None: return None - return self.data['lldp'][interface]['chassis']['mgmt-ip'] + return self.data['lldp'][interface]['chassis'].get('mgmt-ip') def get_switch_port(self, interface): # lldp.eth0.port.descr=GigabitEthernet1/0/1 -- 2.47.2 From 0cff7d3477dd1aa9e97bdeba5da919ca3b74b1fe Mon Sep 17 00:00:00 2001 From: illes Date: Mon, 18 Jul 2022 22:06:33 +0200 Subject: [PATCH 4/6] Fix module platform has no attribute linux_distribution (#224) --- netbox_agent/misc.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/netbox_agent/misc.py b/netbox_agent/misc.py index 6e7e92d..8672cad 100644 --- a/netbox_agent/misc.py +++ b/netbox_agent/misc.py @@ -32,12 +32,17 @@ def get_device_type(type): def get_device_platform(device_platform): if device_platform is None: try: - import platform + # Python 3.8+ moved linux_distribution() to distro + try: + import distro + linux_distribution = " ".join(distro.linux_distribution()) + except ImportError: + import platform + linux_distribution = " ".join(platform.linux_distribution()) - linux_distribution = " ".join(platform.linux_distribution()) if not linux_distribution: return None - except (ModuleNotFoundError, NameError): + except (ModuleNotFoundError, NameError, AttributeError): return None else: linux_distribution = device_platform -- 2.47.2 From ea66becd3d304872bef34827914f162238b9fce2 Mon Sep 17 00:00:00 2001 From: DeathRabbit679 <37566060+DeathRabbit679@users.noreply.github.com> Date: Mon, 18 Jul 2022 15:08:03 -0500 Subject: [PATCH 5/6] Use platform id instead of record (#231) --- netbox_agent/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_agent/server.py b/netbox_agent/server.py index f7008bf..bdc1407 100644 --- a/netbox_agent/server.py +++ b/netbox_agent/server.py @@ -274,7 +274,7 @@ class ServerBase(): serial=serial, device_role=device_role.id, device_type=device_type.id, - platform=self.device_platform, + platform=self.device_platform.id, site=datacenter.id if datacenter else None, tenant=tenant.id if tenant else None, rack=rack.id if rack else None, -- 2.47.2 From 838ffd8e410b05cd3dba9a94fefc6a63a794ebbf Mon Sep 17 00:00:00 2001 From: ChrNic Date: Thu, 21 Jul 2022 08:32:24 +0200 Subject: [PATCH 6/6] using dynamic ref to NIC --- netbox_agent/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_agent/network.py b/netbox_agent/network.py index fb97409..500dc95 100644 --- a/netbox_agent/network.py +++ b/netbox_agent/network.py @@ -214,7 +214,7 @@ class Network(object): lldp_vlan = self.lldp.get_switch_vlan(nic['name']) if config.network.lldp else None # For strange reason, we need to get the object from scratch # The object returned by pynetbox's save isn't always working (since pynetbox 6) - interface = nb.dcim.interfaces.get(id=interface.id) + interface = self.nb_net.interfaces.get(id=interface.id) # Handle the case were the local interface isn't an interface vlan as reported by Netbox # and that LLDP doesn't report a vlan-id -- 2.47.2