Trees | Indices | Help |
|
---|
|
1 2 ########################################################################### 3 # 4 # This program is part of Zenoss Core, an open source monitoring platform. 5 # Copyright (C) 2007, Zenoss Inc. 6 # 7 # This program is free software; you can redistribute it and/or modify it 8 # under the terms of the GNU General Public License version 2 as published by 9 # the Free Software Foundation. 10 # 11 # For complete information please visit: http://www.zenoss.com/oss/ 12 # 13 ########################################################################### 14 15 __doc__="""MonitorClass 16 17 Organizes Monitors 18 19 $Id: MonitorClass.py,v 1.11 2004/04/09 00:34:39 edahl Exp $""" 20 21 __version__ = "$Revision$"[11:-2] 22 23 import types 24 25 from Globals import DTMLFile 26 from Globals import InitializeClass 27 from AccessControl import ClassSecurityInfo 28 from AccessControl import Permissions as permissions 29 from Acquisition import aq_base 30 from OFS.Folder import Folder 31 from Products.ZenUtils.Utils import checkClass 32 from ZenModelRM import ZenModelRM 33 from Products.ZenWidgets import messaging 34 35 from RRDTemplate import RRDTemplate 36 from TemplateContainer import TemplateContainer 3739 """make a device class""" 40 dc = MonitorClass(id, title) 41 context._setObject(id, dc) 42 43 if REQUEST is not None: 44 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')45 46 addMonitorClass = DTMLFile('dtml/addMonitorClass',globals()) 47 4850 #isInTree = 1 51 meta_type = "MonitorClass" 52 sub_class = 'MonitorClass' 53 dmdRootName = 'Monitors' 54 55 _properties = ( 56 {'id':'title', 'type':'string', 'mode':'w'}, 57 {'id':'sub_class', 'type':'string', 'mode':'w'}, 58 {'id':'sub_meta_types', 'type':'lines', 'mode':'w'}, 59 ) 60 61 factory_type_information = ( 62 { 63 'id' : 'MonitorClass', 64 'meta_type' : meta_type, 65 'description' : "Monitor Class", 66 'icon' : 'Classification_icon.gif', 67 'product' : 'ZenModel', 68 'factory' : 'manage_addMonitorClass', 69 'immediate_view' : 'monitorList', 70 'actions' : 71 ( 72 { 'id' : 'view' 73 , 'name' : 'View' 74 , 'action' : 'monitorList' 75 , 'permissions' : ( 76 permissions.view, ) 77 , 'visible' : 0 78 }, 79 ) 80 }, 81 ) 82 83 security = ClassSecurityInfo() 84 _relations = TemplateContainer._relations 85 88 89 92 93233 234 235 InitializeClass(MonitorClass) 23695 """get or create the performance monitor name""" 96 from Products.ZenModel.PerformanceConf \ 97 import manage_addPerformanceConf 98 perfServerObj = self.getDmdRoot("Monitors").Performance 99 if not hasattr(perfServerObj, monitorName): 100 manage_addPerformanceConf(perfServerObj, monitorName) 101 return perfServerObj._getOb(monitorName)102 103105 """return a list of all performance monitor names""" 106 perfServer = self.getDmdRoot("Monitors").Performance 107 cnames = perfServer.objectIds(spec=('PerformanceConf')) 108 cnames.sort() 109 return cnames110 111113 """get contained objects that are sub classes of sub_class""" 114 retdata = [] 115 for obj in self.objectValues(): 116 if checkClass(obj.__class__, self.sub_class): 117 retdata.append(obj) 118 return retdata119 120122 'Add an object of sub_class, from a module of the same name' 123 msg = '' 124 if type(ids) in types.StringTypes: 125 ids = (ids,) 126 child = self._getOb(submon, self) 127 if ids: 128 if len(ids) < len(child._objects): 129 num = 0 130 for id in ids: 131 if child.hasObject(id): 132 child._delObject(id) 133 num += 1 134 messaging.IMessageSender(self).sendToBrowser( 135 'Collectors Deleted', 136 'Deleted collectors: %s' % (', '.join(ids)) 137 ) 138 else: 139 messaging.IMessageSender(self).sendToBrowser( 140 'Error', 141 'You must have at least one collector.', 142 priority=messaging.WARNING 143 ) 144 else: 145 messaging.IMessageSender(self).sendToBrowser( 146 'Error', 147 'No collectors were selected.', 148 priority=messaging.WARNING 149 ) 150 if REQUEST: 151 return self.callZenScreen(REQUEST)152 153155 'Remove an object from this one' 156 values = {} 157 child = self._getOb(submon) or self 158 exec('from Products.ZenModel.%s import %s' % (child.sub_class, 159 child.sub_class), values) 160 ctor = values[child.sub_class] 161 if id: child._setObject(id, ctor(id)) 162 if REQUEST: 163 messaging.IMessageSender(self).sendToBrowser( 164 'Monitor Created', 165 'Monitor %s was created.' % id 166 ) 167 return self.callZenScreen(REQUEST)168 169171 """patch to export all device components 172 """ 173 for o in self.objectValues(): 174 if hasattr(aq_base(o), 'exportXml'): 175 o.exportXml(ofile, ignorerels)176 177179 """ 180 Return a list of all RRDTemplates at this level and below. 181 182 Note: DeviceClass.getAllRRDTemplates has been rewritted to 183 use the searchRRDTemplates catalog. Because there is only 184 one level of MonitorClass this approach might be overkill for 185 this situation. However, if MonitorClasses ever become 186 hierarchical and contain many RRDTemplates it should probably 187 be refactored in a similar way. 188 """ 189 return self.rrdTemplates()190 191 195 196 197 security.declareProtected('Add DMD Objects', 'manage_addRRDTemplate')199 """Add an RRDTemplate to this DeviceClass. 200 """ 201 if not id: return self.callZenScreen(REQUEST) 202 id = self.prepId(id) 203 org = RRDTemplate(id) 204 self.rrdTemplates._setObject(org.id, org) 205 if REQUEST: 206 messaging.IMessageSender(self).sendToBrowser( 207 'Template Added', 208 'Template %s was created.' % id 209 ) 210 return self.callZenScreen(REQUEST)211 212214 """Delete RRDTemplates from this MonitorClass 215 (skips ones in other Classes) 216 """ 217 if not ids and not paths: 218 return self.callZenScreen(REQUEST) 219 for id in ids: 220 self.rrdTemplates._delObject(id) 221 for path in paths: 222 id = path.split('/')[-1] 223 self.rrdTemplates._delObject(id) 224 if REQUEST: 225 messaging.IMessageSender(self).sendToBrowser( 226 'Templates Deleted', 227 'Templates were deleted: %s' % (', '.join(ids)) 228 ) 229 return self.callZenScreen(REQUEST)230
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jul 14 12:01:50 2010 | http://epydoc.sourceforge.net |