1
2
3
4
5
6
7
8
9
10
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
42
44 """
45 Retrieve the datapoint/alias pairs for the passed aliases.
46 """
47 if not aliases: return
48 for brains in context.dmd.searchRRDTemplates():
49 template = brains.getObject()
50 for datasource in template.datasources():
51 for datapoint in datasource.datapoints():
52 thisDatapointsAliases = dict(
53 [ ( dpAlias.id, dpAlias ) for dpAlias in
54 datapoint.aliases() ] )
55 found = False
56 foundAlias = None
57 for alias in aliases:
58 if thisDatapointsAliases.has_key( alias ):
59 found = True
60 yield thisDatapointsAliases[alias], datapoint
61 if alias == datapoint.id:
62 yield None, datapoint
63
69
70
71
72
73 SEPARATOR = '_'
74
76 __pychecker__='no-returnvalues'
77 if type == "integer":
78 return int(value)
79 elif type == "string":
80 return str(value)
81 elif type == "float":
82 return float(value)
83 else:
84 raise TypeError('Unsupported method parameter type: %s' % type)
85
87
89
90 meta_type = 'RRDDataPoint'
91
92 rrdtypes = ('COUNTER', 'GAUGE', 'DERIVE', 'ABSOLUTE')
93
94 createCmd = ""
95 rrdtype = 'GAUGE'
96 isrow = True
97 rrdmin = None
98 rrdmax = None
99
100
101
102 linetypes = ('', 'AREA', 'LINE')
103 rpn = ""
104 color = ""
105 linetype = ''
106 limit = -1
107 format = '%5.2lf%s'
108
109
110 _properties = (
111 {'id':'rrdtype', 'type':'selection',
112 'select_variable' : 'rrdtypes', 'mode':'w'},
113 {'id':'createCmd', 'type':'text', 'mode':'w'},
114 {'id':'isrow', 'type':'boolean', 'mode':'w'},
115 {'id':'rrdmin', 'type':'string', 'mode':'w'},
116 {'id':'rrdmax', 'type':'string', 'mode':'w'},
117 )
118
119
120 _relations = ZenPackable._relations + (
121 ("datasource", ToOne(ToManyCont,"Products.ZenModel.RRDDataSource","datapoints")),
122 ("aliases", ToManyCont(ToOne, "Products.ZenModel.RRDDataPointAlias","datapoint"))
123 )
124
125
126 factory_type_information = (
127 {
128 'immediate_view' : 'editRRDDataPoint',
129 'actions' :
130 (
131 { 'id' : 'edit'
132 , 'name' : 'Data Point'
133 , 'action' : 'editRRDDataPoint'
134 , 'permissions' : ( Permissions.view, )
135 },
136 )
137 },
138 )
139
140 security = ClassSecurityInfo()
141
142
150
151
152
153 security.declareProtected(ZEN_VIEW, 'getPrimaryUrlPath')
155 """get the physicalpath as a url"""
156 return self.absolute_url_path()
157
158
160 """Include the data source name in our name,
161 useful for lists of DataPoints"""
162 return '%s%c%s' % (self.datasource().id, SEPARATOR, self.id)
163
164
166 """Get the create command.
167 Return '' for the default from performanceConf"""
168 unused(performanceConf)
169 if self.createCmd:
170 return self.createCmd
171 return ''
172
173
179
180
182 """
183 Whether this datapoint has an alias of this id
184 """
185 return hasattr( self.aliases, aliasId )
186
187
189 """
190 Remove any alias with the given id
191 """
192 if self.hasAlias( aliasId ):
193 self.aliases._delObject( aliasId )
194
195
197 """
198 Return all the ids of this datapoint's aliases
199 """
200 return [ alias.id for alias in self.aliases() ]
201
202
203 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addDataPointAlias')
212
213
214 security.declareProtected(ZEN_MANAGE_DMD, 'manage_removeDataPointAliases')
223
224
225 security.declareProtected(ZEN_MANAGE_DMD, 'zmanage_editProperties')
248