Package ZenModel :: Module OSProcess
[hide private]
[frames] | no frames]

Source Code for Module ZenModel.OSProcess

  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 
 16  from AccessControl import Permissions 
 17  from Commandable import Commandable 
 18  from Products.ZenRelations.RelSchema import * 
 19  from Acquisition import aq_chain 
 20  from zExceptions import NotFound 
 21   
 22  from OSComponent import OSComponent 
 23  from ZenPackable import ZenPackable 
 24   
25 -def manage_addOSProcess(context, className, userCreated, REQUEST=None):
26 """make an os process""" 27 id = className.split('/')[-1] 28 context._setObject(id, OSProcess(id)) 29 osp = context._getOb(id) 30 setattr(osp, 'procName', id) 31 osp.setOSProcessClass(className) 32 if userCreated: osp.setUserCreateFlag() 33 if REQUEST is not None: 34 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main') 35 return osp
36
37 -class OSProcess(OSComponent, Commandable, ZenPackable):
38 """Hardware object""" 39 portal_type = meta_type = 'OSProcess' 40 41 procName = "" 42 parameters = "" 43 _procKey = "" 44 collectors = ('zenprocess', ) 45 46 _properties = OSComponent._properties + ( 47 {'id':'procName', 'type':'string', 'mode':'w'}, 48 {'id':'parameters', 'type':'string', 'mode':'w'}, 49 {'id':'zAlertOnRestarts', 'type':'boolean', 'mode':'w'}, 50 {'id':'zFailSeverity', 'type':'int', 'mode':'w'}, 51 ) 52 53 _relations = OSComponent._relations + ZenPackable._relations + ( 54 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "processes")), 55 ("osProcessClass", ToOne(ToMany, "Products.ZenModel.OSProcessClass", "instances")), 56 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')), 57 ) 58 59 factory_type_information = ( 60 { 61 'immediate_view' : 'osProcessDetail', 62 'actions' : 63 ( 64 { 'id' : 'status' 65 , 'name' : 'Status' 66 , 'action' : 'osProcessDetail' 67 , 'permissions' : ( Permissions.view, ) 68 }, 69 { 'id' : 'perfConf' 70 , 'name' : 'Template' 71 , 'action' : 'objTemplates' 72 , 'permissions' : ("Change Device", ) 73 }, 74 { 'id' : 'manage' 75 , 'name' : 'Administration' 76 , 'action' : 'osProcessManage' 77 , 'permissions' : ("Manage DMD",) 78 }, 79 { 'id' : 'viewHistory' 80 , 'name' : 'Modifications' 81 , 'action' : 'viewHistory' 82 , 'permissions' : ( Permissions.view, ) 83 }, 84 ) 85 }, 86 ) 87 88 security = ClassSecurityInfo() 89
90 - def getOSProcessConf(self):
91 """Return information used to monitor this process. 92 """ 93 ignoreParams = getattr(self.osProcessClass(), 'ignoreParameters', False) 94 return (self.id, self.name(), ignoreParams, 95 self.alertOnRestart(), self.getFailSeverity())
96 97
98 - def setOSProcessClass(self, procKey):
99 """Set the OSProcessClass based on procKey which is the proc + args. 100 We set by matching regular expressions of each proces class. 101 """ 102 klass = self.getDmdObj(procKey) 103 klass.instances.addRelation(self)
104 105
106 - def getOSProcessClass(self):
107 """Return the current procKey. 108 """ 109 pClass = self.osProcessClass() 110 if pClass: 111 return pClass.getPrimaryDmdId()
112 113 125 126
127 - def name(self):
128 ignoreParams = getattr(self.osProcessClass(), 'ignoreParameters', False) 129 if not self.parameters or ignoreParams: 130 return self.procName 131 return self.procName + " " + self.parameters
132 133
134 - def monitored(self):
135 """Should this service be monitored or not. Use ServiceClass aq path. 136 """ 137 return self.getAqProperty("zMonitor")
138 139
140 - def alertOnRestart(self):
141 return self.getAqProperty("zAlertOnRestart")
142 143
144 - def getSeverities(self):
145 """Return a list of tuples with the possible severities 146 """ 147 return self.ZenEventManager.getSeverities()
148
149 - def getFailSeverity(self):
150 """Return the severity for this service when it fails. 151 """ 152 return self.getAqProperty("zFailSeverity")
153
154 - def getFailSeverityString(self):
155 """Return a string representation of zFailSeverity 156 """ 157 return self.ZenEventManager.severities[self.getAqProperty("zFailSeverity")]
158 159
160 - def getClassObject(self):
161 return self.osProcessClass()
162 163 164 security.declareProtected('Manage DMD', 'manage_editOSProcess')
165 - def manage_editOSProcess(self, zMonitor=False, zAlertOnRestart=False, 166 zFailSeverity=3, msg=None,REQUEST=None):
167 """Edit a Service from a web page. 168 """ 169 if msg is None: msg=[] 170 msg.append(self.setAqProperty("zMonitor", zMonitor, "boolean")) 171 msg.append(self.setAqProperty("zAlertOnRestart",zAlertOnRestart,"int")) 172 msg.append(self.setAqProperty("zFailSeverity",zFailSeverity,"int")) 173 msg = [ m for m in msg if m ] 174 self.index_object() 175 if not msg: msg.append("No action needed") 176 if REQUEST: 177 REQUEST['message'] = ", ".join(msg) + ":" 178 return self.callZenScreen(REQUEST)
179 180
181 - def getUserCommandTargets(self):
182 ''' Called by Commandable.doCommand() to ascertain objects on which 183 a UserCommand should be executed. 184 ''' 185 return [self]
186 187
189 environ = Commandable.getUserCommandEnvironment(self) 190 context = self.primaryAq() 191 environ.update({'proc': context, 'process': context,}) 192 return environ
193 194
196 chain = aq_chain(self.getClassObject().primaryAq()) 197 chain.insert(0, self) 198 return chain
199 200
201 - def getUrlForUserCommands(self):
202 return self.getPrimaryUrlPath() + '/osProcessManage'
203 204 205 InitializeClass(OSProcess) 206