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
44
45
63
64
65 -class OSProcess(OSComponent, Commandable, ZenPackable):
66 """
67 OSProcess object
68 """
69 portal_type = meta_type = 'OSProcess'
70
71 procName = ""
72 parameters = ""
73 _procKey = ""
74
75 collectors = ('zenprocess','zencommand')
76
77 _properties = OSComponent._properties + (
78 {'id':'procName', 'type':'string', 'mode':'w'},
79 {'id':'parameters', 'type':'string', 'mode':'w'},
80 {'id':'zAlertOnRestarts', 'type':'boolean', 'mode':'w'},
81 {'id':'zFailSeverity', 'type':'int', 'mode':'w'},
82 )
83
84 _relations = OSComponent._relations + ZenPackable._relations + (
85 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "processes")),
86 ("osProcessClass", ToOne(ToMany, "Products.ZenModel.OSProcessClass", "instances")),
87 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
88 )
89
90 factory_type_information = (
91 {
92 'immediate_view' : 'osProcessDetail',
93 'actions' :
94 (
95 { 'id' : 'status'
96 , 'name' : 'Status'
97 , 'action' : 'osProcessDetail'
98 , 'permissions' : ( Permissions.view, )
99 },
100 { 'id' : 'events'
101 , 'name' : 'Events'
102 , 'action' : 'viewEvents'
103 , 'permissions' : (ZEN_VIEW, )
104 },
105 { 'id' : 'perfConf'
106 , 'name' : 'Template'
107 , 'action' : 'objTemplates'
108 , 'permissions' : ("Change Device", )
109 },
110 { 'id' : 'manage'
111 , 'name' : 'Administration'
112 , 'action' : 'osProcessManage'
113 , 'permissions' : ("Manage DMD",)
114 },
115 { 'id' : 'viewHistory'
116 , 'name' : 'Modifications'
117 , 'action' : 'viewHistory'
118 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,)
119 },
120 )
121 },
122 )
123
124 security = ClassSecurityInfo()
125
126
128 """
129 Return information used to monitor this process.
130 """
131 ignoreParams = getattr(self.osProcessClass(), 'ignoreParameters', False)
132 return (self.id, self.name(), ignoreParams,
133 self.alertOnRestart(), self.getFailSeverity())
134
135
137 """
138 Set the OSProcessClass based on procKey which is the proc + args.
139 We set by matching regular expressions of each proces class.
140 """
141 klass = self.getDmdObj(procKey)
142 klass.instances.addRelation(self)
143
144
146 """
147 Return the current procKey.
148 """
149 pClass = self.osProcessClass()
150 if pClass:
151 return pClass.getPrimaryDmdId()
152
153
166
167
169 """
170 Return a string that is the process name and, if ignoreParamaters
171 is not True, then also the parameters.
172 """
173 ignoreParams = getattr(self.osProcessClass(), 'ignoreParameters', False)
174 if not self.parameters or ignoreParams:
175 return self.procName
176 return self.procName + " " + self.parameters
177
178
180 """
181 Should this service be monitored or not. Use ServiceClass aq path.
182 """
183 return self.getAqProperty("zMonitor")
184
185
187 """
188 Retrieve the zProperty zAlertOnRestart
189 """
190 return self.getAqProperty("zAlertOnRestart")
191
192
194 """
195 Return a list of tuples with the possible severities
196 """
197 return self.ZenEventManager.getSeverities()
198
199
201 """
202 Return the severity for this service when it fails.
203 """
204 return self.getAqProperty("zFailSeverity")
205
206
208 """
209 Return a string representation of zFailSeverity
210 """
211 return self.ZenEventManager.severities[self.getAqProperty("zFailSeverity")]
212
213
215 """
216 Return the ProcessClass for this proc
217 """
218 return self.osProcessClass()
219
220
221 security.declareProtected('Manage DMD', 'manage_editOSProcess')
222 - def manage_editOSProcess(self, zMonitor=False, zAlertOnRestart=False,
223 zFailSeverity=3, msg=None,REQUEST=None):
240
241
243 '''
244 Called by Commandable.doCommand() to ascertain objects on which
245 a UserCommand should be executed.
246 '''
247 return [self]
248
249
258
259
261 """
262 Setup the aq chain as appropriate for the execution of a UserCommand
263 """
264 chain = aq_chain(self.getClassObject().primaryAq())
265 chain.insert(0, self)
266 return chain
267
268
270 """
271 Return the url where UserCommands are viewed for this object
272 """
273 return self.getPrimaryUrlPath() + '/osProcessManage'
274
293
294
295 InitializeClass(OSProcess)
296