Package Products :: Package ZenModel :: Module WinService
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenModel.WinService

  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  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   
 22  from Service import Service 
 23   
24 -def manage_addWinService(context, id, description, userCreated=None, 25 REQUEST=None):
26 """make a device""" 27 s = WinService(id) 28 context._setObject(id, s) 29 s = context._getOb(id) 30 s.description = description 31 args = {'name':id, 'description':description} 32 s.setServiceClass(args) 33 if userCreated: s.setUserCreateFlag() 34 if REQUEST is not None: 35 REQUEST['RESPONSE'].redirect(context.absolute_url() 36 +'/manage_main') 37 return s
38 39
40 -class WinService(Service):
41 """Windows Service Class 42 """ 43 portal_type = meta_type = 'WinService' 44 45 acceptPause = False 46 acceptStop = False 47 pathName = "" 48 serviceType = "" 49 startMode = "" 50 startName = "" 51 collectors = ('zenwin',) 52 53 _properties = Service._properties + ( 54 {'id': 'acceptPause', 'type':'boolean', 'mode':'w'}, 55 {'id': 'acceptStop', 'type':'boolean', 'mode':'w'}, 56 {'id': 'pathName', 'type':'string', 'mode':'w'}, 57 {'id': 'serviceType', 'type':'string', 'mode':'w'}, 58 {'id': 'startMode', 'type':'string', 'mode':'w'}, 59 {'id': 'startName', 'type':'string', 'mode':'w'}, 60 ) 61 62 _relations = Service._relations + ( 63 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "winservices")), 64 ) 65 66 factory_type_information = ( 67 { 68 'immediate_view' : 'winServiceDetail', 69 'actions' : 70 ( 71 { 'id' : 'status' 72 , 'name' : 'Status' 73 , 'action' : 'winServiceDetail' 74 , 'permissions' : ( 75 Permissions.view, ) 76 }, 77 { 'id' : 'events' 78 , 'name' : 'Events' 79 , 'action' : 'viewEvents' 80 , 'permissions' : (ZEN_VIEW, ) 81 }, 82 { 'id' : 'manage' 83 , 'name' : 'Administration' 84 , 'action' : 'winServiceManage' 85 , 'permissions' : ("Manage DMD",) 86 }, 87 { 'id' : 'viewHistory' 88 , 'name' : 'Modifications' 89 , 'action' : 'viewHistory' 90 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 91 }, 92 ) 93 }, 94 ) 95 96 security = ClassSecurityInfo() 97 98
99 - def getInstDescription(self):
100 """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
105 - def monitored(self):
106 """Should this Windows Service be monitored 107 """ 108 startMode = getattr(self, "startMode", None) 109 #don't monitor Disabled services 110 if startMode and startMode == "Disabled": return False 111 return Service.monitored(self)
112
113 - def getServiceClass(self):
114 """Return a dict like one set by zenwinmodeler for services. 115 """ 116 desc = self.description 117 if not desc: 118 svccl = self.serviceclass() 119 if svccl: desc = svccl.description 120 return {'name': self.name(), 'description': desc }
121 122
123 - def setServiceClass(self, kwargs):
124 """Set the service class where name=ServiceName and description=Caption. 125 """ 126 name = kwargs['name'] 127 description = kwargs['description'] 128 path = "/WinService/" 129 srvs = self.dmd.getDmdRoot("Services") 130 srvclass = srvs.createServiceClass(name=name, description=description, 131 path=path) 132 self.serviceclass.addRelation(srvclass)
133 134
135 - def caption(self):
136 """Return the windows caption for this service. 137 """ 138 svccl = self.serviceclass() 139 if svccl: return svccl.description 140 return ""
141 primarySortKey = caption 142 143 security.declareProtected('Manage DMD', 'manage_editService')
144 - def manage_editService(self, id=None, description=None, 145 acceptPause=None, acceptStop=None, 146 pathName=None, serviceType=None, 147 startMode=None, startName=None, 148 monitor=False, severity=5, 149 REQUEST=None):
150 """Edit a Service from a web page. 151 """ 152 renamed = False 153 if id is not None: 154 self.description = description 155 self.acceptPause = acceptPause 156 self.acceptStop = acceptStop 157 self.pathName = pathName 158 self.serviceType = serviceType 159 self.startMode = startMode 160 self.startName = startName 161 if self.id != id: 162 id = prepId(id) 163 self.setServiceClass(dict(name=id, description=description)) 164 renamed = self.rename(id) 165 tmpl = super(WinService, self).manage_editService(monitor, severity, 166 REQUEST=REQUEST) 167 if REQUEST and renamed: 168 messaging.IMessageSender(self).sendToBrowser( 169 'Service Renamed', 170 "Object renamed to: %s" % self.id 171 ) 172 return self.callZenScreen(REQUEST, renamed) 173 return tmpl
174 175 InitializeClass(WinService) 176