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

Source Code for Module 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 as published by 
  8  # 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 RRDView import GetRRDPath 
 20  from PerformanceConf import performancePath 
 21  from ZenossSecurity import ZEN_MANAGE_DMD 
 22  from Products.ZenWidgets import messaging 
 23   
24 -def manage_addMultiGraphReport(context, id, REQUEST = None):
25 ''' Create a new MultiGraphReport 26 ''' 27 gr = MultiGraphReport(id) 28 context._setObject(gr.id, gr) 29 if REQUEST is not None: 30 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
31 32
33 -class MultiGraphReport(ZenModelRM):
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
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 return REQUEST['RESPONSE'].redirect( 94 '%s/graphGroups/%s' % (self.getPrimaryUrlPath(), gg.id)) 95 return gg
96 97 98 security.declareProtected('Manage DMD', 'manage_deleteGraphGroups')
99 - def manage_deleteGraphGroups(self, ids=(), REQUEST=None):
100 ''' Delete graph groups from this report 101 ''' 102 for id in ids: 103 self.graphGroups._delObject(id) 104 self.manage_resequenceGraphGroups() 105 if REQUEST: 106 messaging.IMessageSender(self).sendToBrowser( 107 'Groups Deleted', 108 'Group%s deleted: %s' % (len(ids) > 1 and 's' or '', 109 ', '.join(ids)) 110 ) 111 return self.callZenScreen(REQUEST)
112 113 114 security.declareProtected('Manage DMD', 'manage_resequenceGraphGroups')
115 - def manage_resequenceGraphGroups(self, seqmap=(), origseq=(), REQUEST=None):
116 """Reorder the sequence of the groups. 117 """ 118 from Products.ZenUtils.Utils import resequence 119 return resequence(self, self.graphGroups(), seqmap, origseq, REQUEST)
120 121
122 - def getGraphGroups(self):
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 ### Collections 132 133 security.declareProtected('Manage DMD', 'getCollections')
134 - def getCollections(self):
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')
145 - def manage_addCollection(self, new_id, REQUEST=None):
146 """Add a collection 147 """ 148 from Collection import Collection 149 col = Collection(new_id) 150 self.collections._setObject(col.id, col) 151 col = self.collections._getOb(col.id) 152 if REQUEST: 153 url = '%s/collections/%s' % (self.getPrimaryUrlPath(), new_id) 154 return REQUEST['RESPONSE'].redirect(url) 155 return col
156 157 security.declareProtected('Manage DMD', 'manage_deleteCollections')
158 - def manage_deleteCollections(self, ids=(), REQUEST=None):
159 ''' Delete collections from this report 160 ''' 161 for id in ids: 162 self.collections._delObject(id) 163 if REQUEST: 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 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
189 - def getGraphDef(self, graphDefId):
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')
199 - def manage_addGraphDefinition(self, new_id, REQUEST=None):
200 """Add a GraphDefinition 201 """ 202 from GraphDefinition import GraphDefinition 203 graph = GraphDefinition(new_id) 204 graph.sequence = len(self.graphDefs()) 205 self.graphDefs._setObject(graph.id, graph) 206 graph = self.graphDefs._getOb(graph.id) 207 if REQUEST: 208 url = '%s/graphDefs/%s' % (self.getPrimaryUrlPath(), graph.id) 209 return REQUEST['RESPONSE'].redirect(url) 210 return graph
211 212 213 security.declareProtected('Manage DMD', 'manage_deleteGraphDefinitions')
214 - def manage_deleteGraphDefinitions(self, ids=(), REQUEST=None):
215 """Remove GraphDefinitions 216 """ 217 for id in ids: 218 self.graphDefs._delObject(id) 219 self.manage_resequenceGraphDefs() 220 if REQUEST: 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 return resequence(self, self.getGraphDefs(), seqmap, origseq, REQUEST)
235 236 ### Graphing 237 238
239 - def getDefaultGraphDefs(self, drange=None):
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