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 RRDView import GetRRDPath
20 from PerformanceConf import performancePath
21 from ZenossSecurity import ZEN_MANAGE_DMD
22 from Products.ZenWidgets import messaging
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')
112
113
114 security.declareProtected('Manage DMD', 'manage_resequenceGraphGroups')
120
121
123 """get the ordered groups
124 """
125 def cmpGroups(a, b):
126 return cmp(a.sequence, b.sequence)
127 groups = [g for g in self.graphGroups()]
128 groups.sort(cmpGroups)
129 return groups
130
131
132
133 security.declareProtected('Manage DMD', 'getCollections')
135 ''' Return an alpha ordered list of available collections
136 '''
137 def cmpCollections(a, b):
138 return cmp(a.id, b.id)
139 collections = self.collections()[:]
140 collections.sort(cmpCollections)
141 return collections
142
143
144 security.declareProtected('Manage DMD', 'manage_addCollection')
156
157 security.declareProtected('Manage DMD', 'manage_deleteCollections')
170
171
172
173
174 security.declareProtected(ZEN_MANAGE_DMD, 'getGraphDefs')
176 ''' Return an ordered list of the graph definitions
177 '''
178 def cmpGraphDefs(a, b):
179 try: a = int(a.sequence)
180 except ValueError: a = sys.maxint
181 try: b = int(b.sequence)
182 except ValueError: b = sys.maxint
183 return cmp(a, b)
184 graphDefs = self.graphDefs()[:]
185 graphDefs.sort(cmpGraphDefs)
186 return graphDefs
187
188
190 ''' Retrieve the given graph def
191 '''
192 rc = getattr(self.dmd.Reports, 'Multi-Graph Reports', None)
193 if rc:
194 return getattr(rc.graphDefs, graphDefId, None)
195 return None
196
197
198 security.declareProtected('Manage DMD', 'manage_addGraphDefinition')
211
212
213 security.declareProtected('Manage DMD', 'manage_deleteGraphDefinitions')
227
228
229 security.declareProtected('Manage DMD', 'manage_resequenceGraphDefs')
235
236
237
238
240 ''' Construct the list of graph dicts for this report.
241 Similar in functionality to RRDView.getDefaultGraphDefs
242 '''
243 graphs = []
244 def AppendToGraphs(thing, cmds, title):
245 perfServer = thing.device().getPerformanceServer()
246 url = perfServer.buildGraphUrlFromCommands(
247 cmds, drange or self.defaultDateRange)
248 graphs.append({
249 'title': title,
250 'url': url,
251 })
252
253 def GetThingTitle(thing, postfix=''):
254 title = thing.device().id
255 if thing != thing.device():
256 title += ' %s' % thing.id
257 if postfix:
258 title += ' - %s' % postfix
259 return title
260
261 for gg in self.getGraphGroups():
262 collection = gg.getCollection()
263 things = collection and collection.getDevicesAndComponents()
264 graphDef = gg.getGraphDef()
265 if not things or not graphDef:
266 continue
267 if gg.combineDevices:
268 cmds = []
269 idxOffset = 0
270 for thing in things:
271 cmds = graphDef.getGraphCmds(
272 thing.primaryAq(),
273 performancePath(GetRRDPath(thing)),
274 includeSetup = not cmds,
275 includeThresholds = not cmds,
276 cmds = cmds,
277 prefix = GetThingTitle(thing),
278 idxOffset=idxOffset)
279 idxOffset += len(graphDef.graphPoints())
280 AppendToGraphs(things[0], cmds, gg.id)
281 else:
282 for thing in things:
283 cmds = []
284 cmds = graphDef.getGraphCmds(
285 thing.primaryAq(),
286 performancePath(GetRRDPath(thing)))
287 AppendToGraphs(thing, cmds, GetThingTitle(thing))
288 return graphs
289
290
291 InitializeClass(MultiGraphReport)
292