Package Products :: Package ZenModel :: Module OSProcessClass
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenModel.OSProcessClass

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
  4  #  
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  7  #  
  8  ############################################################################## 
  9   
 10   
 11  import re 
 12   
 13  from Globals import DTMLFile 
 14  from Globals import InitializeClass 
 15  from AccessControl import ClassSecurityInfo 
 16  from AccessControl import Permissions 
 17  from Products.ZenModel.ZenossSecurity import * 
 18  from Commandable import Commandable 
 19  from Products.ZenRelations.RelSchema import * 
 20  from Products.ZenWidgets import messaging 
 21  from ZenPackable import ZenPackable 
 22   
 23  from ZenModelRM import ZenModelRM 
 24   
 25   
26 -def manage_addOSProcessClass(context, id=None, REQUEST = None):
27 """make a device class""" 28 if id: 29 context.manage_addOSProcessClass(id) 30 if REQUEST is not None: 31 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
32 33 addOSProcessClass = DTMLFile('dtml/addOSProcessClass',globals()) 34
35 -class OSProcessClass(ZenModelRM, Commandable, ZenPackable):
36 meta_type = "OSProcessClass" 37 dmdRootName = "Processes" 38 default_catalog = "processSearch" 39 40 name = "" 41 regex = "" 42 ignoreParametersWhenModeling = False 43 ignoreParameters = False 44 description = "" 45 example = "" 46 sequence = 0 47 48 _properties = ( 49 {'id':'name', 'type':'string', 'mode':'w'}, 50 {'id':'regex', 'type':'string', 'mode':'w'}, 51 {'id': 'ignoreParametersWhenModeling', 'type':'boolean', 'mode':'w'}, 52 {'id':'ignoreParameters', 'type':'boolean', 'mode':'w'}, 53 {'id':'description', 'type':'text', 'mode':'w'}, 54 {'id':'sequence', 'type':'int', 'mode':'w'}, 55 {'id':'example', 'type':'string', 'mode':'w'}, 56 ) 57 58 _relations = ZenPackable._relations + ( 59 ("instances", ToMany(ToOne, "Products.ZenModel.OSProcess", "osProcessClass")), 60 ("osProcessOrganizer", 61 ToOne(ToManyCont,"Products.ZenModel.OSProcessOrganizer","osProcessClasses")), 62 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')), 63 ) 64 65 66 factory_type_information = ( 67 { 68 'immediate_view' : 'osProcessClassStatus', 69 'actions' : 70 ( 71 { 'id' : 'status' 72 , 'name' : 'Status' 73 , 'action' : 'osProcessClassStatus' 74 , 'permissions' : ( 75 Permissions.view, ) 76 }, 77 { 'id' : 'edit' 78 , 'name' : 'Edit' 79 , 'action' : 'osProcessClassEdit' 80 , 'permissions' : ("Manage DMD", ) 81 }, 82 { 'id' : 'manage' 83 , 'name' : 'Administration' 84 , 'action' : 'osProcessClassManage' 85 , 'permissions' : ("Manage DMD",) 86 }, 87 { 'id' : 'zProperties' 88 , 'name' : 'Configuration Properties' 89 , 'action' : 'zPropertyEdit' 90 , 'permissions' : ("Change Device",) 91 }, 92 ) 93 }, 94 ) 95 96 security = ClassSecurityInfo() 97 98
99 - def __init__(self, id):
100 self.title = id 101 id = self.prepId(id) 102 super(OSProcessClass, self).__init__(id) 103 self.name = self.regex = id
104
105 - def getOSProcessClassName(self):
106 """Return the full name of this process class. 107 """ 108 return self.getPrimaryDmdId("Processes", "osProcessClasses")
109 110
111 - def match(self, procKey):
112 """match procKey against our regex. 113 """ 114 return re.search(self.regex, procKey)
115 116
117 - def count(self):
118 """Return count of instances in this class. 119 """ 120 return self.instances.countObjects()
121 122 123 security.declareProtected('Manage DMD', 'manage_editOSProcessClass')
124 - def manage_editOSProcessClass(self, 125 name="", 126 zMonitor=True, 127 zAlertOnRestart=False, 128 zFailSeverity=3, 129 regex="", 130 description="", 131 ignoreParametersWhenModeling=False, 132 ignoreParameters=False, 133 REQUEST=None):
134 135 """ 136 Edit a ProductClass from a web page. 137 """ 138 from Products.ZenUtils.Utils import unused 139 unused(zAlertOnRestart, zFailSeverity, zMonitor) 140 # Left in name, added title for consistency 141 self.title = name 142 self.name = name 143 id = self.prepId(name) 144 redirect = self.rename(id) 145 self.regex = regex 146 self.description = description 147 self.ignoreParametersWhenModeling = ignoreParametersWhenModeling 148 self.ignoreParameters = ignoreParameters 149 if REQUEST: 150 from Products.ZenUtils.Time import SaveMessage 151 messaging.IMessageSender(self).sendToBrowser( 152 'Product Class Saved', 153 SaveMessage() 154 ) 155 return self.callZenScreen(REQUEST, redirect)
156 157
158 - def getUserCommandTargets(self):
159 ''' Called by Commandable.doCommand() to ascertain objects on which 160 a UserCommand should be executed. 161 ''' 162 return self.instances()
163 164
165 - def getUrlForUserCommands(self):
166 return self.getPrimaryUrlPath() + '/osProcessClassManage'
167 168
169 - def getPrimaryParentOrgName(self):
170 ''' Return the organizer name for the primary parent 171 ''' 172 return self.getPrimaryParent().getOrganizerName()
173 174 175 InitializeClass(OSProcessClass) 176