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