Trees | Indices | Help |
|
---|
|
1 ############################################################################## 2 # 3 # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 4 # 5 # This content is made available according to terms specified in 6 # License.zenoss under the directory where your Zenoss product is installed. 7 # 8 ############################################################################## 9 10 11 from Globals import InitializeClass 12 from AccessControl import ClassSecurityInfo, Permissions 13 from Products.ZenModel.ZenossSecurity import * 14 15 from Products.ZenRelations.RelSchema import * 16 from Products.ZenUtils.Utils import prepId 17 from Products.ZenWidgets import messaging 18 from Products.ZenModel.WinServiceClass import WinServiceClass 19 from Service import Service 2023 """ 24 Create a WinService and add it to context. context should be a 25 device.os.winservices relationship. 26 """ 27 s = WinService(id) 28 # Indexing is subscribed to ObjectAddedEvent, which fires 29 # on _setObject, so we want to set service class first. 30 args = {'name':id, 'description':description} 31 s.__of__(context).setServiceClass(args) 32 context._setObject(id, s) 33 s = context._getOb(id) 34 s.serviceName = id 35 s.caption = description 36 if userCreated: s.setUserCreateFlag() 37 if REQUEST is not None: 38 REQUEST['RESPONSE'].redirect(context.absolute_url() 39 +'/manage_main') 40 return s41 4244 """Windows Service Class 45 """ 46 portal_type = meta_type = 'WinService' 47 48 serviceName = "" 49 caption = "" 50 pathName = "" 51 serviceType = "" 52 startMode = "" 53 startName = "" 54 monitoredStartModes = [] 55 collectors = ('zenwin',) 56 57 _properties = Service._properties + ( 58 {'id': 'serviceName', 'type':'string', 'mode':'w'}, 59 {'id': 'caption', 'type':'string', 'mode':'w'}, 60 {'id': 'pathName', 'type':'string', 'mode':'w'}, 61 {'id': 'serviceType', 'type':'string', 'mode':'w'}, 62 {'id': 'startMode', 'type':'string', 'mode':'w'}, 63 {'id': 'startName', 'type':'string', 'mode':'w'}, 64 {'id': 'monitoredStartModes', 'type':'lines', 'mode':'w'}, 65 ) 66 67 _relations = Service._relations + ( 68 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "winservices")), 69 ) 70 71 factory_type_information = ( 72 { 73 'immediate_view' : 'winServiceDetail', 74 'actions' : 75 ( 76 { 'id' : 'status' 77 , 'name' : 'Status' 78 , 'action' : 'winServiceDetail' 79 , 'permissions' : ( 80 Permissions.view, ) 81 }, 82 { 'id' : 'events' 83 , 'name' : 'Events' 84 , 'action' : 'viewEvents' 85 , 'permissions' : (ZEN_VIEW, ) 86 }, 87 { 'id' : 'manage' 88 , 'name' : 'Administration' 89 , 'action' : 'winServiceManage' 90 , 'permissions' : ("Manage DMD",) 91 }, 92 ) 93 }, 94 ) 95 96 security = ClassSecurityInfo() 97 98199 200 InitializeClass(WinService) 201100 """Return some text that describes this component. Default is name. 101 """ 102 return "'%s' StartMode:%s StartName:%s" % (self.caption, 103 self.startMode, self.startName)104 105107 if self.monitoredStartModes: 108 return self.monitoredStartModes 109 return self.serviceclass().monitoredStartModes110 111113 """Should this Windows Service be monitored 114 """ 115 startMode = getattr(self, "startMode", None) 116 #don't monitor Disabled services 117 if startMode and startMode == "Disabled": return False 118 return Service.monitored(self)119 120122 """ 123 Return the status number for this WinService 124 """ 125 if self.startMode not in self.getMonitoredStartModes(): 126 return -1 127 return Service.getStatus(self, statClass)128 129131 """Return a dict like one set by zenwinmodeler for services. 132 """ 133 desc = self.description 134 if not desc: 135 svccl = self.serviceclass() 136 if svccl: desc = svccl.description 137 return {'name': self.serviceName, 'description': self.caption }138 139141 """Set the service class where name=ServiceName and description=Caption. 142 """ 143 self.serviceName = kwargs['name'] 144 self.caption = kwargs['description'] 145 path = "/WinService/" 146 srvs = self.dmd.getDmdRoot("Services") 147 srvclass = srvs.createServiceClass( 148 name=self.serviceName, description=self.caption, path=path, factory=WinServiceClass) 149 self.serviceclass.addRelation(srvclass)150 151 156158 return self.caption159 primarySortKey = getCaption 160 161 security.declareProtected('Manage DMD', 'manage_editService')162 - def manage_editService(self, id=None, description=None, 163 pathName=None, serviceType=None, 164 startMode=None, startName=None, 165 monitoredStartModes=[], 166 monitor=False, severity=5, 167 REQUEST=None):168 """Edit a Service from a web page. 169 """ 170 msg = [] 171 renamed = False 172 if id is not None: 173 self.serviceName = id 174 self.description = description 175 self.caption = description 176 self.pathName = pathName 177 self.serviceType = serviceType 178 self.startMode = startMode 179 self.startName = startName 180 181 if self.id != id: 182 id = prepId(id) 183 self.setServiceClass(dict(name=id, description=description)) 184 renamed = self.rename(id) 185 186 if set(monitoredStartModes) != set(self.getMonitoredStartModes()): 187 self.monitoredStartModes = monitoredStartModes 188 msg.append("Updated monitored start modes") 189 190 tmpl = super(WinService, self).manage_editService( 191 monitor, severity, msg=msg, REQUEST=REQUEST) 192 if REQUEST and renamed: 193 messaging.IMessageSender(self).sendToBrowser( 194 'Service Renamed', 195 "Object renamed to: %s" % self.id 196 ) 197 return self.callZenScreen(REQUEST, renamed) 198 return tmpl
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1.1812 on Mon Jul 30 17:11:34 2012 | http://epydoc.sourceforge.net |