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

Source Code for Module Products.ZenModel.RRDDataPointAlias

 1  ############################################################################## 
 2  #  
 3  # Copyright (C) Zenoss, Inc. 2009, all rights reserved. 
 4  #  
 5  # This content is made available according to terms specified in 
 6  # License.zenoss under the directory where your Zenoss product is installed. 
 7  #  
 8  ############################################################################## 
 9   
10   
11  __doc__="""RRDDataPointAlias 
12   
13  Create a simple level of indirection for normalization of data.  An alias is 
14  a pair of a name and an rpn formula.  The formula should convert the datapoint 
15  to the form represented by the name. 
16   
17  $Id:$""" 
18  import Globals 
19  from AccessControl import ClassSecurityInfo, Permissions 
20   
21  from Products.ZenUtils.ZenTales import talesEvalStr 
22  from Products.ZenRelations.RelSchema import ToOne, ToManyCont 
23  from Products.ZenModel.ZenModelRM import ZenModelRM 
24  from Products.ZenModel.ZenPackable import ZenPackable 
25  from Products.ZenUtils.deprecated import deprecated 
26   
27   
28  ALIAS_DELIMITER = ',' 
29  EVAL_KEY = '__EVAL:' 
30 31 @deprecated 32 -def manage_addDataPointAlias( context, id, formula=None ):
33 """ 34 Add a datapoint alias to the datapoint given 35 """ 36 alias = RRDDataPointAlias( id ) 37 alias.formula = formula 38 context.aliases._setObject( id, alias ) 39 return context.aliases._getOb( id )
40
41 -class RRDDataPointAlias(ZenModelRM, ZenPackable):
42 43 meta_type = 'RRDDataPointAlias' 44 formula = None 45 46 _properties = ( 47 {'id':'formula', 'type':'string', 'mode':'w'}, 48 ) 49 50 _relations = ZenPackable._relations + ( 51 ("datapoint", ToOne(ToManyCont,"Products.ZenModel.RRDDataPoint","aliases")), 52 ) 53 54 55 # Screen action bindings (and tab definitions) 56 factory_type_information = ( 57 { 58 'immediate_view' : 'editRRDDataPoint', 59 'actions' : 60 ( 61 { 'id' : 'edit' 62 , 'name' : 'Data Point' 63 , 'action' : 'editRRDDataPoint' 64 , 'permissions' : ( Permissions.view, ) 65 }, 66 ) 67 }, 68 ) 69
70 - def evaluate(self, context):
71 """ 72 Evaluate the formula with the given context so that the resulting 73 rpn can be applied to the datapoint value. There are two possible 74 layers of evaluation: python and then TALES evaluation. Both use the 75 name 'here' to name the passed context. See testRRDDataPointAlias for 76 examples of usage. 77 """ 78 if self.formula: 79 formula = self.formula 80 if formula.startswith( EVAL_KEY ): 81 formula = formula[ len( EVAL_KEY ): ] 82 formula = str( eval( formula, { 'here' : context } ) ) 83 return talesEvalStr( formula, context ) 84 else: 85 return None
86