| Trees | Indices | Help |
|
|---|
|
|
1 ###########################################################################
2 #
3 # This program is part of Zenoss Core, an open source monitoring platform.
4 # Copyright (C) 2007, Zenoss Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License version 2 or (at your
8 # option) any later version as published by the Free Software Foundation.
9 #
10 # For complete information please visit: http://www.zenoss.com/oss/
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
38 """make a RRDDataPoint"""
39 dp = RRDDataPoint(id)
40 context._setObject(dp.id, dp)
41 if REQUEST is not None:
42 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
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
66 """
67 Retrieve the datapoint/alias pairs for the passed alias.
68 """
69 return getDataPointsByAliases( context, [alias] )
70
71
72 #addRRDDataPoint = DTMLFile('dtml/addRRDDataPoint',globals())
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 ## These attributes can be removed post 2.1
102 ## They should remain in 2.1 so the migrate script works correctly
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 # Screen action bindings (and tab definitions)
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
146 """Return the breadcrumb links for this object add ActionRules list.
147 [('url','id'), ...]
148 """
149 from RRDTemplate import crumbspath
150 crumbs = super(RRDDataPoint, self).breadCrumbs(terminator)
151 return crumbspath(self.rrdTemplate(), crumbs, -3)
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
170 """
171 Add a new alias to this datapoint
172 """
173 manage_addDataPointAlias( self, id, formula )
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')
200 """
201 Add an alias to this datapoint
202 """
203 alias = manage_addDataPointAlias( self, id, formula )
204 if REQUEST:
205 return self.callZenScreen(REQUEST)
206 return alias
207
208
209 security.declareProtected(ZEN_MANAGE_DMD, 'manage_removeDataPointAliases')
211 """
212 Remove aliases from this datapoint
213 """
214 for id in ids:
215 self.removeAlias( id )
216 if REQUEST:
217 return self.callZenScreen(REQUEST)
218
219
220 security.declareProtected(ZEN_MANAGE_DMD, 'zmanage_editProperties')
222 """Edit a ZenModel object and return its proper page template
223 """
224 unused(redirect)
225 if REQUEST:
226 msgs = []
227 for optional in 'rrdmin', 'rrdmax':
228 v = REQUEST.form.get(optional, None)
229 if v:
230 try:
231 REQUEST.form[optional] = long(v)
232 except ValueError:
233 msgs.append('Unable to convert "%s" to a number' % v)
234 msgs = ', '.join(msgs)
235 if msgs:
236 messaging.IMessageSender(self).sendToBrowser(
237 'Properties Saved',
238 msgs[0].capitalize() + msgs[1:]
239 )
240 return self.callZenScreen(REQUEST, False)
241
242 return ZenModelRM.zmanage_editProperties(self, REQUEST)
243
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1.1812 on Tue Oct 11 12:51:52 2011 | http://epydoc.sourceforge.net |