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 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
72
73
74
75
76 SEPARATOR = '_'
77
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
90
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
104
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
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
153
154
155
156 security.declareProtected(ZEN_VIEW, 'getPrimaryUrlPath')
158 """get the physicalpath as a url"""
159 return self.absolute_url_path()
160
161
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
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
182
183
185 """
186 Whether this datapoint has an alias of this id
187 """
188 return hasattr( self.aliases, aliasId )
189
190
192 """
193 Remove any alias with the given id
194 """
195 if self.hasAlias( aliasId ):
196 self.aliases._delObject( aliasId )
197
198
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')
215
216
217 security.declareProtected(ZEN_MANAGE_DMD, 'manage_removeDataPointAliases')
226
227
228 security.declareProtected(ZEN_MANAGE_DMD, 'zmanage_editProperties')
251