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  from Globals import InitializeClass 
 15  from AccessControl import ClassSecurityInfo 
 16  from ZenModelRM import ZenModelRM 
 17  from Products.ZenRelations.RelSchema import * 
 18  from Products.ZenUtils.ZenTales import talesCompile, getEngine 
 19  from DateTime import DateTime 
 20  from RRDView import GetRRDPath 
 21  from PerformanceConf import performancePath 
 22  from ZenossSecurity import ZEN_MANAGE_DMD 
 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 REQUEST['message'] = 'Group%s deleted' % len(ids) > 1 and 's' or '' 107 return self.callZenScreen(REQUEST)
108 109 110 security.declareProtected('Manage DMD', 'manage_resequenceGraphGroups')
111 - def manage_resequenceGraphGroups(self, seqmap=(), origseq=(), REQUEST=None):
112 """Reorder the sequence of the groups. 113 """ 114 from Products.ZenUtils.Utils import resequence 115 return resequence(self, self.graphGroups(), seqmap, origseq, REQUEST)
116 117
118 - def getGraphGroups(self):
119 """get the ordered groups 120 """ 121 def cmpGroups(a, b): 122 return cmp(a.sequence, b.sequence)
123 groups = [g for g in self.graphGroups()] 124 groups.sort(cmpGroups) 125 return groups
126 127 ### Collections 128 129 security.declareProtected('Manage DMD', 'getCollections')
130 - def getCollections(self):
131 ''' Return an alpha ordered list of available collections 132 ''' 133 def cmpCollections(a, b): 134 return cmp(a.id, b.id)
135 collections = self.collections()[:] 136 collections.sort(cmpCollections) 137 return collections 138 139 140 security.declareProtected('Manage DMD', 'manage_addCollection')
141 - def manage_addCollection(self, new_id, REQUEST=None):
142 """Add a collection 143 """ 144 from Collection import Collection 145 col = Collection(new_id) 146 self.collections._setObject(col.id, col) 147 col = self.collections._getOb(col.id) 148 if REQUEST: 149 url = '%s/collections/%s' % (self.getPrimaryUrlPath(), new_id) 150 return REQUEST['RESPONSE'].redirect(url) 151 return col
152 153 security.declareProtected('Manage DMD', 'manage_deleteCollections')
154 - def manage_deleteCollections(self, ids=(), REQUEST=None):
155 ''' Delete collections from this report 156 ''' 157 for id in ids: 158 self.collections._delObject(id) 159 if REQUEST: 160 REQUEST['message'] = 'Collection%s deleted' % len(ids) > 1 and 's' or '' 161 return self.callZenScreen(REQUEST)
162 163 164 ### Graph Definitions 165 166 security.declareProtected(ZEN_MANAGE_DMD, 'getGraphDefs')
167 - def getGraphDefs(self):
168 ''' Return an ordered list of the graph definitions 169 ''' 170 def cmpGraphDefs(a, b): 171 try: a = int(a.sequence) 172 except ValueError: a = sys.maxint 173 try: b = int(b.sequence) 174 except ValueError: b = sys.maxint 175 return cmp(a, b)
176 graphDefs = self.graphDefs()[:] 177 graphDefs.sort(cmpGraphDefs) 178 return graphDefs 179 180
181 - def getGraphDef(self, graphDefId):
182 ''' Retrieve the given graph def 183 ''' 184 rc = getattr(self.dmd.Reports, 'Multi-Graph Reports', None) 185 if rc: 186 return getattr(rc.graphDefs, graphDefId, None) 187 return None
188 189 190 security.declareProtected('Manage DMD', 'manage_addGraphDefinition')
191 - def manage_addGraphDefinition(self, new_id, REQUEST=None):
192 """Add a GraphDefinition 193 """ 194 from GraphDefinition import GraphDefinition 195 graph = GraphDefinition(new_id) 196 graph.sequence = len(self.graphDefs()) 197 self.graphDefs._setObject(graph.id, graph) 198 graph = self.graphDefs._getOb(graph.id) 199 if REQUEST: 200 url = '%s/graphDefs/%s' % (self.getPrimaryUrlPath(), graph.id) 201 return REQUEST['RESPONSE'].redirect(url) 202 return graph
203 204 205 security.declareProtected('Manage DMD', 'manage_deleteGraphDefinitions')
206 - def manage_deleteGraphDefinitions(self, ids=(), REQUEST=None):
207 """Remove GraphDefinitions 208 """ 209 for id in ids: 210 self.graphDefs._delObject(id) 211 self.manage_resequenceGraphDefs() 212 if REQUEST: 213 if len(ids) == 1: 214 REQUEST['message'] = 'Graph %s deleted.' % ids[0] 215 elif len(ids) > 1: 216 REQUEST['message'] = 'Graphs %s deleted.' % ', '.join(ids) 217 return self.callZenScreen(REQUEST)
218 219 220 security.declareProtected('Manage DMD', 'manage_resequenceGraphDefs')
221 - def manage_resequenceGraphDefs(self, seqmap=(), origseq=(), REQUEST=None):
222 ''' Reorder the sequence of the GraphDefinitions. 223 ''' 224 from Products.ZenUtils.Utils import resequence 225 return resequence(self, self.getGraphDefs(), seqmap, origseq, REQUEST)
226 227 ### Graphing 228 229
230 - def getDefaultGraphDefs(self, drange=None):
231 ''' Construct the list of graph dicts for this report. 232 Similar in functionality to RRDView.getDefaultGraphDefs 233 ''' 234 graphs = [] 235 def AppendToGraphs(thing, cmds, title): 236 perfServer = thing.device().getPerformanceServer() 237 url = perfServer.buildGraphUrlFromCommands( 238 cmds, drange or self.defaultDateRange) 239 graphs.append({ 240 'title': title, 241 'url': url, 242 })
243 244 def GetThingTitle(thing, postfix=''): 245 title = thing.device().id 246 if thing != thing.device(): 247 title += ' %s' % thing.id 248 if postfix: 249 title += ' - %s' % postfix 250 return title 251 252 for gg in self.getGraphGroups(): 253 collection = gg.getCollection() 254 things = collection and collection.getDevicesAndComponents() 255 graphDef = gg.getGraphDef() 256 if not things or not graphDef: 257 continue 258 if gg.combineDevices: 259 cmds = [] 260 idxOffset = 0 261 for thing in things: 262 cmds = graphDef.getGraphCmds( 263 thing.primaryAq(), 264 performancePath(GetRRDPath(thing)), 265 includeSetup = not cmds, 266 includeThresholds = not cmds, 267 cmds = cmds, 268 prefix = GetThingTitle(thing), 269 idxOffset=idxOffset) 270 idxOffset += len(graphDef.graphPoints()) 271 AppendToGraphs(things[0], cmds, gg.id) 272 else: 273 for thing in things: 274 cmds = [] 275 cmds = graphDef.getGraphCmds( 276 thing.primaryAq(), 277 performancePath(GetRRDPath(thing))) 278 AppendToGraphs(thing, cmds, GetThingTitle(thing)) 279 return graphs 280 281 282 InitializeClass(MultiGraphReport) 283