Improves error detection

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

View file

@ -6,13 +6,13 @@ from netbox_agent.misc import is_tool
class LLDP():
def __init__(self, output=None):
if not is_tool('alldpctl'):
if not is_tool('lldpctl'):
logging.debug('lldpd package seems to be missing or daemon not running.')
if output:
self.output = output
else:
self.output = subprocess.getoutput('lldpctl -f keyvalue')
self.data = self.parse()
self.data = None #self.parse()
def parse(self):
output_dict = {}
@ -52,14 +52,14 @@ class LLDP():
def get_switch_ip(self, interface):
# lldp.eth0.chassis.mgmt-ip=100.66.7.222
return 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
#return None
if self.data['lldp'].get(interface) is None:
return None
if self.data['lldp'][interface]['port'].get('ifname'):
@ -68,7 +68,7 @@ class LLDP():
def get_switch_vlan(self, interface):
# lldp.eth0.vlan.vlan-id=296
return None
#return None
if self.data['lldp'].get(interface) is None:
return None
return self.data['lldp'][interface]['vlan']