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