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

# Source Code for Module Products.ZenModel.MonitorClass

      1
      2  ###########################################################################
      3  #
      4  # This program is part of Zenoss Core, an open source monitoring platform.
      5  # Copyright (C) 2007, Zenoss Inc.
      6  #
      7  # This program is free software; you can redistribute it and/or modify it
      8  # under the terms of the GNU General Public License version 2 or (at your
      9  # option) any later version as published by the Free Software Foundation.
     10  #
     11  # For complete information please visit: http://www.zenoss.com/oss/
     12  #
     13  ###########################################################################
     14
     15  __doc__="""MonitorClass
     16
     17  Organizes Monitors
     18
     19  $Id: MonitorClass.py,v 1.11 2004/04/09 00:34:39 edahl Exp $"""
     20
     21  __version__ = "$Revision$"[11:-2]
     22
     23  from Globals import DTMLFile
     24  from Globals import InitializeClass
     25  from AccessControl import ClassSecurityInfo
     26  from AccessControl import Permissions as permissions
     27  from Acquisition import aq_base
     28  from OFS.Folder import Folder
     29  from Products.ZenUtils.Utils import checkClass
     30  from ZenModelRM import ZenModelRM
     31  from Products.ZenWidgets import messaging
     32
     33  from RRDTemplate import RRDTemplate
     34  from TemplateContainer import TemplateContainer
     35
     36 -def manage_addMonitorClass(context, id, title = None, REQUEST = None):
     37      """make a device class"""
     38      dc = MonitorClass(id, title)
     39      context._setObject(id, dc)
     40
     41      if REQUEST is not None:
     42          REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
     43
     44  addMonitorClass = DTMLFile('dtml/addMonitorClass',globals())
     45
     46
     47 -class MonitorClass(ZenModelRM, Folder, TemplateContainer):
     48      #isInTree = 1
     49      meta_type = "MonitorClass"
     50      sub_class = 'MonitorClass'
     51      dmdRootName = 'Monitors'
     52
     53      _properties = (
     54          {'id':'title', 'type':'string', 'mode':'w'},
     55          {'id':'sub_class', 'type':'string', 'mode':'w'},
     56          {'id':'sub_meta_types', 'type':'lines', 'mode':'w'},
     57      )
     58
     59      factory_type_information = (
     60          {
     61              'id'             : 'MonitorClass',
     62              'meta_type'      : meta_type,
     63              'description'    : "Monitor Class",
     64              'icon'           : 'Classification_icon.gif',
     65              'product'        : 'ZenModel',
     66              'factory'        : 'manage_addMonitorClass',
     67              'immediate_view' : 'monitorList',
     68              'actions'        :
     69              (
     70                  { 'id'            : 'view'
     71                  , 'name'          : 'View'
     72                  , 'action'        : 'monitorList'
     73                  , 'permissions'   : (
     74                    permissions.view, )
     75                  , 'visible'       : 0
     76                  },
     77              )
     78            },
     79          )
     80
     81      security = ClassSecurityInfo()
     82      _relations = TemplateContainer._relations
     83
     84 -    def __init__(self, id, title=None, buildRelations=True):
     85          ZenModelRM.__init__(self, id, title, buildRelations)
     86
     87
     88 -    def getBreadCrumbName(self):
     89          return 'Collectors'
     90
     91
     92 -    def getPerformanceMonitor(self, monitorName):
     93          """get or create the performance monitor name"""
     94          from Products.ZenModel.PerformanceConf \
     95              import manage_addPerformanceConf
     96          perfServerObj = self.getDmdRoot("Monitors").Performance
     97          if not hasattr(perfServerObj, monitorName):
     98              manage_addPerformanceConf(perfServerObj, monitorName)
     99          return perfServerObj._getOb(monitorName)
    100
    101
    102 -    def getPerformanceMonitorNames(self):
    103          """return a list of all performance monitor names"""
    104          perfServer = self.getDmdRoot("Monitors").Performance
    105          cnames = perfServer.objectIds(spec=('PerformanceConf'))
    106          cnames.sort()
    107          return cnames
    108
    109
    110 -    def objectSubValues(self):
    111          """get contained objects that are sub classes of sub_class"""
    112          retdata = []
    113          for obj in self.objectValues():
    114              if checkClass(obj.__class__, self.sub_class):
    115                  retdata.append(obj)
    116          return retdata
    117
    118
    119 -    def manage_removeMonitor(self, ids = None, submon = "", REQUEST=None):
    120          'Add an object of sub_class, from a module of the same name'
    121          msg = ''
    122          if isinstance(ids, basestring):
    123              ids = (ids,)
    124          child = self._getOb(submon, self)
    125          if ids:
    126              if len(ids) < len(child._objects):
    127                  num = 0
    128                  for id in ids:
    129                      if child.hasObject(id):
    130                          child._delObject(id)
    131                          num += 1
    132                  messaging.IMessageSender(self).sendToBrowser(
    133                      'Collectors Deleted',
    134                      'Deleted collectors: %s' % (', '.join(ids))
    135                  )
    136              else:
    137                  messaging.IMessageSender(self).sendToBrowser(
    138                      'Error',
    139                      'You must have at least one collector.',
    140                      priority=messaging.WARNING
    141                  )
    142          else:
    143              messaging.IMessageSender(self).sendToBrowser(
    144                  'Error',
    145                  'No collectors were selected.',
    146                  priority=messaging.WARNING
    147              )
    148          if REQUEST:
    149              return self.callZenScreen(REQUEST)
    150
    151
    152 -    def manage_addMonitor(self, id, submon=None, REQUEST=None):
    153          'Remove an object from this one'
    154          values = {}
    155          child = self._getOb(submon) or self
    156          exec('from Products.ZenModel.%s import %s' % (child.sub_class,
    157                                                        child.sub_class), values)
    158          ctor = values[child.sub_class]
    159          if id: child._setObject(id, ctor(id))
    160          if REQUEST:
    161              messaging.IMessageSender(self).sendToBrowser(
    162                  'Monitor Created',
    163                  'Monitor %s was created.' % id
    164              )
    165              return self.callZenScreen(REQUEST)
    166
    167
    168 -    def exportXmlHook(self, ofile, ignorerels):
    169          """patch to export all device components
    170          """
    171          for o in self.objectValues():
    172              if hasattr(aq_base(o), 'exportXml'):
    173                  o.exportXml(ofile, ignorerels)
    174
    175
    176 -    def getAllRRDTemplates(self):
    177          """
    178          Return a list of all RRDTemplates at this level and below.
    179
    180          Note: DeviceClass.getAllRRDTemplates has been rewritted to
    181          use the searchRRDTemplates catalog.  Because there is only
    182          one level of MonitorClass this approach might be overkill for
    183          this situation.  However, if MonitorClasses ever become
    184          hierarchical and contain many RRDTemplates it should probably
    185          be refactored in a similar way.
    186          """
    187          return self.rrdTemplates()
    188
    189
    190 -    def getRRDTemplates(self):
    191          "return the list of RRD Templates available at this level"
    192          return self.rrdTemplates()
    193
    194
    195      security.declareProtected('Add DMD Objects', 'manage_addRRDTemplate')
    196 -    def manage_addRRDTemplate(self, id, REQUEST=None):
    197          """Add an RRDTemplate to this DeviceClass.
    198          """
    199          if not id: return self.callZenScreen(REQUEST)
    200          id = self.prepId(id)
    201          org = RRDTemplate(id)
    202          self.rrdTemplates._setObject(org.id, org)
    203          if REQUEST:
    204              messaging.IMessageSender(self).sendToBrowser(
    205                  'Template Added',
    206                  'Template %s was created.' % id
    207              )
    208              return self.callZenScreen(REQUEST)
    209
    210
    211 -    def manage_deleteRRDTemplates(self, ids=(), paths=(), REQUEST=None):
    212          """Delete RRDTemplates from this MonitorClass
    213          (skips ones in other Classes)
    214          """
    215          if not ids and not paths:
    216              return self.callZenScreen(REQUEST)
    217          for id in ids:
    218              self.rrdTemplates._delObject(id)
    219          for path in paths:
    220              id = path.split('/')[-1]
    221              self.rrdTemplates._delObject(id)
    222          if REQUEST:
    223              messaging.IMessageSender(self).sendToBrowser(
    224                  'Templates Deleted',
    225                  'Templates were deleted: %s' % (', '.join(ids))
    226              )
    227              return self.callZenScreen(REQUEST)
    228
    229 -    def getSubDevicesGen(self):
    230          return []
    231
    232
    233  InitializeClass(MonitorClass)
    234