1
2
3
4
5
6
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:'
40
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
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
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