From 605ad82eda261cb586b351547e4e97d94d33d25f Mon Sep 17 00:00:00 2001 From: Mathis Ribet Date: Fri, 11 Oct 2024 10:15:43 +0200 Subject: [PATCH] Gracefully handle neighbor-less devices --- netbox_agent/lldp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox_agent/lldp.py b/netbox_agent/lldp.py index 21b645f..0581ff9 100644 --- a/netbox_agent/lldp.py +++ b/netbox_agent/lldp.py @@ -52,13 +52,13 @@ class LLDP(): def get_switch_ip(self, interface): # lldp.eth0.chassis.mgmt-ip=100.66.7.222 - if self.data['lldp'].get(interface) is None: + if self.data.get("lldp", {}).get(interface) is None: return None return self.data['lldp'][interface]['chassis'].get('mgmt-ip') def get_switch_port(self, interface): # lldp.eth0.port.descr=GigabitEthernet1/0/1 - if self.data['lldp'].get(interface) is None: + if self.data.get("lldp", {}).get(interface) is None: return None if self.data['lldp'][interface]['port'].get('ifname'): return self.data['lldp'][interface]['port']['ifname'] @@ -66,6 +66,6 @@ class LLDP(): def get_switch_vlan(self, interface): # lldp.eth0.vlan.vlan-id=296 - if self.data['lldp'].get(interface) is None: + if self.data.get("lldp", {}).get(interface) is None: return None return self.data['lldp'][interface]['vlan']