1
2
3
4
5
6
7
8
9
10
11 __doc__="""RRDDataPoint
12
13 Defines attributes for how a datasource will be graphed
14 and builds the nessesary DEF and CDEF statements for it.
15
16 """
17
18 import logging
19 log = logging.getLogger('zen.RRDDatapoint')
20
21 import Globals
22 from AccessControl import ClassSecurityInfo, Permissions
23 from Products.ZenModel.ZenossSecurity import ZEN_VIEW, ZEN_MANAGE_DMD
24 from Products.ZenRelations.RelSchema import *
25 from Products.ZenWidgets import messaging
26
27 from ZenModelRM import ZenModelRM
28 from ZenPackable import ZenPackable
29
30 from Products.ZenUtils.Utils import unused, getDisplayType
31 from Products.ZenUtils.deprecated import deprecated
32 from Products.ZenModel.RRDDataPointAlias import manage_addDataPointAlias
41
43 """
44 Retrieve the datapoint/alias pairs for the passed aliases.
45 """
46 if not aliases: return
47 for brains in context.dmd.searchRRDTemplates():
48 template = brains.getObject()
49 for datasource in template.datasources():
50 if not hasattr(datasource, 'datapoints'):
51 log.error('The datasource %s on template %s is broken -- skipping',
52 datasource, template.getPrimaryUrlPath())
53 continue
54 for datapoint in datasource.datapoints():
55 thisDatapointsAliases = dict((dpAlias.id, dpAlias)
56 for dpAlias in datapoint.aliases())
57 for alias in aliases:
58 if alias in thisDatapointsAliases:
59 yield thisDatapointsAliases[alias], datapoint
60 if alias == datapoint.id:
61 yield None, datapoint
62
68
69
70
71
72 SEPARATOR = '_'
75 __pychecker__='no-returnvalues'
76 if type == "integer":
77 return int(value)
78 elif type == "string":
79 return str(value)
80 elif type == "float":
81 return float(value)
82 else:
83 raise TypeError('Unsupported method parameter type: %s' % type)
84
86
88
89 meta_type = 'RRDDataPoint'
90
91 rrdtypes = ('COUNTER', 'GAUGE', 'DERIVE', 'ABSOLUTE')
92
93 createCmd = ""
94 rrdtype = 'GAUGE'
95 isrow = True
96 rrdmin = None
97 rrdmax = None
98
99
100
101 linetypes = ('', 'AREA', 'LINE')
102 rpn = ""
103 color = ""
104 linetype = ''
105 limit = -1
106 format = '%5.2lf%s'
107
108
109 _properties = (
110 {'id':'rrdtype', 'type':'selection',
111 'select_variable' : 'rrdtypes', 'mode':'w'},
112 {'id':'createCmd', 'type':'text', 'mode':'w'},
113 {'id':'isrow', 'type':'boolean', 'mode':'w'},
114 {'id':'rrdmin', 'type':'string', 'mode':'w'},
115 {'id':'rrdmax', 'type':'string', 'mode':'w'},
116 {'id':'description', '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
153 """Include the data source name in our name,
154 useful for lists of DataPoints"""
155 return '%s%c%s' % (self.datasource().id, SEPARATOR, self.id)
156
157
159 """Get the create command.
160 Return '' for the default from performanceConf"""
161 unused(performanceConf)
162 if self.createCmd:
163 return self.createCmd
164 return ''
165
166
172
173
175 """
176 Whether this datapoint has an alias of this id
177 """
178 return hasattr( self.aliases, aliasId )
179
180
182 """
183 Remove any alias with the given id
184 """
185 if self.hasAlias( aliasId ):
186 self.aliases._delObject( aliasId )
187
188
190 """
191 Return all the ids of this datapoint's aliases
192 """
193 return [ alias.id for alias in self.aliases() ]
194
195
196 security.declareProtected(ZEN_MANAGE_DMD, 'manage_addDataPointAlias')
205
206
207 security.declareProtected(ZEN_MANAGE_DMD, 'manage_removeDataPointAliases')
216
217
218 security.declareProtected(ZEN_MANAGE_DMD, 'zmanage_editProperties')
241