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

Source Code for Module Products.ZenModel.MultiGraphReport

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, Zenoss Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify it 
  7  # under the terms of the GNU General Public License version 2 or (at your 
  8  # option) any later version as published by the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 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   
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 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
30 31
32 -class MultiGraphReport(ZenModelRM):
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
72 - def getBreadCrumbUrlPath(self):
73 ''' 74 Return the url to be used in breadcrumbs for this object. 75 ''' 76 return self.getPrimaryUrlPath() + '/editMultiGraphReport'
77 78 79 ### Graph Groups 80 81 security.declareProtected('Manage DMD', 'manage_addGraphGroup')
82 - def manage_addGraphGroup(self, new_id, collectionId='', graphDefId='', 83 REQUEST=None):
84 ''' Add a new graph group 85 ''' 86 from GraphGroup import GraphGroup 87 gg = GraphGroup(new_id, collectionId, graphDefId, 88 len(self.graphGroups())) 89 self.graphGroups._setObject(gg.id, gg) 90 gg = self.graphGroups._getOb(gg.id) 91 if REQUEST: 92 return REQUEST['RESPONSE'].redirect( 93 '%s/graphGroups/%s' % (self.getPrimaryUrlPath(), gg.id)) 94 return gg
95 96 97 security.declareProtected('Manage DMD', 'manage_deleteGraphGroups')
98 - def manage_deleteGraphGroups(self, ids=(), REQUEST=None):
99 ''' Delete graph groups from this report 100 ''' 101 for id in ids: 102 self.graphGroups._delObject(id) 103 self.manage_resequenceGraphGroups() 104 if REQUEST: 105 messaging.IMessageSender(self).sendToBrowser( 106 'Groups Deleted', 107 'Group%s deleted: %s' % (len(ids) > 1 and 's' or '', 108 ', '.join(ids)) 109 ) 110 return self.callZenScreen(REQUEST)
111 112 113 security.declareProtected('Manage DMD', 'manage_resequenceGraphGroups')
114 - def manage_resequenceGraphGroups(self, seqmap=(), origseq=(), REQUEST=None):
115 """Reorder the sequence of the groups. 116 """ 117 from Products.ZenUtils.Utils import resequence 118 return resequence(self, self.graphGroups(), seqmap, origseq, REQUEST)
119 120
121 - def getGraphGroups(self):
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 ### Collections 131 132 security.declareProtected('Manage DMD', 'getCollections')
133 - def getCollections(self):
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')
144 - def manage_addCollection(self, new_id, REQUEST=None):
145 """Add a collection 146 """ 147 from Collection import Collection 148 col = Collection(new_id) 149 self.collections._setObject(col.id, col) 150 col = self.collections._getOb(col.id) 151 if REQUEST: 152 url = '%s/collections/%s' % (self.getPrimaryUrlPath(), new_id) 153 return REQUEST['RESPONSE'].redirect(url) 154 return col
155 156 security.declareProtected('Manage DMD', 'manage_deleteCollections')
157 - def manage_deleteCollections(self, ids=(), REQUEST=None):
158 ''' Delete collections from this report 159 ''' 160 for id in ids: 161 self.collections._delObject(id) 162 if REQUEST: 163 messaging.IMessageSender(self).sendToBrowser( 164 'Collections Deleted', 165 'Collection%s deleted: %s' % (len(ids) > 1 and 's' or '', 166 ', '.join(ids)) 167 ) 168 return self.callZenScreen(REQUEST)
169 170 171 ### Graph Definitions 172 173 security.declareProtected(ZEN_MANAGE_DMD, 'getGraphDefs')
174 - def getGraphDefs(self):
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
188 - def getGraphDef(self, graphDefId):
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')
198 - def manage_addGraphDefinition(self, new_id, REQUEST=None):
199 """Add a GraphDefinition 200 """ 201 from GraphDefinition import GraphDefinition 202 graph = GraphDefinition(new_id) 203 graph.sequence = len(self.graphDefs()) 204 self.graphDefs._setObject(graph.id, graph) 205 graph = self.graphDefs._getOb(graph.id) 206 if REQUEST: 207 url = '%s/graphDefs/%s' % (self.getPrimaryUrlPath(), graph.id) 208 return REQUEST['RESPONSE'].redirect(url) 209 return graph
210 211 212 security.declareProtected('Manage DMD', 'manage_deleteGraphDefinitions')
213 - def manage_deleteGraphDefinitions(self, ids=(), REQUEST=None):
214 """Remove GraphDefinitions 215 """ 216 for id in ids: 217 self.graphDefs._delObject(id) 218 self.manage_resequenceGraphDefs() 219 if REQUEST: 220 messaging.IMessageSender(self).sendToBrowser( 221 'Graphs Deleted', 222 'Graph%s deleted: %s' % (len(ids) > 1 and 's' or '', 223 ', '.join(ids)) 224 ) 225 return self.callZenScreen(REQUEST)
226 227 228 security.declareProtected('Manage DMD', 'manage_resequenceGraphDefs')
229 - def manage_resequenceGraphDefs(self, seqmap=(), origseq=(), REQUEST=None):
230 ''' Reorder the sequence of the GraphDefinitions. 231 ''' 232 from Products.ZenUtils.Utils import resequence 233 return resequence(self, self.getGraphDefs(), seqmap, origseq, REQUEST)
234 235 ### Graphing 236 237
238 - def getDefaultGraphDefs(self, drange=None):
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