1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""RRDDataPointAlias
15
16 Create a simple level of indirection for normalization of data. An alias is
17 a pair of a name and an rpn formula. The formula should convert the datapoint
18 to the form represented by the name.
19
20 $Id:$"""
21 import Globals
22 from AccessControl import ClassSecurityInfo, Permissions
23
24 from Products.ZenUtils.ZenTales import talesEvalStr
25 from Products.ZenRelations.RelSchema import ToOne, ToManyCont
26 from Products.ZenModel.ZenModelRM import ZenModelRM
27 from Products.ZenModel.ZenPackable import ZenPackable
28
29
30 ALIAS_DELIMITER = ','
31 EVAL_KEY = '__EVAL:'
32
41
43
44 meta_type = 'RRDDataPointAlias'
45 formula = None
46
47 _properties = (
48 {'id':'formula', 'type':'string', 'mode':'w'},
49 )
50
51 _relations = ZenPackable._relations + (
52 ("datapoint", ToOne(ToManyCont,"Products.ZenModel.RRDDataPoint","aliases")),
53 )
54
55
56
57 factory_type_information = (
58 {
59 'immediate_view' : 'editRRDDataPoint',
60 'actions' :
61 (
62 { 'id' : 'edit'
63 , 'name' : 'Data Point'
64 , 'action' : 'editRRDDataPoint'
65 , 'permissions' : ( Permissions.view, )
66 },
67 )
68 },
69 )
70
72 """
73 Evaluate the formula with the given context so that the resulting
74 rpn can be applied to the datapoint value. There are two possible
75 layers of evaluation: python and then TALES evaluation. Both use the
76 name 'here' to name the passed context. See testRRDDataPointAlias for
77 examples of usage.
78 """
79 if self.formula:
80 formula = self.formula
81 if formula.startswith( EVAL_KEY ):
82 formula = formula[ len( EVAL_KEY ): ]
83 formula = str( eval( formula, { 'here' : context } ) )
84 return talesEvalStr( formula, context )
85 else:
86 return None
87