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 """
20
21 import logging
22 log = logging.getLogger('zen.RRDDatapoint')
23
24 import Globals
25 from AccessControl import ClassSecurityInfo, Permissions
26 from Products.ZenModel.ZenossSecurity import ZEN_VIEW, ZEN_MANAGE_DMD
27
28 from Products.ZenRelations.RelSchema import *
29 from Products.ZenWidgets import messaging
30
31 from ZenModelRM import ZenModelRM
32 from ZenPackable import ZenPackable
33
34 from Products.ZenUtils.Utils import unused
35 from Products.ZenModel.RRDDataPointAlias import manage_addDataPointAlias
36
43
45 """
46 Retrieve the datapoint/alias pairs for the passed aliases.
47 """
48 if not aliases: return
49 for brains in context.dmd.searchRRDTemplates():
50 template = brains.getObject()
51 for datasource in template.datasources():
52 if not hasattr(datasource, 'datapoints'):
53 log.error('The datasource %s on template %s is broken -- skipping',
54 datasource, template.getPrimaryUrlPath())
55 continue
56 for datapoint in datasource.datapoints():
57 thisDatapointsAliases = dict((dpAlias.id, dpAlias)
58 for dpAlias in datapoint.aliases())
59 for alias in aliases:
60 if alias in thisDatapointsAliases:
61 yield thisDatapointsAliases[alias], datapoint
62 if alias == datapoint.id:
63 yield None, datapoint
64
70
71
72
73
74 SEPARATOR = '_'
75
77 __pychecker__='no-returnvalues'
78 if type == "integer":
79 return int(value)
80 elif type == "string":
81 return str(value)
82 elif type == "float":
83 return float(value)
84 else:
85 raise TypeError('Unsupported method parameter type: %s' % type)
86
88
90
91 meta_type = 'RRDDataPoint'
92
93 rrdtypes = ('COUNTER', 'GAUGE', 'DERIVE', 'ABSOLUTE')
94
95 createCmd = ""
96 rrdtype = 'GAUGE'
97 isrow = True
98 rrdmin = None
99 rrdmax = None
100
101
102
103 linetypes = ('', 'AREA', 'LINE')
104 rpn = ""
105 color = ""
106 linetype = ''
107 limit = -1
108 format = '%5.2lf%s'
109
110
111 _properties = (
112 {'id':'rrdtype', 'type':'selection',
113 'select_variable' : 'rrdtypes', 'mode':'w'},
114 {'id':'createCmd', 'type':'text', 'mode':'w'},
115 {'id':'isrow', 'type':'boolean', 'mode':'w'},
116 {'id':'rrdmin', 'type':'string', 'mode':'w'},
117 {'id':'rrdmax', 'type':'string', 'mode':'w'},
118 {'id':'description', 'type':'string', 'mode':'w'},
119 )
120
121
122 _relations = ZenPackable._relations + (
123 ("datasource", ToOne(ToManyCont,"Products.ZenModel.RRDDataSource","datapoints")),
124 ("aliases", ToManyCont(ToOne, "Products.ZenModel.RRDDataPointAlias","datapoint"))
125 )
126
127
128 factory_type_information = (
129 {
130 'immediate_view' : 'editRRDDataPoint',
131 'actions' :
132 (
133 { 'id' : 'edit'
134 , 'name' : 'Data Point'
135 , 'action' : 'editRRDDataPoint'
136 , 'permissions' : ( Permissions.view, )
137 },
138 )
139 },
140 )
141
142 security = ClassSecurityInfo()
143
144
152
153
155 """Include the data source name in our name,
156 useful for lists of DataPoints"""
157 return '%s%c%s' % (self.datasource().id, SEPARATOR, self.id)
158
159
161 """Get the create command.
162 Return '' for the default from performanceConf"""
163 unused(performanceConf)
164 if self.createCmd:
165 return self.createCmd
166 return ''
167
168
174
175
177 """
178 Whether this datapoint has an alias of this id
179 """
180 return hasattr( self.aliases, aliasId )
181
182
184 """
185 Remove any alias with the given id
186 """
187 if self.hasAlias( aliasId ):
188 self.aliases._delObject( aliasId )
189
190
192 """
193 Return all the ids of this datapoint's aliases
194 """
195 return [ alias.id for alias in self.aliases() ]
196
197
198 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addDataPointAlias')
207
208
209 security.declareProtected(ZEN_MANAGE_DMD, 'manage_removeDataPointAliases')
218
219
220 security.declareProtected(ZEN_MANAGE_DMD, 'zmanage_editProperties')
243