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 Products.ZenModel.ZenossSecurity import * 
 21  from Commandable import Commandable 
 22  from Products.ZenRelations.RelSchema import * 
 23  from Products.ZenWidgets import messaging 
 24  from ZenPackable import ZenPackable 
 25   
 26  from ZenModelRM import ZenModelRM 
 27   
 28   
29 -def manage_addOSProcessClass(context, id=None, REQUEST = None):
30 """make a device class""" 31 if id: 32 context.manage_addOSProcessClass(id) 33 if REQUEST is not None: 34 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
35 36 addOSProcessClass = DTMLFile('dtml/addOSProcessClass',globals()) 37
38 -class OSProcessClass(ZenModelRM, Commandable, ZenPackable):
39 meta_type = "OSProcessClass" 40 dmdRootName = "Processes" 41 default_catalog = "processSearch" 42 43 name = "" 44 regex = "" 45 ignoreParameters = False 46 description = "" 47 sequence = 0 48 49 _properties = ( 50 {'id':'name', 'type':'string', 'mode':'w'}, 51 {'id':'regex', 'type':'string', 'mode':'w'}, 52 {'id':'ignoreParameters', 'type':'boolean', 'mode':'w'}, 53 {'id':'description', 'type':'text', 'mode':'w'}, 54 {'id':'sequence', 'type':'int', 'mode':'w'}, 55 ) 56 57 _relations = ZenPackable._relations + ( 58 ("instances", ToMany(ToOne, "Products.ZenModel.OSProcess", "osProcessClass")), 59 ("osProcessOrganizer", 60 ToOne(ToManyCont,"Products.ZenModel.OSProcessOrganizer","osProcessClasses")), 61 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')), 62 ) 63 64 65 factory_type_information = ( 66 { 67 'immediate_view' : 'osProcessClassStatus', 68 'actions' : 69 ( 70 { 'id' : 'status' 71 , 'name' : 'Status' 72 , 'action' : 'osProcessClassStatus' 73 , 'permissions' : ( 74 Permissions.view, ) 75 }, 76 { 'id' : 'edit' 77 , 'name' : 'Edit' 78 , 'action' : 'osProcessClassEdit' 79 , 'permissions' : ("Manage DMD", ) 80 }, 81 { 'id' : 'manage' 82 , 'name' : 'Administration' 83 , 'action' : 'osProcessClassManage' 84 , 'permissions' : ("Manage DMD",) 85 }, 86 { 'id' : 'zproperties' 87 , 'name' : 'zProperties' 88 , 'action' : 'zPropertyEdit' 89 , 'permissions' : ("Change Device",) 90 }, 91 { 'id' : 'viewHistory' 92 , 'name' : 'Modifications' 93 , 'action' : 'viewHistory' 94 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 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 from Products.ZenUtils.Utils import unused 142 unused(zAlertOnRestart, zFailSeverity, zMonitor) 143 # Left in name, added title for consistency 144 self.title = name 145 self.name = name 146 id = self.prepId(name) 147 redirect = self.rename(id) 148 self.regex = regex 149 self.description = description 150 self.ignoreParameters = ignoreParameters 151 if REQUEST: 152 from Products.ZenUtils.Time import SaveMessage 153 messaging.IMessageSender(self).sendToBrowser( 154 'Product Class Saved', 155 SaveMessage() 156 ) 157 return self.callZenScreen(REQUEST, redirect)
158 159
160 - def getUserCommandTargets(self):
161 ''' Called by Commandable.doCommand() to ascertain objects on which 162 a UserCommand should be executed. 163 ''' 164 return self.instances()
165 166
167 - def getUrlForUserCommands(self):
168 return self.getPrimaryUrlPath() + '/osProcessClassManage'
169 170
171 - def getPrimaryParentOrgName(self):
172 ''' Return the organizer name for the primary parent 173 ''' 174 return self.getPrimaryParent().getOrganizerName()
175 176 177 178 179 180 InitializeClass(OSProcessClass) 181