Skip to content
Snippets Groups Projects
Commit 5c24f7ed authored by Erik Reid's avatar Erik Reid
Browse files

add individual interface records for snmp indexes

... optimization for lookup performance
parent c623ee82
No related branches found
No related tags found
No related merge requests found
......@@ -89,23 +89,37 @@ class InventoryTask(Task):
@log_task_entry_and_exit
def snmp_refresh_interfaces(self, hostname, community):
try:
value = list(snmp.get_router_snmp_indexes(hostname, community))
interfaces = list(snmp.get_router_snmp_indexes(hostname, community))
except ConnectionError:
msg = f'error loading snmp data from {hostname}'
logger.exception(msg)
self.log_warning(msg)
r = get_current_redis(InventoryTask.config)
value = r.get(f'snmp-interfaces:{hostname}')
if not value:
interfaces = r.get(f'snmp-interfaces:{hostname}')
if not interfaces:
raise InventoryTaskError(
f'snmp error with {hostname}'
f' and no cached netconf data found')
# unnecessary json encode/decode here ... could be optimized
value = json.loads(value.decode('utf-8'))
interfaces = json.loads(interfaces.decode('utf-8'))
self.log_warning(f'using cached snmp data for {hostname}')
r = get_next_redis(InventoryTask.config)
r.set(f'snmp-interfaces:{hostname}', json.dumps(value))
rp = r.pipeline()
rp.set(f'snmp-interfaces:{hostname}', json.dumps(interfaces))
# optimization for DBOARD3-372
# interfaces is a list of dicts like: {'name': str, 'index': int}
for ifc in interfaces:
ifc['hostname'] = hostname
ifc['community'] = community
rp.set(
f'snmp-interfaces:{hostname}:{ifc["name"]}',
json.dumps(ifc))
rp.execute()
self.log_info(f'snmp info loaded from {hostname}')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment