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

Source Code for Module ZenModel.OSProcessClass

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