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

Source Code for Module ZenModel.ServiceOrganizer

  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  import types 
 15  import logging 
 16  log = logging.getLogger("zen.ServiceOrganizer") 
 17   
 18  from Globals import DTMLFile 
 19  from Globals import InitializeClass 
 20  from AccessControl import ClassSecurityInfo 
 21  from AccessControl import Permissions 
 22  from Acquisition import aq_base 
 23  from Commandable import Commandable 
 24  from ZenMenuable import ZenMenuable 
 25  from ZenPackable import ZenPackable 
 26   
 27  from Products.ZenRelations.RelSchema import * 
 28   
 29  from Organizer import Organizer 
 30  from ServiceClass import ServiceClass 
 31  from IpServiceClass import IpServiceClass 
 32   
33 -def manage_addServiceOrganizer(context, id, REQUEST = None):
34 """make a device class""" 35 sc = ServiceOrganizer(id) 36 context._setObject(id, sc) 37 sc = context._getOb(id) 38 if REQUEST is not None: 39 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
40 41 addServiceOrganizer = DTMLFile('dtml/addServiceOrganizer',globals()) 42
43 -class ServiceOrganizer(Organizer, Commandable, ZenPackable):
44 meta_type = "ServiceOrganizer" 45 dmdRootName = "Services" 46 default_catalog = "serviceSearch" 47 48 description = "" 49 50 _properties = ( 51 {'id':'description', 'type':'text', 'mode':'w'}, 52 ) 53 54 _relations = Organizer._relations + ZenPackable._relations + ( 55 ("serviceclasses", ToManyCont(ToOne,"Products.ZenModel.ServiceClass","serviceorganizer")), 56 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')), 57 ) 58 59 factory_type_information = ( 60 { 61 'id' : 'ServiceOrganizer', 62 'meta_type' : 'ServiceOrganizer', 63 'icon' : 'ServiceOrganizer.gif', 64 'product' : 'ZenModel', 65 'factory' : 'manage_addServiceOrganizer', 66 'immediate_view' : 'serviceOrganizerOverview', 67 'actions' : 68 ( 69 { 'id' : 'classes' 70 , 'name' : 'Classes' 71 , 'action' : 'serviceOrganizerOverview' 72 , 'permissions' : ( 73 Permissions.view, ) 74 }, 75 { 'id' : 'manage' 76 , 'name' : 'Administration' 77 , 'action' : 'serviceOrganizerManage' 78 , 'permissions' : ("Manage DMD",) 79 }, 80 { 'id' : 'zproperties' 81 , 'name' : 'zProperties' 82 , 'action' : 'zPropertyEdit' 83 , 'permissions' : ("Change Device",) 84 }, 85 { 'id' : 'viewHistory' 86 , 'name' : 'Modifications' 87 , 'action' : 'viewHistory' 88 , 'permissions' : ( 89 Permissions.view, ) 90 }, 91 ) 92 }, 93 ) 94 95 security = ClassSecurityInfo() 96
97 - def __init__(self, id=None):
98 if not id: id = self.dmdRootName 99 super(ServiceOrganizer, self).__init__(id) 100 if self.id == self.dmdRootName: 101 self.createCatalog() 102 self.buildZProperties()
103 104
105 - def find(self, query):
106 """Find a service class by is serviceKey. 107 """ 108 cat = getattr(self, self.default_catalog, None) 109 if not cat: return 110 brains = cat({'serviceKeys': query}) 111 if not brains: return None 112 try: 113 return self.getObjByPath(brains[0].getPrimaryId) 114 except KeyError: 115 log.warn("bad path '%s' for index '%s'", brains[0].getPrimaryId, 116 self.default_catalog)
117 118
119 - def countClasses(self):
120 """Count all serviceclasses with in a ServiceOrganizer. 121 """ 122 count = self.serviceclasses.countObjects() 123 for group in self.children(): 124 count += group.countClasses() 125 return count
126 127
128 - def createServiceClass(self, name="", description="", 129 path="", factory=ServiceClass, **kwargs):
130 """Create a service class (or retrun existing) based on keywords. 131 """ 132 svcs = self.getDmdRoot(self.dmdRootName) 133 svccl = svcs.find(name) 134 if not svccl: 135 svcorg = svcs.createOrganizer(path) 136 svccl = factory(name, (name,),description=description, **kwargs) 137 svcorg.serviceclasses._setObject(svccl.id, svccl) 138 svccl = svcorg.serviceclasses._getOb(svccl.id) 139 return svccl
140 141
142 - def manage_addServiceClass(self, id=None, REQUEST=None):
143 """Create a new service class in this Organizer. 144 """ 145 if id: 146 sc = ServiceClass(id) 147 self.serviceclasses._setObject(id, sc) 148 if REQUEST or not id: 149 return self.callZenScreen(REQUEST) 150 else: 151 return self.serviceclasses._getOb(id)
152 153
154 - def manage_addIpServiceClass(self, id=None, REQUEST=None):
155 """Create a new service class in this Organizer. 156 """ 157 if id: 158 sc = IpServiceClass(id) 159 self.serviceclasses._setObject(id, sc) 160 if REQUEST or not id: 161 return self.callZenScreen(REQUEST) 162 else: 163 return self.serviceclasses._getOb(id)
164 165
166 - def unmonitorServiceClasses(self, ids=None, REQUEST=None):
167 return self.monitorServiceClasses(ids, False, REQUEST)
168 169
170 - def monitorServiceClasses(self, ids=None, monitor=True, REQUEST=None):
171 """Remove ServiceClasses from an EventClass. 172 """ 173 if not ids: return self() 174 if type(ids) == types.StringType: ids = (ids,) 175 for id in ids: 176 svc = self.serviceclasses._getOb(id) 177 svc.setZenProperty("zMonitor", monitor) 178 if REQUEST: return self()
179 180
181 - def removeServiceClasses(self, ids=None, REQUEST=None):
182 """Remove ServiceClasses from an EventClass. 183 """ 184 if not ids: return self() 185 if type(ids) == types.StringType: ids = (ids,) 186 for id in ids: 187 self.serviceclasses._delObject(id) 188 if REQUEST: return self()
189 190
191 - def moveServiceClasses(self, moveTarget, ids=None, REQUEST=None):
192 """Move ServiceClasses from this EventClass to moveTarget. 193 """ 194 if not moveTarget or not ids: return self() 195 if type(ids) == types.StringType: ids = (ids,) 196 target = self.getChildMoveTarget(moveTarget) 197 for id in ids: 198 rec = self.serviceclasses._getOb(id) 199 rec._operation = 1 # moving object state 200 self.serviceclasses._delObject(id) 201 target.serviceclasses._setObject(id, rec) 202 if REQUEST: 203 REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())
204 205
206 - def buildZProperties(self):
207 if hasattr(aq_base(self), "zMonitor"): return 208 self._setProperty("zMonitor", False, type="boolean") 209 self._setProperty("zFailSeverity", 5, type="int") 210 self._setProperty("zHideFieldsFromList", [], type="lines")
211 212
213 - def reIndex(self):
214 """Go through all devices in this tree and reindex them.""" 215 zcat = self._getOb(self.default_catalog) 216 zcat.manage_catalogClear() 217 for srv in self.getSubOrganizers(): 218 for inst in srv.serviceclasses(): 219 inst.index_object()
220 221
222 - def createCatalog(self):
223 """Create a catalog for ServiceClass searching""" 224 from Products.ZCatalog.ZCatalog import manage_addZCatalog 225 manage_addZCatalog(self, self.default_catalog, 226 self.default_catalog) 227 zcat = self._getOb(self.default_catalog) 228 zcat.addIndex('serviceKeys', 'KeywordIndex') 229 zcat.addColumn('getPrimaryId')
230 231
232 - def getUserCommandTargets(self):
233 ''' Called by Commandable.doCommand() to ascertain objects on which 234 a UserCommand should be executed. 235 ''' 236 targets = [] 237 for sc in self.serviceclasses(): 238 targets += sc.getUserCommandTargets() 239 for so in self.children(): 240 targets += so.getUserCommandTargets() 241 return targets
242 243
244 - def getUrlForUserCommands(self):
245 return self.getPrimaryUrlPath() + '/serviceOrganizerManage'
246 247
248 - def getServiceLiveSearchList(self):
249 """ Get a list of id and descriptions for a live search 250 """ 251 liveSearchList = [] 252 for srv in self.getSubInstancesGen(rel='serviceclasses'): 253 if getattr(srv, 'description', None): 254 liveSearchList.append('%s [%s]' % (srv.id, srv.description)) 255 else: 256 liveSearchList.append(srv.id) 257 return liveSearchList
258
259 - def parseServiceLiveSearchString(self, str):
260 """ Parse a string of id and description from a live search 261 """ 262 id = str.split(' ') 263 if type(id) == types.TupleType: 264 id = id[0] 265 return id
266 267 268 InitializeClass(ServiceOrganizer) 269