Package Products :: Package ZenModel :: Module MultiGraphReport
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenModel.MultiGraphReport

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
  4  #  
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  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 
21 22 @deprecated 23 -def manage_addMultiGraphReport(context, id, REQUEST = None):
24 """ Create a new MultiGraphReport 25 """ 26 gr = MultiGraphReport(id) 27 context._setObject(gr.id, gr) 28 if REQUEST is not None: 29 audit('UI.Report.Add', gr.id, reportType=getDisplayType(gr), organizer=context) 30 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
31
32 33 -class MultiGraphReport(BaseReport):
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
73 - def getBreadCrumbUrlPath(self):
74 """ 75 Return the url to be used in breadcrumbs for this object. 76 """ 77 return self.getPrimaryUrlPath() + '/editMultiGraphReport'
78 79 80 ### Graph Groups 81 82 security.declareProtected('Manage DMD', 'manage_addGraphGroup')
83 - def manage_addGraphGroup(self, new_id, collectionId='', graphDefId='', 84 REQUEST=None):
85 """ Add a new graph group 86 """ 87 from GraphGroup import GraphGroup 88 gg = GraphGroup(new_id, collectionId, graphDefId, 89 len(self.graphGroups())) 90 self.graphGroups._setObject(gg.id, gg) 91 gg = self.graphGroups._getOb(gg.id) 92 if REQUEST: 93 audit('UI.Report.AddGraphGroup', self.id, graphGroup=gg.id) 94 return REQUEST['RESPONSE'].redirect( 95 '%s/graphGroups/%s' % (self.getPrimaryUrlPath(), gg.id)) 96 return gg
97 98 99 security.declareProtected('Manage DMD', 'manage_deleteGraphGroups')
100 - def manage_deleteGraphGroups(self, ids=(), REQUEST=None):
101 """ Delete graph groups from this report 102 """ 103 for id in ids: 104 self.graphGroups._delObject(id) 105 self.manage_resequenceGraphGroups() 106 if REQUEST: 107 for id in ids: 108 audit('UI.Report.DeleteGraphGroup', self.id, graphGroup=id) 109 messaging.IMessageSender(self).sendToBrowser( 110 'Groups Deleted', 111 'Group%s deleted: %s' % (len(ids) > 1 and 's' or '', 112 ', '.join(ids)) 113 ) 114 return self.callZenScreen(REQUEST)
115 116 117 security.declareProtected('Manage DMD', 'manage_resequenceGraphGroups')
118 - def manage_resequenceGraphGroups(self, seqmap=(), origseq=(), REQUEST=None):
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
127 - def getGraphGroups(self):
128 """get the ordered groups 129 """ 130 return sorted(self.graphGroups(), key=lambda a: a.sequence)
131 132 ### Collections 133 134 security.declareProtected('Manage DMD', 'getCollections')
135 - def getCollections(self):
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')
142 - def manage_addCollection(self, new_id, REQUEST=None):
143 """Add a collection 144 """ 145 from Collection import Collection 146 col = Collection(new_id) 147 self.collections._setObject(col.id, col) 148 col = self.collections._getOb(col.id) 149 if REQUEST: 150 audit('UI.Report.AddCollection', self.id, collection=col.id) 151 url = '%s/collections/%s' % (self.getPrimaryUrlPath(), new_id) 152 return REQUEST['RESPONSE'].redirect(url) 153 return col
154 155 security.declareProtected('Manage DMD', 'manage_deleteCollections')
156 - def manage_deleteCollections(self, ids=(), REQUEST=None):
157 """ Delete collections from this report 158 """ 159 for id in ids: 160 self.collections._delObject(id) 161 if REQUEST: 162 for id in ids: 163 audit('UI.Report.DeleteCollection', self.id, collection=id) 164 messaging.IMessageSender(self).sendToBrowser( 165 'Collections Deleted', 166 'Collection%s deleted: %s' % (len(ids) > 1 and 's' or '', 167 ', '.join(ids)) 168 ) 169 return self.callZenScreen(REQUEST)
170 171 172 ### Graph Definitions 173 174 security.declareProtected(ZEN_MANAGE_DMD, 'getGraphDefs')
175 - def getGraphDefs(self):
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
186 - def getGraphDef(self, graphDefId):
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')
196 - def manage_addGraphDefinition(self, new_id, REQUEST=None):
197 """Add a GraphDefinition 198 """ 199 from GraphDefinition import GraphDefinition 200 graph = GraphDefinition(new_id) 201 graph.sequence = len(self.graphDefs()) 202 self.graphDefs._setObject(graph.id, graph) 203 graph = self.graphDefs._getOb(graph.id) 204 if REQUEST: 205 audit('UI.Report.AddGraphDefinition', self.id, graphDefinition=graph.id) 206 url = '%s/graphDefs/%s' % (self.getPrimaryUrlPath(), graph.id) 207 return REQUEST['RESPONSE'].redirect(url) 208 return graph
209 210 211 security.declareProtected('Manage DMD', 'manage_deleteGraphDefinitions')
212 - def manage_deleteGraphDefinitions(self, ids=(), REQUEST=None):
213 """Remove GraphDefinitions 214 """ 215 for id in ids: 216 self.graphDefs._delObject(id) 217 self.manage_resequenceGraphDefs() 218 if REQUEST: 219 for id in ids: 220 audit('UI.Report.DeleteGraphDefinition', self.id, graphDefinition=id) 221 messaging.IMessageSender(self).sendToBrowser( 222 'Graphs Deleted', 223 'Graph%s deleted: %s' % (len(ids) > 1 and 's' or '', 224 ', '.join(ids)) 225 ) 226 return self.callZenScreen(REQUEST)
227 228 229 security.declareProtected('Manage DMD', 'manage_resequenceGraphDefs')
230 - def manage_resequenceGraphDefs(self, seqmap=(), origseq=(), REQUEST=None):
231 """ Reorder the sequence of the GraphDefinitions. 232 """ 233 from Products.ZenUtils.Utils import resequence 234 retval = resequence(self, self.getGraphDefs(), seqmap, origseq, REQUEST) 235 if REQUEST: 236 audit('UI.Report.ResequenceGraphDefinitions', self.id, sequence=seqmap, oldData_={'sequence':origseq}) 237 return retval
238 239 ### Graphing 240 241
242 - def getDefaultGraphDefs(self, drange=None):
243 """ Construct the list of graph dicts for this report. 244 Similar in functionality to RRDView.getDefaultGraphDefs 245 """ 246 graphs = [] 247 def AppendToGraphs(thing, cmds, title): 248 perfServer = thing.device().getPerformanceServer() 249 url = perfServer.buildGraphUrlFromCommands( 250 cmds, drange or self.defaultDateRange) 251 graphs.append({ 252 'title': title, 253 'url': url, 254 })
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