From 9a813d3324c2dae32fcfd690591a9e31cdad649d Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 20 Jan 2006 23:10:33 +0000 Subject: Initial import --- tools/rrdui-collect.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tools/rrdui-collect.py (limited to 'tools/rrdui-collect.py') 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) + + + -- cgit v1.2.3