From 5484f87b3296fc67034ae316b414e474447aefed Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Fri, 16 Nov 2018 14:54:16 +0100
Subject: [PATCH] add snmp interface query task

---
 inventory_provider/snmp.py         | 4 ++--
 inventory_provider/tasks/worker.py | 9 ++++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/inventory_provider/snmp.py b/inventory_provider/snmp.py
index 5d588403..9492c27d 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 55fa8614..da8dbd85 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)))
-- 
GitLab