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

# Source Code for Module Products.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 or (at your
      8  # option) any later version as published by 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      example = ""
     48      sequence = 0
     49
     50      _properties = (
     51          {'id':'name', 'type':'string', 'mode':'w'},
     52          {'id':'regex', 'type':'string', 'mode':'w'},
     53          {'id':'ignoreParameters', 'type':'boolean', 'mode':'w'},
     54          {'id':'description', 'type':'text', 'mode':'w'},
     55          {'id':'sequence', 'type':'int', 'mode':'w'},
     56          {'id':'example', 'type':'string', 'mode':'w'},
     57          )
     58
     59      _relations = ZenPackable._relations + (
     60          ("instances", ToMany(ToOne, "Products.ZenModel.OSProcess", "osProcessClass")),
     61          ("osProcessOrganizer",
     62              ToOne(ToManyCont,"Products.ZenModel.OSProcessOrganizer","osProcessClasses")),
     63          ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
     64          )
     65
     66
     67      factory_type_information = (
     68          {
     69              'immediate_view' : 'osProcessClassStatus',
     70              'actions'        :
     71              (
     72                  { 'id'            : 'status'
     73                  , 'name'          : 'Status'
     74                  , 'action'        : 'osProcessClassStatus'
     75                  , 'permissions'   : (
     76                    Permissions.view, )
     77                  },
     78                  { 'id'            : 'edit'
     79                  , 'name'          : 'Edit'
     80                  , 'action'        : 'osProcessClassEdit'
     81                  , 'permissions'   : ("Manage DMD", )
     82                  },
     83                  { 'id'            : 'manage'
     84                  , 'name'          : 'Administration'
     85                  , 'action'        : 'osProcessClassManage'
     86                  , 'permissions'   : ("Manage DMD",)
     87                  },
     88                  { 'id'            : 'zProperties'
     89                  , 'name'          : 'Configuration Properties'
     90                  , 'action'        : 'zPropertyEdit'
     91                  , 'permissions'   : ("Change Device",)
     92                  },
     93              )
     94           },
     95          )
     96
     97      security = ClassSecurityInfo()
     98
     99
    100 -    def __init__(self, id):
    101          self.title = id
    102          id = self.prepId(id)
    103          super(OSProcessClass, self).__init__(id)
    104          self.name = self.regex = id
    105
    106 -    def getOSProcessClassName(self):
    107          """Return the full name of this process class.
    108          """
    109          return self.getPrimaryDmdId("Processes", "osProcessClasses")
    110
    111
    112 -    def match(self, procKey):
    113          """match procKey against our regex.
    114          """
    115          return re.search(self.regex, procKey)
    116
    117
    118 -    def count(self):
    119          """Return count of instances in this class.
    120          """
    121          return self.instances.countObjects()
    122
    123
    124      security.declareProtected('Manage DMD', 'manage_editOSProcessClass')
    125 -    def manage_editOSProcessClass(self,
    126                                    name="",
    127                                    zMonitor=True,
    128                                    zAlertOnRestart=False,
    129                                    zFailSeverity=3,
    130                                    regex="",
    131                                    description="",
    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.ignoreParameters = ignoreParameters
    148          if REQUEST:
    149              from Products.ZenUtils.Time import SaveMessage
    150              messaging.IMessageSender(self).sendToBrowser(
    151                  'Product Class Saved',
    152                  SaveMessage()
    153              )
    154              return self.callZenScreen(REQUEST, redirect)
    155
    156
    157 -    def getUserCommandTargets(self):
    158          ''' Called by Commandable.doCommand() to ascertain objects on which
    159          a UserCommand should be executed.
    160          '''
    161          return self.instances()
    162
    163
    164 -    def getUrlForUserCommands(self):
    165          return self.getPrimaryUrlPath() + '/osProcessClassManage'
    166
    167
    168 -    def getPrimaryParentOrgName(self):
    169          ''' Return the organizer name for the primary parent
    170          '''
    171          return self.getPrimaryParent().getOrganizerName()
    172
    173
    174  InitializeClass(OSProcessClass)
    175