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

# Source Code for Module Products.ZenModel.OSProcessOrganizer

      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 logging
     15  log = logging.getLogger("zen.OSProcessOrganizer")
     16
     17  from Globals import DTMLFile
     18  from Globals import InitializeClass
     19  from AccessControl import ClassSecurityInfo
     20  from AccessControl import Permissions
     21  from Products.ZenModel.ZenossSecurity import *
     22  from Acquisition import aq_base
     23  from Commandable import Commandable
     24  from Products.ZenRelations.RelSchema import *
     25  from ZenPackable import ZenPackable
     26
     27  from Organizer import Organizer
     28  from OSProcessClass import OSProcessClass
     29
     30 -def manage_addOSProcessOrganizer(context, id, REQUEST = None):
     31      """make a device class"""
     32      sc = OSProcessOrganizer(id)
     33      context._setObject(id, sc)
     34      sc = context._getOb(id)
     35      if REQUEST is not None:
     36          REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
     37
     38  addOSProcessOrganizer = DTMLFile('dtml/addOSProcessOrganizer',globals())
     39
     40 -class OSProcessOrganizer(Organizer, Commandable, ZenPackable):
     41      meta_type = "OSProcessOrganizer"
     42      dmdRootName = "Processes"
     43      #default_catalog = "osprocessSearch"
     44
     45      description = ""
     46
     47      _properties = (
     48          {'id':'description', 'type':'text', 'mode':'w'},
     49          )
     50
     51      _relations = Organizer._relations + ZenPackable._relations + (
     52          ("osProcessClasses", ToManyCont(
     53              ToOne,"Products.ZenModel.OSProcessClass","osProcessOrganizer")),
     54          ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
     55          )
     56
     57      factory_type_information = (
     58          {
     59              'immediate_view' : 'osProcessOrganizerOverview',
     60              'actions'        :
     61              (
     62                  { 'id'            : 'classes'
     63                  , 'name'          : 'Classes'
     64                  , 'action'        : 'osProcessOrganizerOverview'
     65                  , 'permissions'   : (
     66                    Permissions.view, )
     67                  },
     68                  { 'id'            : 'resequence'
     69                  , 'name'          : 'Sequence'
     70                  , 'action'        : 'osProcessResequence'
     71                  , 'permissions'   : (
     72                    Permissions.view, )
     73                  },
     74                  { 'id'            : 'manage'
     75                  , 'name'          : 'Administration'
     76                  , 'action'        : 'osProcessOrganizerManage'
     77                  , 'permissions'   : ("Manage DMD",)
     78                  },
     79                  { 'id'            : 'zProperties'
     80                  , 'name'          : 'Configuration Properties'
     81                  , 'action'        : 'zPropertyEdit'
     82                  , 'permissions'   : ("Change Device",)
     83                  },
     84              )
     85           },
     86          )
     87
     88      security = ClassSecurityInfo()
     89
     90 -    def __init__(self, id=None, description=None):
     91          if not id: id = self.dmdRootName
     92          super(OSProcessOrganizer, self).__init__(id, description)
     93          if self.id == self.dmdRootName:
     94              self.buildZProperties()
     95
     96
     97 -    def zentinelTabs(self, templateName):
     98          """Return a list of hashs that define the screen tabs for this object.
     99          [{'name':'Name','action':'template','selected':False},...]
    100          """
    101          tabs = Organizer.zentinelTabs(self, templateName)
    102          if self.getPrimaryId() != '/zport/dmd/Processes':
    103              tabs = [t for t in tabs if t['id'] != 'resequence']
    104          return tabs
    105
    106
    107 -    def getSubOSProcessClassesGen(self):
    108          """Return generator that goes through all process classes.
    109          """
    110          for proc in self.osProcessClasses.objectValuesGen():
    111              yield proc
    112          for subgroup in self.children():
    113              for proc in subgroup.getSubOSProcessClassesGen():
    114                  yield proc
    115
    116
    117 -    def getSubOSProcessClassesSorted(self):
    118          '''Return list of the process classes sorted by sequence.
    119          '''
    120          def cmpProc(a, b):
    121              return cmp(a.sequence, b.sequence)
    122          procs = list(self.getSubOSProcessClassesGen())
    123          procs.sort(cmpProc)
    124          for i, p in enumerate(procs):
    125              p.sequence = i
    126          return procs
    127
    128 -    def countClasses(self):
    129          """Count all osprocessclasses with in a ServiceOrganizer.
    130          """
    131          count = self.osProcessClasses.countObjects()
    132          for group in self.children():
    133              count += group.countClasses()
    134          return count
    135
    136
    137      security.declareProtected(ZEN_ADD, 'manage_addOSProcessClass')
    138 -    def manage_addOSProcessClass(self, id=None, REQUEST=None):
    139          """Create a new service class in this Organizer.
    140          """
    141          if id:
    142              sc = OSProcessClass(id)
    143              sc.sequence = len(self.osProcessClasses())
    144              self.osProcessClasses._setObject(id, sc)
    145          if REQUEST:
    146              return self.callZenScreen(REQUEST)
    147          else:
    148              return self.osProcessClasses._getOb(id)
    149
    150
    151 -    def manage_resequenceProcesses(self, seqmap=(), origseq=(), REQUEST=None):
    152          "resequence the OsProcesses"
    153          from Products.ZenUtils.Utils import resequence
    154          return resequence(self, self.getSubOSProcessClassesGen(),
    155                              seqmap, origseq, REQUEST)
    156
    157 -    def unmonitorOSProcessClasses(self, ids=None, REQUEST=None):
    158          return self.monitorOSProcessClasses(ids, False, REQUEST)
    159
    160
    161 -    def monitorOSProcessClasses(self, ids=None, monitor=True, REQUEST=None):
    162          """Remove OSProcessClasses from an EventClass.
    163          """
    164          if not ids: return self()
    165          if isinstance(ids, basestring): ids = (ids,)
    166          for id in ids:
    167              svc = self.osProcessClasses._getOb(id)
    168              svc.setZenProperty("zMonitor", monitor)
    169          if REQUEST: return self()
    170
    171
    172 -    def removeOSProcessClasses(self, ids=None, REQUEST=None):
    173          """Remove OSProcessClasses from an EventClass.
    174          """
    175          if not ids: return self()
    176          if isinstance(ids, basestring): ids = (ids,)
    177          for id in ids:
    178              # delete related os process instances
    179              klass = self.osProcessClasses._getOb(id)
    180              for p in klass.instances():
    181                  p.device().os.processes._delObject(p.id)
    182              self.osProcessClasses._delObject(id)
    183          self.manage_resequenceProcesses()
    184          if REQUEST: return self()
    185
    186
    187 -    def moveOSProcessClasses(self, moveTarget, ids=None, REQUEST=None):
    188          """Move OSProcessClasses from this EventClass to moveTarget.
    189          """
    190          if not moveTarget or not ids: return self()
    191          if isinstance(ids, basestring): ids = (ids,)
    192          target = self.getChildMoveTarget(moveTarget)
    193          for id in ids:
    194              rec = self.osProcessClasses._getOb(id)
    195              rec._operation = 1 # moving object state
    196              self.osProcessClasses._delObject(id)
    197              target.osProcessClasses._setObject(id, rec)
    198          if REQUEST:
    199              REQUEST['RESPONSE'].redirect(target.getPrimaryUrlPath())
    200
    201
    202 -    def buildZProperties(self):
    203          if hasattr(aq_base(self), "zCountProcs"): return
    204          self._setProperty("zCountProcs", False, type="boolean")
    205          self._setProperty("zAlertOnRestart", False, type="boolean")
    206          self._setProperty("zMonitor", True, type="boolean")
    207          self._setProperty("zFailSeverity", 4, type="int")
    208
    209
    210 -    def getUserCommandTargets(self):
    211          ''' Called by Commandable.doCommand() to ascertain objects on which
    212          a UserCommand should be executed.
    213          '''
    214          targets = []
    215          for osc in self.osProcessClasses():
    216              targets += osc.getUserCommandTargets()
    217          for org in self.children():
    218              targets += org.getUserCommandTargets()
    219          return targets
    220
    221
    222 -    def getUrlForUserCommands(self):
    223          return self.getPrimaryUrlPath() + '/osProcessOrganizerManage'
    224
    225
    226  InitializeClass(OSProcessOrganizer)
    227