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

Source Code for Module ZenModel.RRDDataPoint

  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  __doc__="""RRDDataPoint 
 15   
 16  Defines attributes for how a datasource will be graphed 
 17  and builds the nessesary DEF and CDEF statements for it. 
 18   
 19  $Id:$""" 
 20   
 21  __version__ = "$Revision:$"[11:-2] 
 22   
 23  import Globals 
 24  from AccessControl import ClassSecurityInfo, Permissions 
 25  from Products.ZenModel.ZenossSecurity import ZEN_VIEW, ZEN_MANAGE_DMD 
 26   
 27  from Products.ZenRelations.RelSchema import * 
 28  from Products.ZenWidgets import messaging 
 29   
 30  from ZenModelRM import ZenModelRM 
 31  from ZenPackable import ZenPackable 
 32   
 33  from Products.ZenUtils.Utils import unused 
 34  from Products.ZenModel.RRDDataPointAlias import manage_addDataPointAlias 
 35   
36 -def manage_addRRDDataPoint(context, id, REQUEST = None):
37 """make a RRDDataPoint""" 38 dp = RRDDataPoint(id) 39 context._setObject(dp.id, dp) 40 if REQUEST is not None: 41 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
42
43 -def getDataPointsByAliases( context, aliases ):
44 """ 45 Retrieve the datapoint/alias pairs for the passed aliases. 46 """ 47 for brains in context.dmd.searchRRDTemplates(): 48 template = brains.getObject() 49 for datasource in template.datasources(): 50 for datapoint in datasource.datapoints(): 51 thisDatapointsAliases = dict( 52 [ ( dpAlias.id, dpAlias ) for dpAlias in 53 datapoint.aliases() ] ) 54 found = False 55 foundAlias = None 56 for alias in aliases: 57 if not found and thisDatapointsAliases.has_key( alias ): 58 found = True 59 foundAlias = thisDatapointsAliases[alias] 60 break 61 elif alias == datapoint.id: 62 found = True 63 break 64 if found: 65 yield foundAlias, datapoint
66
67 -def getDataPointsByAlias( context, alias ):
68 """ 69 Retrieve the datapoint/alias pairs for the passed alias. 70 """ 71 return getDataPointsByAliases( context, [alias] )
72 73 74 #addRRDDataPoint = DTMLFile('dtml/addRRDDataPoint',globals()) 75 76 SEPARATOR = '_' 77
78 -def convertMethodParameter(value, type):
79 __pychecker__='no-returnvalues' 80 if type == "integer": 81 return int(value) 82 elif type == "string": 83 return str(value) 84 elif type == "float": 85 return float(value) 86 else: 87 raise TypeError('Unsupported method parameter type: %s' % type)
88
89 -class RRDDataPointError(Exception): pass
90
91 -class RRDDataPoint(ZenModelRM, ZenPackable):
92 93 meta_type = 'RRDDataPoint' 94 95 rrdtypes = ('COUNTER', 'GAUGE', 'DERIVE', 'ABSOLUTE') 96 97 createCmd = "" 98 rrdtype = 'GAUGE' 99 isrow = True 100 rrdmin = None 101 rrdmax = None 102 103 ## These attributes can be removed post 2.1 104 ## They should remain in 2.1 so the migrate script works correctly 105 linetypes = ('', 'AREA', 'LINE') 106 rpn = "" 107 color = "" 108 linetype = '' 109 limit = -1 110 format = '%5.2lf%s' 111 112 113 _properties = ( 114 {'id':'rrdtype', 'type':'selection', 115 'select_variable' : 'rrdtypes', 'mode':'w'}, 116 {'id':'createCmd', 'type':'text', 'mode':'w'}, 117 {'id':'isrow', 'type':'boolean', 'mode':'w'}, 118 {'id':'rrdmin', 'type':'string', 'mode':'w'}, 119 {'id':'rrdmax', 'type':'string', 'mode':'w'}, 120 ) 121 122 123 _relations = ZenPackable._relations + ( 124 ("datasource", ToOne(ToManyCont,"Products.ZenModel.RRDDataSource","datapoints")), 125 ("aliases", ToManyCont(ToOne, "Products.ZenModel.RRDDataPointAlias","datapoint")) 126 ) 127 128 # Screen action bindings (and tab definitions) 129 factory_type_information = ( 130 { 131 'immediate_view' : 'editRRDDataPoint', 132 'actions' : 133 ( 134 { 'id' : 'edit' 135 , 'name' : 'Data Point' 136 , 'action' : 'editRRDDataPoint' 137 , 'permissions' : ( Permissions.view, ) 138 }, 139 ) 140 }, 141 ) 142 143 security = ClassSecurityInfo() 144 145
146 - def breadCrumbs(self, terminator='dmd'):
147 """Return the breadcrumb links for this object add ActionRules list. 148 [('url','id'), ...] 149 """ 150 from RRDTemplate import crumbspath 151 crumbs = super(RRDDataPoint, self).breadCrumbs(terminator) 152 return crumbspath(self.rrdTemplate(), crumbs, -3)
153 154 155 156 security.declareProtected(ZEN_VIEW, 'getPrimaryUrlPath')
157 - def getPrimaryUrlPath(self, ignored=None):
158 """get the physicalpath as a url""" 159 return self.absolute_url_path()
160 161
162 - def name(self):
163 """Include the data source name in our name, 164 useful for lists of DataPoints""" 165 return '%s%c%s' % (self.datasource().id, SEPARATOR, self.id)
166 167
168 - def getRRDCreateCommand(self, performanceConf):
169 """Get the create command. 170 Return '' for the default from performanceConf""" 171 unused(performanceConf) 172 if self.createCmd: 173 return self.createCmd 174 return ''
175 176
177 - def addAlias(self, id, formula=None):
178 """ 179 Add a new alias to this datapoint 180 """ 181 manage_addDataPointAlias( self, id, formula )
182 183
184 - def hasAlias(self, aliasId):
185 """ 186 Whether this datapoint has an alias of this id 187 """ 188 return hasattr( self.aliases, aliasId )
189 190
191 - def removeAlias(self, aliasId):
192 """ 193 Remove any alias with the given id 194 """ 195 if self.hasAlias( aliasId ): 196 self.aliases._delObject( aliasId )
197 198
199 - def getAliasNames(self):
200 """ 201 Return all the ids of this datapoint's aliases 202 """ 203 return [ alias.id for alias in self.aliases() ]
204 205 206 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addDataPointAlias')
207 - def manage_addDataPointAlias(self, id, formula, REQUEST=None ):
208 """ 209 Add an alias to this datapoint 210 """ 211 alias = manage_addDataPointAlias( self, id, formula ) 212 if REQUEST: 213 return self.callZenScreen(REQUEST) 214 return alias
215 216 217 security.declareProtected(ZEN_MANAGE_DMD, 'manage_removeDataPointAliases')
218 - def manage_removeDataPointAliases(self, ids=(), REQUEST=None ):
219 """ 220 Remove aliases from this datapoint 221 """ 222 for id in ids: 223 self.removeAlias( id ) 224 if REQUEST: 225 return self.callZenScreen(REQUEST)
226 227 228 security.declareProtected(ZEN_MANAGE_DMD, 'zmanage_editProperties')
229 - def zmanage_editProperties(self, REQUEST=None, redirect=False):
230 """Edit a ZenModel object and return its proper page template 231 """ 232 unused(redirect) 233 if REQUEST: 234 msgs = [] 235 for optional in 'rrdmin', 'rrdmax': 236 v = REQUEST.form.get(optional, None) 237 if v: 238 try: 239 REQUEST.form[optional] = long(v) 240 except ValueError: 241 msgs.append('Unable to convert "%s" to a number' % v) 242 msgs = ', '.join(msgs) 243 if msgs: 244 messaging.IMessageSender(self).sendToBrowser( 245 'Properties Saved', 246 msgs[0].capitalize() + msgs[1:] 247 ) 248 return self.callZenScreen(REQUEST, False) 249 250 return ZenModelRM.zmanage_editProperties(self, REQUEST)
251