| Trees | Indices | Help |
|
|---|
|
|
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 or (at your 8 # option) any later version as published by the Free Software Foundation. 9 # 10 # For complete information please visit: http://www.zenoss.com/oss/ 11 # 12 ########################################################################### 13 14 from Globals import InitializeClass 15 from AccessControl import ClassSecurityInfo, Permissions 16 from Products.ZenModel.ZenossSecurity import * 17 18 from Products.ZenRelations.RelSchema import * 19 from Products.ZenUtils.Utils import prepId 20 from Products.ZenWidgets import messaging 21 from Products.ZenModel.WinServiceClass import WinServiceClass 22 from Service import Service 2326 """ 27 Create a WinService and add it to context. context should be a 28 device.os.winservices relationship. 29 """ 30 s = WinService(id) 31 # Indexing is subscribed to ObjectAddedEvent, which fires 32 # on _setObject, so we want to set service class first. 33 args = {'name':id, 'description':description} 34 s.__of__(context).setServiceClass(args) 35 context._setObject(id, s) 36 s = context._getOb(id) 37 s.serviceName = id 38 s.caption = description 39 if userCreated: s.setUserCreateFlag() 40 if REQUEST is not None: 41 REQUEST['RESPONSE'].redirect(context.absolute_url() 42 +'/manage_main') 43 return s44 4547 """Windows Service Class 48 """ 49 portal_type = meta_type = 'WinService' 50 51 serviceName = "" 52 caption = "" 53 pathName = "" 54 serviceType = "" 55 startMode = "" 56 startName = "" 57 monitoredStartModes = [] 58 collectors = ('zenwin',) 59 60 _properties = Service._properties + ( 61 {'id': 'serviceName', 'type':'string', 'mode':'w'}, 62 {'id': 'caption', 'type':'string', 'mode':'w'}, 63 {'id': 'pathName', 'type':'string', 'mode':'w'}, 64 {'id': 'serviceType', 'type':'string', 'mode':'w'}, 65 {'id': 'startMode', 'type':'string', 'mode':'w'}, 66 {'id': 'startName', 'type':'string', 'mode':'w'}, 67 {'id': 'monitoredStartModes', 'type':'lines', 'mode':'w'}, 68 ) 69 70 _relations = Service._relations + ( 71 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "winservices")), 72 ) 73 74 factory_type_information = ( 75 { 76 'immediate_view' : 'winServiceDetail', 77 'actions' : 78 ( 79 { 'id' : 'status' 80 , 'name' : 'Status' 81 , 'action' : 'winServiceDetail' 82 , 'permissions' : ( 83 Permissions.view, ) 84 }, 85 { 'id' : 'events' 86 , 'name' : 'Events' 87 , 'action' : 'viewEvents' 88 , 'permissions' : (ZEN_VIEW, ) 89 }, 90 { 'id' : 'manage' 91 , 'name' : 'Administration' 92 , 'action' : 'winServiceManage' 93 , 'permissions' : ("Manage DMD",) 94 }, 95 { 'id' : 'viewHistory' 96 , 'name' : 'Modifications' 97 , 'action' : 'viewHistory' 98 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 99 }, 100 ) 101 }, 102 ) 103 104 security = ClassSecurityInfo() 105 106207 208 InitializeClass(WinService) 209108 """Return some text that describes this component. Default is name. 109 """ 110 return "'%s' StartMode:%s StartName:%s" % (self.caption, 111 self.startMode, self.startName)112 113115 if self.monitoredStartModes: 116 return self.monitoredStartModes 117 return self.serviceclass().monitoredStartModes118 119121 """Should this Windows Service be monitored 122 """ 123 startMode = getattr(self, "startMode", None) 124 #don't monitor Disabled services 125 if startMode and startMode == "Disabled": return False 126 return Service.monitored(self)127 128130 """ 131 Return the status number for this WinService 132 """ 133 if self.startMode not in self.getMonitoredStartModes(): 134 return -1 135 return Service.getStatus(self, statClass)136 137139 """Return a dict like one set by zenwinmodeler for services. 140 """ 141 desc = self.description 142 if not desc: 143 svccl = self.serviceclass() 144 if svccl: desc = svccl.description 145 return {'name': self.serviceName, 'description': self.caption }146 147149 """Set the service class where name=ServiceName and description=Caption. 150 """ 151 self.serviceName = kwargs['name'] 152 self.caption = kwargs['description'] 153 path = "/WinService/" 154 srvs = self.dmd.getDmdRoot("Services") 155 srvclass = srvs.createServiceClass( 156 name=self.serviceName, description=self.caption, path=path, factory=WinServiceClass) 157 self.serviceclass.addRelation(srvclass)158 159 164166 return self.caption167 primarySortKey = getCaption 168 169 security.declareProtected('Manage DMD', 'manage_editService')170 - def manage_editService(self, id=None, description=None, 171 pathName=None, serviceType=None, 172 startMode=None, startName=None, 173 monitoredStartModes=[], 174 monitor=False, severity=5, 175 REQUEST=None):176 """Edit a Service from a web page. 177 """ 178 msg = [] 179 renamed = False 180 if id is not None: 181 self.serviceName = id 182 self.description = description 183 self.caption = description 184 self.pathName = pathName 185 self.serviceType = serviceType 186 self.startMode = startMode 187 self.startName = startName 188 189 if self.id != id: 190 id = prepId(id) 191 self.setServiceClass(dict(name=id, description=description)) 192 renamed = self.rename(id) 193 194 if set(monitoredStartModes) != set(self.getMonitoredStartModes()): 195 self.monitoredStartModes = monitoredStartModes 196 msg.append("Updated monitored start modes") 197 198 tmpl = super(WinService, self).manage_editService( 199 monitor, severity, msg=msg, REQUEST=REQUEST) 200 if REQUEST and renamed: 201 messaging.IMessageSender(self).sendToBrowser( 202 'Service Renamed', 203 "Object renamed to: %s" % self.id 204 ) 205 return self.callZenScreen(REQUEST, renamed) 206 return tmpl
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1.1812 on Thu Sep 1 19:03:28 2011 | http://epydoc.sourceforge.net |