diff options
author | Stef Walter <stef@memberwebs.com> | 2006-01-20 23:10:33 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2006-01-20 23:10:33 +0000 |
commit | 9a813d3324c2dae32fcfd690591a9e31cdad649d (patch) | |
tree | 2b96e4e2008143f261721187293c2b517285400a /tools/rrdui.py |
Initial import
Diffstat (limited to 'tools/rrdui.py')
-rw-r--r-- | tools/rrdui.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/tools/rrdui.py b/tools/rrdui.py new file mode 100644 index 0000000..ee10eae --- /dev/null +++ b/tools/rrdui.py @@ -0,0 +1,96 @@ +import os, sys, time +import ConfigParser + +# TODO: Temporary +CONFDIR = "/data/projects/rrdui/conf" +WORKDIR = "/data/projects/rrdui/work" + +class GraphDef: + filename = None + filedata = None + title = "" + height = 0 + width = 0 + options = "" + commands = "" + category = "" + name = "" + + __config = None + + def __init__(self, category, name): + self.filename = "%s/%s/%s" % (CONFDIR, category, name) + self.filedata = "%s/%s-%s.rrd" % (WORKDIR, category, name) + self.category = category + self.name = name + + cfg = self.__config = ConfigParser.RawConfigParser() + cfg.read(self.filename) + + # Loading general stuff + if cfg.has_option("general", "title"): + self.title = cfg.get("general", "title") + + # Loading graph stuff + if cfg.has_option("graph", "width"): + self.width = int(cfg.get("graph", "width")) + if cfg.has_option("graph", "height"): + self.height = int(cfg.get("graph", "height")) + if cfg.has_option("graph", "options"): + self.options = cfg.get("graph", "options") + if not cfg.has_option("graph", "commands"): + raise "Missing commands attribute in: %s" % self.filename + self.commands = cfg.get("graph", "commands") + + + def getCreateInfo(self): + cfg = self.__config + rra = None + fields = {} + + # The RRA info + if cfg.has_option("create", "rra"): + rra = cfg.get("create", "rra").split() + + # The various fields + for field in cfg.options("create"): + if not field.startswith("field."): + continue + fieldname = field[6:] + fields[fieldname] = cfg.get("create", field) + + return (fields, rra) + + + def getPollingInfo(self): + cfg = self.__config + interval = 300 + fields = {} + + # The interval + if cfg.has_option("poll", "interval"): + interval = int(cfg.get("poll", "interval")) + + # The various fields + for field in cfg.options("poll"): + if not field.startswith("field."): + continue + fieldname = field[6:] + fields[fieldname] = cfg.get("poll", field) + + return (fields, interval) + + +def loadGraphs(): + + # List files and add appropriate paths + graphs = [] + for category in os.listdir(CONFDIR): + dir = "%s/%s" % (CONFDIR, category) + if not os.path.isdir(dir): + continue + for f in os.listdir(dir): + graphs.append(GraphDef(category, f)) + return graphs + + |