1
2
3
4
5
6
7
8
9
10
11
12
13
14 from Globals import InitializeClass
15 from AccessControl import ClassSecurityInfo
16 from AccessControl import Permissions
17 from Products.ZenModel.ZenossSecurity import *
18
19 from Commandable import Commandable
20 from Products.ZenRelations.RelSchema import *
21 from Products.ZenWidgets import messaging
22 from Acquisition import aq_chain
23
24 from OSComponent import OSComponent
25 from ZenPackable import ZenPackable
26
27
41
42
60
61
62 -class OSProcess(OSComponent, Commandable, ZenPackable):
63 """
64 OSProcess object
65 """
66 portal_type = meta_type = 'OSProcess'
67
68 procName = ""
69 parameters = ""
70 _procKey = ""
71
72 collectors = ('zenprocess','zencommand')
73
74 _properties = OSComponent._properties + (
75 {'id':'procName', 'type':'string', 'mode':'w'},
76 {'id':'parameters', 'type':'string', 'mode':'w'},
77 {'id':'zAlertOnRestarts', 'type':'boolean', 'mode':'w'},
78 {'id':'zFailSeverity', 'type':'int', 'mode':'w'},
79 )
80
81 _relations = OSComponent._relations + ZenPackable._relations + (
82 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "processes")),
83 ("osProcessClass", ToOne(ToMany, "Products.ZenModel.OSProcessClass", "instances")),
84 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
85 )
86
87 factory_type_information = (
88 {
89 'immediate_view' : 'osProcessDetail',
90 'actions' :
91 (
92 { 'id' : 'status'
93 , 'name' : 'Status'
94 , 'action' : 'osProcessDetail'
95 , 'permissions' : ( Permissions.view, )
96 },
97 { 'id' : 'events'
98 , 'name' : 'Events'
99 , 'action' : 'viewEvents'
100 , 'permissions' : (ZEN_VIEW, )
101 },
102 { 'id' : 'perfConf'
103 , 'name' : 'Template'
104 , 'action' : 'objTemplates'
105 , 'permissions' : ("Change Device", )
106 },
107 { 'id' : 'manage'
108 , 'name' : 'Administration'
109 , 'action' : 'osProcessManage'
110 , 'permissions' : ("Manage DMD",)
111 },
112 { 'id' : 'viewHistory'
113 , 'name' : 'Modifications'
114 , 'action' : 'viewHistory'
115 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,)
116 },
117 )
118 },
119 )
120
121 security = ClassSecurityInfo()
122
123
125 """
126 Return information used to monitor this process.
127 """
128 ignoreParams = getattr(self.osProcessClass(), 'ignoreParameters', False)
129 return (self.id, self.name(), ignoreParams,
130 self.alertOnRestart(), self.getFailSeverity())
131
132
134 """
135 Set the OSProcessClass based on procKey which is the proc + args.
136 We set by matching regular expressions of each proces class.
137 """
138 klass = self.getDmdObj(procKey)
139 klass.instances.addRelation(self)
140
141
143 """
144 Return the current procKey.
145 """
146 pClass = self.osProcessClass()
147 if pClass:
148 return pClass.getPrimaryDmdId()
149
150
163
164
166 """
167 Return a string that is the process name and, if ignoreParamaters
168 is not True, then also the parameters.
169 """
170 ignoreParams = getattr(self.osProcessClass(), 'ignoreParameters', False)
171 if not self.parameters or ignoreParams:
172 return self.procName
173 return self.procName + " " + self.parameters
174
175
177 """
178 Should this service be monitored or not. Use ServiceClass aq path.
179 """
180 return self.getAqProperty("zMonitor")
181
182
184 """
185 Retrieve the zProperty zAlertOnRestart
186 """
187 return self.getAqProperty("zAlertOnRestart")
188
189
191 """
192 Return a list of tuples with the possible severities
193 """
194 return self.ZenEventManager.getSeverities()
195
196
198 """
199 Return the severity for this service when it fails.
200 """
201 return self.getAqProperty("zFailSeverity")
202
203
205 """
206 Return a string representation of zFailSeverity
207 """
208 return self.ZenEventManager.severities[self.getAqProperty("zFailSeverity")]
209
210
212 """
213 Return the ProcessClass for this proc
214 """
215 return self.osProcessClass()
216
217
218 security.declareProtected('Manage DMD', 'manage_editOSProcess')
219 - def manage_editOSProcess(self, zMonitor=False, zAlertOnRestart=False,
220 zFailSeverity=3, msg=None,REQUEST=None):
237
238
240 '''
241 Called by Commandable.doCommand() to ascertain objects on which
242 a UserCommand should be executed.
243 '''
244 return [self]
245
246
255
256
258 """
259 Setup the aq chain as appropriate for the execution of a UserCommand
260 """
261 chain = aq_chain(self.getClassObject().primaryAq())
262 chain.insert(0, self)
263 return chain
264
265
267 """
268 Return the url where UserCommands are viewed for this object
269 """
270 return self.getPrimaryUrlPath() + '/osProcessManage'
271
290
291
292 InitializeClass(OSProcess)
293