1
2
3
4
5
6
7
8
9
10
11
12
13
14 import sys
15 from Globals import InitializeClass
16 from AccessControl import ClassSecurityInfo
17 from ZenModelRM import ZenModelRM
18 from Products.ZenRelations.RelSchema import *
19 from PerformanceConf import performancePath
20 from ZenossSecurity import ZEN_MANAGE_DMD
21 from Products.ZenWidgets import messaging
22
30
31
33
34 meta_type = "MultiGraphReport"
35
36 numColumns = 1
37 numColumnsOptions = (1, 2, 3)
38
39 _properties = ZenModelRM._properties + (
40 {'id':'numColumns', 'type':'int',
41 'select_variable' : 'numColumnOptions', 'mode':'w'},
42 )
43
44 _relations = (
45 ('collections',
46 ToManyCont(ToOne, 'Products.ZenModel.Collection', 'report')),
47 ("graphGroups",
48 ToManyCont(ToOne,"Products.ZenModel.GraphGroup", "report")),
49 ('graphDefs',
50 ToManyCont(ToOne, 'Products.ZenModel.GraphDefinition', 'report')),
51 )
52
53 factory_type_information = (
54 {
55 'immediate_view' : '',
56 'actions' :
57 (
58 {'name' : 'View Report',
59 'action' : '',
60 'permissions' : ("View",),
61 },
62 {'name' : 'Edit Report',
63 'action' : 'editMultiGraphReport',
64 'permissions' : ("Manage DMD",),
65 },
66 )
67 },
68 )
69
70 security = ClassSecurityInfo()
71
73 '''
74 Return the url to be used in breadcrumbs for this object.
75 '''
76 return self.getPrimaryUrlPath() + '/editMultiGraphReport'
77
78
79
80
81 security.declareProtected('Manage DMD', 'manage_addGraphGroup')
95
96
97 security.declareProtected('Manage DMD', 'manage_deleteGraphGroups')
111
112
113 security.declareProtected('Manage DMD', 'manage_resequenceGraphGroups')
119
120
122 """get the ordered groups
123 """
124 def cmpGroups(a, b):
125 return cmp(a.sequence, b.sequence)
126 groups = [g for g in self.graphGroups()]
127 groups.sort(cmpGroups)
128 return groups
129
130
131
132 security.declareProtected('Manage DMD', 'getCollections')
134 ''' Return an alpha ordered list of available collections
135 '''
136 def cmpCollections(a, b):
137 return cmp(a.id, b.id)
138 collections = self.collections()[:]
139 collections.sort(cmpCollections)
140 return collections
141
142
143 security.declareProtected('Manage DMD', 'manage_addCollection')
155
156 security.declareProtected('Manage DMD', 'manage_deleteCollections')
169
170
171
172
173 security.declareProtected(ZEN_MANAGE_DMD, 'getGraphDefs')
175 ''' Return an ordered list of the graph definitions
176 '''
177 def cmpGraphDefs(a, b):
178 try: a = int(a.sequence)
179 except ValueError: a = sys.maxint
180 try: b = int(b.sequence)
181 except ValueError: b = sys.maxint
182 return cmp(a, b)
183 graphDefs = self.graphDefs()[:]
184 graphDefs.sort(cmpGraphDefs)
185 return graphDefs
186
187
189 ''' Retrieve the given graph def
190 '''
191 rc = getattr(self.dmd.Reports, 'Multi-Graph Reports', None)
192 if rc:
193 return getattr(rc.graphDefs, graphDefId, None)
194 return None
195
196
197 security.declareProtected('Manage DMD', 'manage_addGraphDefinition')
210
211
212 security.declareProtected('Manage DMD', 'manage_deleteGraphDefinitions')
226
227
228 security.declareProtected('Manage DMD', 'manage_resequenceGraphDefs')
234
235
236
237
239 ''' Construct the list of graph dicts for this report.
240 Similar in functionality to RRDView.getDefaultGraphDefs
241 '''
242 graphs = []
243 def AppendToGraphs(thing, cmds, title):
244 perfServer = thing.device().getPerformanceServer()
245 url = perfServer.buildGraphUrlFromCommands(
246 cmds, drange or self.defaultDateRange)
247 graphs.append({
248 'title': title,
249 'url': url,
250 })
251
252 def GetThingTitle(thing, postfix=''):
253 title = thing.device().id
254 if thing != thing.device():
255 title += ' %s' % thing.id
256 if postfix:
257 title += ' - %s' % postfix
258 return title
259
260 for gg in self.getGraphGroups():
261 collection = gg.getCollection()
262 things = collection and collection.getDevicesAndComponents()
263 graphDef = gg.getGraphDef()
264 if not things or not graphDef:
265 continue
266 if gg.combineDevices:
267 cmds = []
268 idxOffset = 0
269 for thing in things:
270 cmds = graphDef.getGraphCmds(
271 thing.primaryAq(),
272 thing.fullRRDPath(),
273 includeSetup = not cmds,
274 includeThresholds = not cmds,
275 cmds = cmds,
276 prefix = GetThingTitle(thing),
277 idxOffset=idxOffset)
278 idxOffset += len(graphDef.graphPoints())
279 AppendToGraphs(things[0], cmds, gg.id)
280 else:
281 for thing in things:
282 cmds = []
283 cmds = graphDef.getGraphCmds(
284 thing.primaryAq(),
285 thing.fullRRDPath())
286 AppendToGraphs(thing, cmds, GetThingTitle(thing))
287 return graphs
288
289
290 InitializeClass(MultiGraphReport)
291