1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
|