1
2
3
4
5
6
7
8
9
10
11
12
13
14 from Globals import InitializeClass
15 from AccessControl import ClassSecurityInfo
16 from ZenModelRM import ZenModelRM
17 from Products.ZenRelations.RelSchema import *
18 from Products.ZenUtils.ZenTales import talesCompile, getEngine
19 from DateTime import DateTime
20 from RRDView import GetRRDPath
21 from PerformanceConf import performancePath
22 from ZenossSecurity import ZEN_MANAGE_DMD
23
31
32
34
35 meta_type = "MultiGraphReport"
36
37 numColumns = 1
38 numColumnsOptions = (1, 2, 3)
39
40 _properties = ZenModelRM._properties + (
41 {'id':'numColumns', 'type':'int',
42 'select_variable' : 'numColumnOptions', 'mode':'w'},
43 )
44
45 _relations = (
46 ('collections',
47 ToManyCont(ToOne, 'Products.ZenModel.Collection', 'report')),
48 ("graphGroups",
49 ToManyCont(ToOne,"Products.ZenModel.GraphGroup", "report")),
50 ('graphDefs',
51 ToManyCont(ToOne, 'Products.ZenModel.GraphDefinition', 'report')),
52 )
53
54 factory_type_information = (
55 {
56 'immediate_view' : 'viewMultiGraphReport',
57 'actions' :
58 (
59 {'name' : 'Report',
60 'action' : 'viewMultiGraphReport',
61 'permissions' : ("View",),
62 },
63 {'name' : 'Edit',
64 'action' : 'editMultiGraphReport',
65 'permissions' : ("Manage DMD",),
66 },
67 )
68 },
69 )
70
71 security = ClassSecurityInfo()
72
74 '''
75 Return the url to be used in breadcrumbs for this object.
76 '''
77 return self.getPrimaryUrlPath() + '/editMultiGraphReport'
78
79
80
81
82 security.declareProtected('Manage DMD', 'manage_addGraphGroup')
96
97
98 security.declareProtected('Manage DMD', 'manage_deleteGraphGroups')
108
109
110 security.declareProtected('Manage DMD', 'manage_resequenceGraphGroups')
116
117
119 """get the ordered groups
120 """
121 def cmpGroups(a, b):
122 return cmp(a.sequence, b.sequence)
123 groups = [g for g in self.graphGroups()]
124 groups.sort(cmpGroups)
125 return groups
126
127
128
129 security.declareProtected('Manage DMD', 'getCollections')
131 ''' Return an alpha ordered list of available collections
132 '''
133 def cmpCollections(a, b):
134 return cmp(a.id, b.id)
135 collections = self.collections()[:]
136 collections.sort(cmpCollections)
137 return collections
138
139
140 security.declareProtected('Manage DMD', 'manage_addCollection')
152
153 security.declareProtected('Manage DMD', 'manage_deleteCollections')
162
163
164
165
166 security.declareProtected(ZEN_MANAGE_DMD, 'getGraphDefs')
176 graphDefs = self.graphDefs()[:]
177 graphDefs.sort(cmpGraphDefs)
178 return graphDefs
179
180
182 ''' Retrieve the given graph def
183 '''
184 rc = getattr(self.dmd.Reports, 'Multi-Graph Reports', None)
185 if rc:
186 return getattr(rc.graphDefs, graphDefId, None)
187 return None
188
189
190 security.declareProtected('Manage DMD', 'manage_addGraphDefinition')
203
204
205 security.declareProtected('Manage DMD', 'manage_deleteGraphDefinitions')
218
219
220 security.declareProtected('Manage DMD', 'manage_resequenceGraphDefs')
226
227
228
229
231 ''' Construct the list of graph dicts for this report.
232 Similar in functionality to RRDView.getDefaultGraphDefs
233 '''
234 graphs = []
235 def AppendToGraphs(thing, cmds, title):
236 perfServer = thing.device().getPerformanceServer()
237 url = perfServer.buildGraphUrlFromCommands(
238 cmds, drange or self.defaultDateRange)
239 graphs.append({
240 'title': title,
241 'url': url,
242 })
243
244 def GetThingTitle(thing, postfix=''):
245 title = thing.device().id
246 if thing != thing.device():
247 title += ' %s' % thing.id
248 if postfix:
249 title += ' - %s' % postfix
250 return title
251
252 for gg in self.getGraphGroups():
253 collection = gg.getCollection()
254 things = collection and collection.getDevicesAndComponents()
255 graphDef = gg.getGraphDef()
256 if not things or not graphDef:
257 continue
258 if gg.combineDevices:
259 cmds = []
260 idxOffset = 0
261 for thing in things:
262 cmds = graphDef.getGraphCmds(
263 thing.primaryAq(),
264 performancePath(GetRRDPath(thing)),
265 includeSetup = not cmds,
266 includeThresholds = not cmds,
267 cmds = cmds,
268 prefix = GetThingTitle(thing),
269 idxOffset=idxOffset)
270 idxOffset += len(graphDef.graphPoints())
271 AppendToGraphs(things[0], cmds, gg.id)
272 else:
273 for thing in things:
274 cmds = []
275 cmds = graphDef.getGraphCmds(
276 thing.primaryAq(),
277 performancePath(GetRRDPath(thing)))
278 AppendToGraphs(thing, cmds, GetThingTitle(thing))
279 return graphs
280
281
282 InitializeClass(MultiGraphReport)
283