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

Source Code for Module ZenModel.RRDDataSource

  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__="""RRDDataSource 
 15   
 16  Base class for DataSources 
 17  """ 
 18   
 19  import os 
 20   
 21  from Globals import DTMLFile 
 22  from Globals import InitializeClass 
 23  from DateTime import DateTime 
 24  from Acquisition import aq_parent 
 25  from AccessControl import ClassSecurityInfo, Permissions 
 26   
 27  from Products.PageTemplates.Expressions import getEngine 
 28   
 29  from Products.ZenUtils.ZenTales import talesCompile 
 30  from Products.ZenRelations.RelSchema import * 
 31   
 32  from ZenModelRM import ZenModelRM 
 33  from ZenPackable import ZenPackable 
 34   
 35   
36 -def manage_addRRDDataSource(context, id, dsOption, REQUEST = None):
37 """make a RRDDataSource""" 38 ds = context.getDataSourceInstance(id, dsOption, REQUEST=None) 39 context._setObject(ds.id, ds) 40 if REQUEST is not None: 41 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
42 43 44 #addRRDDataSource = DTMLFile('dtml/addRRDDataSource',globals()) 45 46
47 -def convertMethodParameter(value, type):
48 if type == "integer": 49 return int(value) 50 elif type == "string": 51 return str(value) 52 elif type == "float": 53 return float(value) 54 else: 55 raise TypeError('Unsupported method parameter type: %s' % type)
56 57 58 59 #class RRDDataSourceError(Exception): pass 60 61
62 -class RRDDataSource(ZenModelRM, ZenPackable):
63 64 meta_type = 'RRDDataSource' 65 66 paramtypes = ('integer', 'string', 'float') 67 sourcetypes = () 68 69 sourcetype = None 70 enabled = True 71 component = '' 72 eventClass = '' 73 eventKey = '' 74 severity = 3 75 commandTemplate = "" 76 cycletime = 300 77 78 _properties = ( 79 {'id':'sourcetype', 'type':'selection', 80 'select_variable' : 'sourcetypes', 'mode':'w'}, 81 {'id':'enabled', 'type':'boolean', 'mode':'w'}, 82 {'id':'component', 'type':'string', 'mode':'w'}, 83 {'id':'eventClass', 'type':'string', 'mode':'w'}, 84 {'id':'eventKey', 'type':'string', 'mode':'w'}, 85 {'id':'severity', 'type':'int', 'mode':'w'}, 86 {'id':'commandTemplate', 'type':'string', 'mode':'w'}, 87 {'id':'cycletime', 'type':'int', 'mode':'w'}, 88 ) 89 90 _relations = ZenPackable._relations + ( 91 ("rrdTemplate", ToOne(ToManyCont,"Products.ZenModel.RRDTemplate","datasources")), 92 ("datapoints", ToManyCont(ToOne,"Products.ZenModel.RRDDataPoint","datasource")), 93 ) 94 95 # Screen action bindings (and tab definitions) 96 factory_type_information = ( 97 { 98 'immediate_view' : 'editRRDDataSource', 99 'actions' : 100 ( 101 { 'id' : 'edit' 102 , 'name' : 'Data Source' 103 , 'action' : 'editRRDDataSource' 104 , 'permissions' : ( Permissions.view, ) 105 }, 106 ) 107 }, 108 ) 109 110 security = ClassSecurityInfo() 111 112
113 - def breadCrumbs(self, terminator='dmd'):
114 """Return the breadcrumb links for this object add ActionRules list. 115 [('url','id'), ...] 116 """ 117 from RRDTemplate import crumbspath 118 crumbs = super(RRDDataSource, self).breadCrumbs(terminator) 119 return crumbspath(self.rrdTemplate(), crumbs, -2)
120 121
122 - def getDescription(self):
123 return None
124 125
126 - def getRRDDataPoints(self):
127 return self.datapoints()
128 129
130 - def useZenCommand(self):
131 return False
132 133
134 - def manage_addRRDDataPoint(self, id, REQUEST = None):
135 """make a RRDDataPoint""" 136 if not id: 137 return self.callZenScreen(REQUEST) 138 from Products.ZenModel.RRDDataPoint import RRDDataPoint 139 dp = RRDDataPoint(id) 140 self.datapoints._setObject(dp.id, dp) 141 dp = self.datapoints._getOb(dp.id) 142 if REQUEST: 143 if dp: 144 #REQUEST['message'] = "Command Added" 145 url = '%s/datapoints/%s' % (self.getPrimaryUrlPath(), dp.id) 146 REQUEST['RESPONSE'].redirect(url) 147 return self.callZenScreen(REQUEST) 148 return dp
149 150
151 - def manage_deleteRRDDataPoints(self, ids=(), REQUEST=None):
152 """Delete RRDDataPoints from this RRDDataSource""" 153 154 def clean(rel, id): 155 for obj in rel(): 156 if id in obj.dsnames: 157 obj.dsnames.remove(id) 158 if not obj.dsnames: 159 rel._delObject(obj.id)
160 161 if not ids: return self.callZenScreen(REQUEST) 162 for id in ids: 163 dp = getattr(self.datapoints,id,False) 164 if dp: 165 if getattr(self, 'device', False): 166 perfConf = self.device().getPerformanceServer() 167 perfConf.deleteRRDFiles(device=self.device().id, datapoint=dp.name()) 168 else: 169 for d in self.deviceClass.obj.getSubDevicesGen(): 170 perfConf = d.getPerformanceServer() 171 perfConf.deleteRRDFiles(device=d.id, datapoint=dp.name()) 172 173 clean(self.graphs, dp.name()) 174 clean(self.thresholds, dp.name()) 175 self.datapoints._delObject(dp.id) 176 177 if REQUEST: 178 return self.callZenScreen(REQUEST)
179 180
181 - def getCommand(self, context, cmd=None):
182 """Return localized command target. 183 """ 184 # Perform a TALES eval on the expression using self 185 if cmd is None: 186 cmd = self.commandTemplate 187 exp = "string:"+ cmd 188 compiled = talesCompile(exp) 189 d = context.device() 190 environ = {'dev' : d, 191 'devname': d.id, 192 'here' : context, 193 'zCommandPath' : context.zCommandPath, 194 'nothing' : None, 195 'now' : DateTime() } 196 res = compiled(getEngine().getContext(environ)) 197 if isinstance(res, Exception): 198 raise res 199 res = self.checkCommandPrefix(context, res) 200 return res
201 202
203 - def checkCommandPrefix(self, context, cmd):
204 if not cmd.startswith('/') and not cmd.startswith('$'): 205 if not cmd.startswith(context.zCommandPath): 206 cmd = os.path.join(context.zCommandPath, cmd) 207 return cmd
208 209
210 - def getSeverityString(self):
211 return self.ZenEventManager.getSeverityString(self.severity)
212 213
214 - def zmanage_editProperties(self, REQUEST=None):
215 return ZenModelRM.zmanage_editProperties(self, REQUEST)
216