diff options
author | Stef Walter <stef@memberwebs.com> | 2006-03-01 01:32:52 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2006-03-01 01:32:52 +0000 |
commit | c6e0f00687bcef76d2ce325e9489aba9b3c3da2a (patch) | |
tree | 3167640c0c048c44f64070eb8b55d83ef48cb7e1 /tools | |
parent | 9da991ea5f6d5b02ee22c1d87f95d989efde4b30 (diff) |
Add support to rrdui from reading configs and rrds from subdirectories.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/rrdui-cgi.py | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/tools/rrdui-cgi.py b/tools/rrdui-cgi.py index fc58608..7390547 100755 --- a/tools/rrdui-cgi.py +++ b/tools/rrdui-cgi.py @@ -5,8 +5,6 @@ import sets, cgi, shlex import ConfigParser import rrdtool -from rrdui import * - # TODO: Temporary if not os.environ.has_key("CONFDIR") or not os.environ.has_key("WORKDIR"): raise "not setup properly. CONFDIR and WORKDIR env variables must be set" @@ -14,6 +12,10 @@ if not os.environ.has_key("CONFDIR") or not os.environ.has_key("WORKDIR"): CONFDIR = os.environ["CONFDIR"] WORKDIR = os.environ["WORKDIR"] +# We always have this as our current directory. +# It helps when constructing graphs and the like +os.chdir(WORKDIR) + class GraphDef: filename = None filedata = None @@ -24,6 +26,7 @@ class GraphDef: commands = "" category = "" name = "" + valid = False __config = None @@ -32,6 +35,7 @@ class GraphDef: self.filedata = "%s/%s.rrd" % (WORKDIR, name) self.category = "All" self.name = name + self.valid = False cfg = self.__config = ConfigParser.RawConfigParser() cfg.read(self.filename) @@ -43,15 +47,17 @@ class GraphDef: self.category = cfg.get("general", "category") # 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") + if cfg.has_section("graph"): + if not cfg.has_option("graph", "commands"): + raise "Missing commands attribute in: %s" % self.filename + self.commands = cfg.get("graph", "commands") + 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") + self.valid = True def getCreateInfo(self): @@ -92,14 +98,16 @@ class GraphDef: return (fields, interval) -def loadGraphs(): +def loadGraphs(path = ""): # List files and add appropriate paths graphs = [] - for file in os.listdir(CONFDIR): - if os.path.isdir(file): + for file in os.listdir(CONFDIR + "/" + path): + if os.path.isdir(CONFDIR + "/" + path + file): + if file != "." and file != "..": + graphs.extend(loadGraphs(path + file + "/")) continue - graphs.append(GraphDef(file)) + graphs.append(GraphDef(path + file)) return graphs @@ -108,6 +116,8 @@ def listGraphs(): graphs = loadGraphs() categories = {} for item in graphs: + if not item.valid: + continue if not categories.has_key(item.category): categories[item.category] = [] categories[item.category].append(item) |