Package ZenModel :: Module RRDDataPoint
[hide private]
[frames] | no frames]

Source Code for Module ZenModel.RRDDataPoint

  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 as published by 
  8  # 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  $Id:$""" 
 20   
 21  __version__ = "$Revision:$"[11:-2] 
 22   
 23  import os 
 24   
 25  from Globals import DTMLFile 
 26  from Globals import InitializeClass 
 27  from AccessControl import ClassSecurityInfo, Permissions 
 28  from Acquisition import aq_parent 
 29   
 30  from Products.ZenRelations.RelSchema import * 
 31   
 32  from ZenModelRM import ZenModelRM 
 33  from ZenPackable import ZenPackable 
 34   
35 -def manage_addRRDDataPoint(context, id, REQUEST = None):
36 """make a RRDDataPoint""" 37 dp = RRDDataPoint(id) 38 context._setObject(dp.id, dp) 39 if REQUEST is not None: 40 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
41 42 #addRRDDataPoint = DTMLFile('dtml/addRRDDataPoint',globals()) 43 44 SEPARATOR = '_' 45
46 -def convertMethodParameter(value, type):
47 if type == "integer": 48 return int(value) 49 elif type == "string": 50 return str(value) 51 elif type == "float": 52 return float(value) 53 else: 54 raise TypeError('Unsupported method parameter type: %s' % type)
55
56 -class RRDDataPointError(Exception): pass
57
58 -class RRDDataPoint(ZenModelRM, ZenPackable):
59 60 meta_type = 'RRDDataPoint' 61 62 rrdtypes = ('COUNTER', 'GAUGE', 'DERIVE', 'ABSOLUTE') 63 64 createCmd = "" 65 rrdtype = 'GAUGE' 66 isrow = True 67 rrdmin = None 68 rrdmax = None 69 70 ## These attributes can be removed post 2.1 71 ## They should remain in 2.1 so the migrate script works correctly 72 linetypes = ('', 'AREA', 'LINE') 73 rpn = "" 74 color = "" 75 linetype = '' 76 limit = -1 77 format = '%5.2lf%s' 78 79 80 _properties = ( 81 {'id':'rrdtype', 'type':'selection', 82 'select_variable' : 'rrdtypes', 'mode':'w'}, 83 {'id':'createCmd', 'type':'text', 'mode':'w'}, 84 {'id':'isrow', 'type':'boolean', 'mode':'w'}, 85 {'id':'rrdmin', 'type':'string', 'mode':'w'}, 86 {'id':'rrdmax', 'type':'string', 'mode':'w'}, 87 ) 88 89 90 _relations = ZenPackable._relations + ( 91 ("datasource", ToOne(ToManyCont,"Products.ZenModel.RRDDataSource","datapoints")), 92 ) 93 94 # Screen action bindings (and tab definitions) 95 factory_type_information = ( 96 { 97 'immediate_view' : 'editRRDDataPoint', 98 'actions' : 99 ( 100 { 'id' : 'edit' 101 , 'name' : 'Data Point' 102 , 'action' : 'editRRDDataPoint' 103 , 'permissions' : ( Permissions.view, ) 104 }, 105 ) 106 }, 107 ) 108 109 security = ClassSecurityInfo() 110 111
112 - def breadCrumbs(self, terminator='dmd'):
113 """Return the breadcrumb links for this object add ActionRules list. 114 [('url','id'), ...] 115 """ 116 from RRDTemplate import crumbspath 117 crumbs = super(RRDDataPoint, self).breadCrumbs(terminator) 118 return crumbspath(self.rrdTemplate(), crumbs, -3)
119 120 121 122 security.declareProtected('View', 'getPrimaryUrlPath')
123 - def getPrimaryUrlPath(self):
124 """get the physicalpath as a url""" 125 return self.absolute_url_path()
126 127
128 - def name(self):
129 """Include the data source name in our name, 130 useful for lists of DataPoints""" 131 return '%s%c%s' % (self.datasource().id, SEPARATOR, self.id)
132
133 - def getRRDCreateCommand(self, performanceConf):
134 """Get the create command. 135 Return '' for the default from performanceConf""" 136 if self.createCmd: 137 return self.createCmd 138 return ''
139 140 141 security.declareProtected('Manage DMD', 'zmanage_editProperties')
142 - def zmanage_editProperties(self, REQUEST=None):
143 """Edit a ZenModel object and return its proper page template 144 """ 145 if REQUEST: 146 msgs = [] 147 for optional in 'rrdmin', 'rrdmax': 148 v = REQUEST.form.get(optional, None) 149 if v: 150 try: 151 REQUEST.form[optional] = long(v) 152 except ValueError: 153 msgs.append('Unable to convert "%s" to a number' % v) 154 msgs = ', '.join(msgs) 155 if msgs: 156 REQUEST['message'] = msgs[0].capitalize() + msgs[1:] + ", at Time:" 157 return self.callZenScreen(REQUEST, False) 158 159 return ZenModelRM.zmanage_editProperties(self, REQUEST)
160