summaryrefslogtreecommitdiff
path: root/tools/rrdui-collect.py
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2006-01-20 23:10:33 +0000
committerStef Walter <stef@memberwebs.com>2006-01-20 23:10:33 +0000
commit9a813d3324c2dae32fcfd690591a9e31cdad649d (patch)
tree2b96e4e2008143f261721187293c2b517285400a /tools/rrdui-collect.py
Initial import
Diffstat (limited to 'tools/rrdui-collect.py')
-rw-r--r--tools/rrdui-collect.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tools/rrdui-collect.py b/tools/rrdui-collect.py
new file mode 100644
index 0000000..892fdf8
--- /dev/null
+++ b/tools/rrdui-collect.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+
+import os, sys, time
+import rrdtool
+
+from rrdui import *
+
+def readItemValue(host, community, oid):
+
+ cmd = "snmpget -c %s -Ov -OQ -v 2c %s %s" % (community, host, oid)
+ p = os.popen(cmd, "r")
+ out = p.read()
+ (pid, status) = os.wait()
+ status = status >> 8
+
+ try:
+ p.close()
+ except IOError:
+ pass
+
+ if status != 0:
+ print "Couldn't query %s for %s" % (host, oid) # XXXXXX
+ out = "U"
+
+ return out.strip()
+
+
+def updateItems(graphs):
+ for item in graphs:
+ if not os.path.exists(item.filedata):
+ continue
+
+ (fields, interval) = item.getPollingInfo()
+
+ values = {}
+ for fieldname in fields.keys():
+ info = fields[fieldname].split(":")
+ if len(info) != 4:
+ raise "Bad src format" # XXXXXXXXX
+ if info[0] != "SNMP":
+ raise "Unknown src method: %s" % info[0] # XXXXXXXXX
+
+ value = readItemValue(host = info[1], community = info[2], oid = info[3])
+ values[fieldname] = value
+
+ print ":".join(values.keys()), ":".join(values.values())
+ args = [item.filedata, "--template", ":".join(values.keys()),
+ "N:%s" % ":".join(values.values())]
+ rrdtool.update(*args)
+
+
+graphs = loadGraphs()
+while True:
+ updateItems(graphs)
+ # TODO: Work out the interval stuff. for now all at 10 seconds
+ time.sleep(10)
+
+
+