1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""GraphPoint
15
16 Defines attributes for how a data source will be graphed
17 and builds the nessesary rrd commands.
18 """
19
20 import os
21
22 from Globals import InitializeClass
23 from AccessControl import ClassSecurityInfo, Permissions
24 from Products.ZenRelations.RelSchema import *
25 from ZenModelRM import ZenModelRM
26 from ZenPackable import ZenPackable
27
28
37
38
40 '''
41 '''
42
43 isThreshold = False
44
45 DEFAULT_FORMAT = '%5.2lf%s'
46 DEFAULT_LEGEND = '${graphPoint/id}'
47 DEFAULT_MULTIGRAPH_LEGEND = '${here/name | here/id} ${graphPoint/id}'
48
49 sequence = 0
50 _properties = (
51 {'id':'sequence', 'type':'long', 'mode':'w'},
52 )
53
54 _relations = ZenPackable._relations + (
55 ("graphDef", ToOne(ToManyCont,"Products.ZenModel.GraphDefinition","graphPoints")),
56 )
57
58 factory_type_information = (
59 {
60 'immediate_view' : 'editGraphPoint',
61 'actions' :
62 (
63 { 'id' : 'edit'
64 , 'name' : 'Graph Point'
65 , 'action' : 'editGraphPoint'
66 , 'permissions' : ( Permissions.view, )
67 },
68 )
69 },
70 )
71
72 colors = (
73 '#00cc00', '#0000ff', '#00ffff', '#ff0000',
74 '#ffff00', '#cc0000', '#0000cc', '#0080c0',
75 '#8080c0', '#ff0080', '#800080', '#0000a0',
76 '#408080', '#808000', '#000000', '#00ff00',
77 '#fb31fb', '#0080ff', '#ff8000', '#800000',
78 )
79
80
81
82
83
93
94
101
102
104 ''' Return a description
105 '''
106 return self.id
107
108
109 - def getTalesContext(self, thing=None, **kw):
110 '''
111 Standard stuff to add to context for tales expressions
112 '''
113 context = {
114 'graphDef': self.graphDef(),
115 'graphPoint': self,
116 }
117 if thing:
118 if thing.meta_type == 'Device':
119 context['dev'] = thing
120 context['devId'] = thing.id
121 else:
122 context['comp'] = thing
123 context['compId'] = thing.id
124 context['compName'] = thing.name()
125 context['dev'] = thing.device()
126 context['devId'] = thing.device().id
127 for key, value in kw.items():
128 context[key] = value
129 return context
130
131
143
144
145
146
152
153
159
160
161 - def getGraphCmds(self, cmds, context, rrdDir, addSummary, idx,
162 multiid=-1, prefix=''):
163 ''' Build the graphing commands for this graphpoint
164 '''
165 return cmds
166
167
168 - def getDsName(self, base, multiid=-1, prefix=''):
173
174
176 ''' If not base then return ''
177 elif prefix then return prefix_base
178 else return base
179 The result is rrd scrubbed
180 '''
181 s = base or ''
182 if s and prefix:
183 s = '_'.join((prefix, base))
184 s = self.scrubForRRD(s)
185 return s
186
187
189 ''' scrub value so it is a valid rrd variable name. If namespace
190 is provided then massage value as needed to avoid name conflicts
191 with items in namespace.
192 '''
193 import string
194 import itertools
195 def Scrub(c):
196 if c not in string.ascii_letters + string.digits + '_-':
197 c = '_'
198 return c
199 value = ''.join([Scrub(c) for c in value])
200 if namespace:
201 postfixIter = itertools.count(2)
202 candidate = value
203 while candidate in namespace:
204 candidate = value + str(postfixIter.next())
205 value = candidate
206 return value
207
208
210 '''
211 Escapes characters like colon ':' for use by RRDTool which would
212 '''
213 value = value.replace(":", "\:")
214 return value
215
216
217 InitializeClass(GraphPoint)
218