diff --git a/inventory_provider/snmp.py b/inventory_provider/snmp.py index 5d5884031192fc05be4afe584f9e0bebc02c70d0..9492c27dbe293a76f08323135480fa5cf1e803e5 100644 --- a/inventory_provider/snmp.py +++ b/inventory_provider/snmp.py @@ -68,12 +68,12 @@ def walk(agent_hostname, community, base_oid): yield {"oid": "." + str(oid), "value": val.prettyPrint()} -def get_router_interfaces(router, config): +def get_router_interfaces(hostname, community, config): oid_map = config["oids"] details = {} for name, oid in oid_map.items(): - details[name] = walk(router["hostname"], router["community"], oid) + details[name] = walk(hostname, community, oid) details[name] = list(details[name]) v4IfcNames = {} diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 55fa8614831f455d7eaf21f5bcc6e0d39156df42..da8dbd85c774acfbfe00795daf3e104b4341e1ac 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -5,7 +5,7 @@ import redis from inventory_provider.tasks.app import app from inventory_provider import config -from inventory_provider import juniper +from inventory_provider import juniper, snmp class InventoryTask(Task): @@ -69,3 +69,10 @@ def juniper_refresh_interfaces(self, hostname): "interfaces", juniper.fetch_interfaces(hostname, InventoryTask.config["ssh"])) + +@app.task(bind=InventoryTask) +def snmp_refresh_interfaces(self, hostname, community): + InventoryTask.save_key( + hostname, + "interfaces", + list(snmp.get_router_interfaces(hostname, community, InventoryTask.config)))