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