1
2
3
4
5
6
7
8
9
10
11 import sys
12 from Globals import InitializeClass
13 from AccessControl import ClassSecurityInfo
14 from Products.ZenMessaging.audit import audit
15 from Products.ZenUtils.deprecated import deprecated
16 from Products.ZenModel.BaseReport import BaseReport
17 from Products.ZenRelations.RelSchema import *
18 from Products.ZenUtils.Utils import resequence, getDisplayType
19 from ZenossSecurity import ZEN_MANAGE_DMD
20 from Products.ZenWidgets import messaging
31
34
35 meta_type = "MultiGraphReport"
36
37 numColumns = 1
38 numColumnsOptions = (1, 2, 3)
39
40 _properties = BaseReport._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' : '',
57 'actions' :
58 (
59 {'name' : 'View Report',
60 'action' : '',
61 'permissions' : ("View",),
62 },
63 {'name' : 'Edit Report',
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')
97
98
99 security.declareProtected('Manage DMD', 'manage_deleteGraphGroups')
115
116
117 security.declareProtected('Manage DMD', 'manage_resequenceGraphGroups')
119 """Reorder the sequence of the groups.
120 """
121 retval = resequence(self, self.graphGroups(), seqmap, origseq, REQUEST)
122 if REQUEST:
123 audit('UI.Report.ResequenceGraphGroups', self.id, sequence=seqmap, oldData_={'sequence':origseq})
124 return retval
125
126
128 """get the ordered groups
129 """
130 return sorted(self.graphGroups(), key=lambda a: a.sequence)
131
132
133
134 security.declareProtected('Manage DMD', 'getCollections')
136 """ Return an alpha ordered list of available collections
137 """
138 return sorted(self.collections(), key=lambda a: a.id)
139
140
141 security.declareProtected('Manage DMD', 'manage_addCollection')
154
155 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 graphDefSortKey(a):
179 try:
180 return int(a.sequence)
181 except ValueError:
182 return sys.maxint
183 return sorted(self.graphDefs(), key=graphDefSortKey)
184
185
187 """ Retrieve the given graph def
188 """
189 rc = getattr(self.dmd.Reports, 'Multi-Graph Reports', None)
190 if rc:
191 return getattr(rc.graphDefs, graphDefId, None)
192 return None
193
194
195 security.declareProtected('Manage DMD', 'manage_addGraphDefinition')
209
210
211 security.declareProtected('Manage DMD', 'manage_deleteGraphDefinitions')
227
228
229 security.declareProtected('Manage DMD', 'manage_resequenceGraphDefs')
238
239
240
241
255
256 def GetThingTitle(thing, postfix=''):
257 title = thing.device().id
258 if thing != thing.device():
259 title += ' %s' % thing.id
260 if postfix:
261 title += ' - %s' % postfix
262 return title
263
264 for gg in self.getGraphGroups():
265 collection = gg.getCollection()
266 things = collection and collection.getDevicesAndComponents()
267 graphDef = gg.getGraphDef()
268 if not things or not graphDef:
269 continue
270 if gg.combineDevices:
271 cmds = []
272 idxOffset = 0
273 for thing in things:
274 cmds = graphDef.getGraphCmds(
275 thing.primaryAq(),
276 thing.fullRRDPath(),
277 includeSetup = not cmds,
278 includeThresholds = not cmds,
279 cmds = cmds,
280 prefix = GetThingTitle(thing),
281 idxOffset=idxOffset)
282 idxOffset += len(graphDef.graphPoints())
283 AppendToGraphs(things[0], cmds, gg.id)
284 else:
285 for thing in things:
286 cmds = []
287 cmds = graphDef.getGraphCmds(
288 thing.primaryAq(),
289 thing.fullRRDPath())
290 AppendToGraphs(thing, cmds, GetThingTitle(thing))
291 return graphs
292
293
294 InitializeClass(MultiGraphReport)
295