1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""Service.py
15
16 Service is a function provided by computer (like a server). it
17 is defined by a protocol type (udp/tcp) and a port number.
18
19 $Id: Service.py,v 1.15 2003/03/11 23:32:13 edahl Exp $"""
20
21 __version__ = "$Revision: 1.15 $"[11:-2]
22
23 import Globals
24 from Acquisition import aq_chain
25 from AccessControl import ClassSecurityInfo
26 from Commandable import Commandable
27
28 from Products.CMFCore.utils import getToolByName
29 from Products.ZenRelations.RelSchema import *
30 from Products.ZenWidgets import messaging
31
32 from OSComponent import OSComponent
33 from ZenPackable import ZenPackable
34
35 -class Service(OSComponent, Commandable, ZenPackable):
36 """
37 Service class
38 """
39 portal_type = meta_type = 'Service'
40
41 _relations = OSComponent._relations + ZenPackable._relations + (
42 ("serviceclass", ToOne(ToMany,"Products.ZenModel.ServiceClass","instances")),
43 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
44 )
45
46 security = ClassSecurityInfo()
47
49 """
50 Return tuple (manageIp, name) for this service to uniquely id it.
51 """
52 return (self.getManageIp(), self.name())
53
54
56 """
57 Return the name of this service. (short name for net stop/start).
58 """
59 svccl = self.serviceclass()
60 if svccl: return svccl.name
61 return ""
62
63
65 """
66 Should this service be monitored or not. Use ServiceClass aq path.
67 """
68 return self.monitor and self.getAqProperty("zMonitor")
69
70
72 """
73 Returns the same as "monitored" but from the catalog instead of from
74 the service class.
75 """
76 try:
77 index_dict = self.dmd.Devices.componentSearch.getIndexDataForUID(
78 self.getPrimaryId())
79 except KeyError:
80 return self.monitored()
81
82 return index_dict.get('monitored', self.monitored())
83
84
95
96
98 """
99 Return a list of tuples with the possible severities
100 """
101 return self.ZenEventManager.getSeverities()
102
103
105 """
106 Return the severity for this service when it fails.
107 """
108 return self.getAqProperty("zFailSeverity")
109
110
112 """
113 Return a string representation of zFailSeverity
114 """
115 return self.ZenEventManager.severities[self.getAqProperty("zFailSeverity")]
116
117
128
129
142
143
145 """
146 Return the ServiceClass for this service.
147 """
148 return self.serviceclass()
149
150
151 security.declareProtected('Manage DMD', 'manage_editService')
168
169
171 '''
172 Called by Commandable.doCommand() to ascertain objects on which
173 a UserCommand should be executed.
174 '''
175 return [self]
176
177
186
187
189 """
190 Setup the aq chain as appropriate for the execution of a UserCommand
191 """
192 chain = aq_chain(self.getClassObject().primaryAq())
193 chain.insert(0, self)
194 return chain
195
196
198 """
199 Return the url where UserCommands are viewed for this object
200 """
201 return self.getPrimaryUrlPath() + '/serviceManage'
202