Improves error detection

This commit is contained in:
Pierre Lannoy 2024-03-12 10:15:12 +01:00
commit fca0507c8b
Signed by: Pierre Lannoy
GPG key ID: D27231EF87D53F31

View file

@ -13,7 +13,6 @@ class LLDP():
else:
self.output = subprocess.getoutput('lldpctl -f keyvalue')
self.data = None #self.parse()
self.output = None
def parse(self):
output_dict = {}
@ -53,14 +52,16 @@ class LLDP():
def get_switch_ip(self, interface):
# lldp.eth0.chassis.mgmt-ip=100.66.7.222
#return None
if self.data is None:
return None
if self.data['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
#return None
if self.data is None:
return None
if self.data['lldp'].get(interface) is None:
return None
if self.data['lldp'][interface]['port'].get('ifname'):
@ -69,7 +70,8 @@ class LLDP():
def get_switch_vlan(self, interface):
# lldp.eth0.vlan.vlan-id=296
#return None
if self.data is None:
return None
if self.data['lldp'].get(interface) is None:
return None
return self.data['lldp'][interface]['vlan']