Trees | Indices | Help |
|
---|
|
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 DTMLFile 16 from Globals import InitializeClass 17 from AccessControl import ClassSecurityInfo, Permissions 18 from Acquisition import aq_parent 19 20 from ZenModelRM import ZenModelRM 21 22 from Products.ZenRelations.RelSchema import * 23 import Products.ZenModel.RRDDataSource as RRDDataSource 24 from Products.ZenModel.BasicDataSource import BasicDataSource 25 from Products.ZenModel.ConfigurationError import ConfigurationError 26 from RRDDataPoint import SEPARATOR 27 from ZenPackable import ZenPackable 28 2931 """make a RRDTemplate""" 32 tt = RRDTemplate(id) 33 context._setObject(tt.id, tt) 34 if REQUEST is not None: 35 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')36 37 38 addRRDTemplate = DTMLFile('dtml/addRRDTemplate',globals()) 39 4042 """Create the crumbs path for sub objects of an RRDTemplate. 43 """ 44 dc = templ.deviceClass() 45 if dc: 46 url = '%s/perfConfig' % dc.getPrimaryUrlPath() 47 else: 48 url = '%s/objTemplates' % templ.getPrimaryParent().getPrimaryUrlPath() 49 crumbs.insert(idx,(url,'Templates')) 50 return crumbs51 52 5355 56 meta_type = 'RRDTemplate' 57 58 security = ClassSecurityInfo() 59 60 description = "" 61 62 _properties = ( 63 {'id':'description', 'type':'text', 'mode':'w'}, 64 ) 65 66 # The graphs relationship can be removed post 2.1. It is needed 67 # by the graphDefinitionAndFriends migrate script for 2.1 68 69 _relations = ZenPackable._relations + ( 70 ("deviceClass", ToOne(ToManyCont,"Products.ZenModel.DeviceClass", "rrdTemplates")), 71 ("datasources", ToManyCont(ToOne,"Products.ZenModel.RRDDataSource", "rrdTemplate")), 72 ("graphs", ToManyCont(ToOne,"Products.ZenModel.RRDGraph", "rrdTemplate")), 73 ("thresholds", ToManyCont(ToOne,"Products.ZenModel.ThresholdClass", "rrdTemplate")), 74 ("graphDefs", ToManyCont(ToOne,"Products.ZenModel.GraphDefinition", "rrdTemplate")), 75 ) 76 77 78 # Screen action bindings (and tab definitions) 79 factory_type_information = ( 80 { 81 'immediate_view' : 'viewRRDTemplate', 82 'actions' : 83 ( 84 { 'id' : 'overview' 85 , 'name' : 'Performance Template' 86 , 'action' : 'viewRRDTemplate' 87 , 'permissions' : ( Permissions.view, ) 88 }, 89 ) 90 }, 91 ) 92120 12194 """Return the breadcrumb links for this object add ActionRules list. 95 [('url','id'), ...] 96 """ 97 crumbs = super(RRDTemplate, self).breadCrumbs(terminator) 98 return crumbspath(self, crumbs)99 100102 """Is this template editable in context. 103 """ 104 return ((context == self or context.isLocalName(self.id)) 105 and self.isManager(obj=self))106 107109 ''' Return an ordered list of the graph definitions 110 ''' 111 def cmpGraphDefs(a, b): 112 try: a = int(a.sequence) 113 except ValueError: a = sys.maxint 114 try: b = int(b.sequence) 115 except ValueError: b = sys.maxint 116 return cmp(a, b)117 graphDefs = [g for g in self.graphDefs()] 118 graphDefs.sort(cmpGraphDefs) 119 return graphDefs123 """Return the path on which this template is defined. 124 """ 125 return self.getPrimaryParent().getPrimaryDmdId(subrel="rrdTemplates")126 127129 ''' Return a list of names of graphable thresholds 130 ''' 131 return [t for t in self.thresholds()]132 133135 """Return the list of all datapoint names. 136 """ 137 return [p.name() for s in self.datasources() for p in s.datapoints()]138 139141 """Return a list of all datapoints on this template. 142 """ 143 if dsType is None: return self.datasources() 144 return [ds for ds in self.datasources() 145 if ds.sourcetype == dsType 146 or (dsType=='COMMAND' and ds.useZenCommand())]147 148150 """Return a list of all datapoints on this template. 151 """ 152 result = [] 153 for s in self.datasources(): 154 result.extend(s.datapoints()) 155 return result156 157159 """Return a datapoint based on its name. 160 """ 161 source = name 162 point = name 163 if name.find(SEPARATOR) >= 0: 164 source, point = name.split(SEPARATOR, 1) 165 ds = self.datasources._getOb(source, None) 166 if ds is None: 167 results = [] 168 for ds in self.datasources(): 169 for dp in ds.datapoints(): 170 if dp.name() == name: 171 results.append(dp) 172 if len(results) == 1: 173 return results[0] 174 else: 175 return ds.datapoints._getOb(point) 176 raise ConfigurationError('Unknown data point "%s"' % name)177 178 179 security.declareProtected('Add DMD Objects', 'manage_addRRDDataSource')181 """Add an RRDDataSource to this DeviceClass. 182 """ 183 ds = None 184 if id and dsOption: 185 ds = self.getDataSourceInstance(id, dsOption) 186 self.datasources._setObject(ds.id, ds) 187 ds = self.datasources._getOb(ds.id) 188 if REQUEST: 189 if ds: 190 REQUEST['message'] = "Data source %s added" % ds.id 191 url = '%s/datasources/%s' % (self.getPrimaryUrlPath(), ds.id) 192 return REQUEST['RESPONSE'].redirect(url) 193 else: 194 return self.callZenScreen(REQUEST) 195 return ds196 197199 """Delete RRDDataSources from this DeviceClass 200 """ 201 def clean(rel, id): 202 for obj in rel(): 203 if id in obj.dsnames: 204 obj.dsnames.remove(id) 205 if not obj.dsnames: 206 rel._delObject(obj.id)207 208 if not ids: return self.callZenScreen(REQUEST) 209 for id in ids: 210 self._p_changed = True 211 if getattr(self.datasources,id,False): 212 if getattr(self, 'device', False): 213 perfConf = self.device().getPerformanceServer() 214 perfConf.deleteRRDFiles(device=self.device().id, datasource=id) 215 else: 216 for d in self.deviceClass.obj.getSubDevicesGen(): 217 perfConf = d.getPerformanceServer() 218 perfConf.deleteRRDFiles(device=d, datasource=id) 219 220 self.datasources._delObject(id) 221 clean(self.graphs, id) 222 clean(self.thresholds, id) 223 224 if REQUEST: 225 if len(ids) == 1: 226 REQUEST['message'] = 'Data source %s deleted.' % ids[0] 227 elif len(ids) > 1: 228 REQUEST['message'] = 'Data sources %s deleted.' % ', '.join(ids) 229 return self.callZenScreen(REQUEST) 230 231 232 security.declareProtected('Add DMD Objects', 'manage_addRRDThreshold')234 """Add an RRDThreshold to this DeviceClass. 235 """ 236 from RRDThreshold import RRDThreshold 237 if not id: return self.callZenScreen(REQUEST) 238 org = self.getThresholdClass(id, thresholdClassName) 239 self.thresholds._setObject(org.id, org) 240 org = self.thresholds._getOb(org.id) 241 if REQUEST: 242 if org: 243 REQUEST['message'] = 'Threshold %s added' % org.id 244 url = '%s/thresholds/%s' % (self.getPrimaryUrlPath(), org.id) 245 return REQUEST['RESPONSE'].redirect(url) 246 else: 247 return self.callZenScreen(REQUEST) 248 return org249 250252 """Delete RRDThresholds from this DeviceClass 253 """ 254 if not ids: return self.callZenScreen(REQUEST) 255 for id in ids: 256 if getattr(self.thresholds,id,False): 257 self.thresholds._delObject(id) 258 if REQUEST: 259 if len(ids) == 1: 260 REQUEST['message'] = 'Threshold %s deleted.' % ids[0] 261 elif len(ids) > 1: 262 REQUEST['message'] = 'Thresholds %s deleted.' % ', '.join(ids) 263 return self.callZenScreen(REQUEST)264 265 266 security.declareProtected('Manage DMD', 'manage_addGraphDefinition')268 """Add a GraphDefinition to our RRDTemplate. 269 """ 270 from GraphDefinition import GraphDefinition 271 graphs = self.getGraphDefs() 272 graph = None 273 graph = GraphDefinition(new_id) 274 graph.sequence = len(self.graphDefs()) 275 self.graphDefs._setObject(graph.id, graph) 276 graph = self.graphDefs._getOb(graph.id) 277 if REQUEST: 278 REQUEST['message'] = 'Graph %s added' % graph.id 279 url = '%s/graphDefs/%s' % (self.getPrimaryUrlPath(), graph.id) 280 return REQUEST['RESPONSE'].redirect(url) 281 return graph282 283 284 security.declareProtected('Manage DMD', 'manage_deleteGraphDefinitions')286 """Remove GraphDefinitions from this RRDTemplate. 287 """ 288 for id in ids: 289 self.graphDefs._delObject(id) 290 self.manage_resequenceGraphDefs() 291 if REQUEST: 292 if len(ids) == 1: 293 REQUEST['message'] = 'Graph %s deleted.' % ids[0] 294 elif len(ids) > 1: 295 REQUEST['message'] = 'Graphs %s deleted.' % ', '.join(ids) 296 return self.callZenScreen(REQUEST)297 298 299 security.declareProtected('Manage DMD', 'manage_resequenceGraphDefs')301 """Reorder the sequence of the GraphDefinitions. 302 """ 303 from Products.ZenUtils.Utils import resequence 304 return resequence(self, self.getGraphDefs(), 305 seqmap, origseq, REQUEST)306 307309 dsClasses = [BasicDataSource] 310 for zp in self.dmd.packs(): 311 dsClasses += zp.getDataSourceClasses() 312 return dsClasses313 314316 ''' Returns a list of the available datasource options as a list 317 of (display name, dsOption) 318 ''' 319 dsTypes = [] 320 for dsClass in self.getDataSourceClasses(): 321 dsTypes += [(t, '%s.%s' % (dsClass.__name__, t)) 322 for t in dsClass.sourcetypes] 323 return dsTypes324 325327 ''' Given one of the dsOptions returned by getDataSourceOptions) 328 return an instance of the that RRDDataSource subclass. 329 ''' 330 dsClassName, dsType = dsOption.split('.') 331 for c in self.getDataSourceClasses(): 332 if dsClassName == c.__name__: 333 ds = c(id) 334 ds.sourcetype = dsType 335 break 336 else: 337 raise ConfigurationError('Cannot find datasource class' 338 ' for %s' % dsOption) 339 return ds340 341343 from Products.ZenModel.MinMaxThreshold import MinMaxThreshold 344 thresholdClasses = [MinMaxThreshold] 345 for zp in self.dmd.packs(): 346 thresholdClasses += zp.getThresholdClasses() 347 return map(lambda x: (x, x.__name__), thresholdClasses)348 349351 ''' Given one of the dsOptions returned by getDataSourceOptions) 352 return an instance of the that RRDDataSource subclass. 353 ''' 354 for c, name in self.getThresholdClasses(): 355 if thresholdClassName == c.__name__: 356 return c(id) 357 raise ConfigurationError('Cannot find threshold class %s' % 358 thresholdClassName)359 360 361 InitializeClass(RRDTemplate) 362
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu Oct 25 16:28:39 2007 | http://epydoc.sourceforge.net |