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 88228 229 230 InitializeClass(MonitorClass) 23190 """get or create the performance monitor name""" 91 from Products.ZenModel.PerformanceConf \ 92 import manage_addPerformanceConf 93 perfServerObj = self.getDmdRoot("Monitors").Performance 94 if not hasattr(perfServerObj, monitorName): 95 manage_addPerformanceConf(perfServerObj, monitorName) 96 return perfServerObj._getOb(monitorName)97 98100 """return a list of all performance monitor names""" 101 perfServer = self.getDmdRoot("Monitors").Performance 102 cnames = perfServer.objectIds(spec=('PerformanceConf')) 103 cnames.sort() 104 return cnames105 106108 """get contained objects that are sub classes of sub_class""" 109 retdata = [] 110 for obj in self.objectValues(): 111 if checkClass(obj.__class__, self.sub_class): 112 retdata.append(obj) 113 return retdata114 115117 'Add an object of sub_class, from a module of the same name' 118 msg = '' 119 if type(ids) in types.StringTypes: 120 ids = (ids,) 121 child = self._getOb(submon, self) 122 if ids: 123 if len(ids) < len(child._objects): 124 num = 0 125 for id in ids: 126 if child.hasObject(id): 127 child._delObject(id) 128 num += 1 129 messaging.IMessageSender(self).sendToBrowser( 130 'Monitors Deleted', 131 'Deleted monitors: %s' % (', '.join(ids)) 132 ) 133 else: 134 messaging.IMessageSender(self).sendToBrowser( 135 'Error', 136 'You must have at least one monitor.', 137 priority=messaging.WARNING 138 ) 139 else: 140 messaging.IMessageSender(self).sendToBrowser( 141 'Error', 142 'No monitors were selected.', 143 priority=messaging.WARNING 144 ) 145 if REQUEST: 146 return self.callZenScreen(REQUEST)147 148150 'Remove an object from this one' 151 values = {} 152 child = self._getOb(submon) or self 153 exec('from Products.ZenModel.%s import %s' % (child.sub_class, 154 child.sub_class), values) 155 ctor = values[child.sub_class] 156 if id: child._setObject(id, ctor(id)) 157 if REQUEST: 158 messaging.IMessageSender(self).sendToBrowser( 159 'Monitor Created', 160 'Monitor %s was created.' % id 161 ) 162 return self.callZenScreen(REQUEST)163 164166 """patch to export all device components 167 """ 168 for o in self.objectValues(): 169 if hasattr(aq_base(o), 'exportXml'): 170 o.exportXml(ofile, ignorerels)171 172174 """ 175 Return a list of all RRDTemplates at this level and below. 176 177 Note: DeviceClass.getAllRRDTemplates has been rewritted to 178 use the searchRRDTemplates catalog. Because there is only 179 one level of MonitorClass this approach might be overkill for 180 this situation. However, if MonitorClasses ever become 181 hierarchical and contain many RRDTemplates it should probably 182 be refactored in a similar way. 183 """ 184 return self.rrdTemplates()185 186 190 191 192 security.declareProtected('Add DMD Objects', 'manage_addRRDTemplate')194 """Add an RRDTemplate to this DeviceClass. 195 """ 196 if not id: return self.callZenScreen(REQUEST) 197 id = self.prepId(id) 198 org = RRDTemplate(id) 199 self.rrdTemplates._setObject(org.id, org) 200 if REQUEST: 201 messaging.IMessageSender(self).sendToBrowser( 202 'Template Added', 203 'Template %s was created.' % id 204 ) 205 return self.callZenScreen(REQUEST)206 207209 """Delete RRDTemplates from this MonitorClass 210 (skips ones in other Classes) 211 """ 212 if not ids and not paths: 213 return self.callZenScreen(REQUEST) 214 for id in ids: 215 self.rrdTemplates._delObject(id) 216 for path in paths: 217 id = path.split('/')[-1] 218 self.rrdTemplates._delObject(id) 219 if REQUEST: 220 messaging.IMessageSender(self).sendToBrowser( 221 'Templates Deleted', 222 'Templates were deleted: %s' % (', '.join(ids)) 223 ) 224 return self.callZenScreen(REQUEST)225
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu May 7 11:46:34 2009 | http://epydoc.sourceforge.net |