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 -    def getPerformanceMonitor(self, monitorName):
     90          """get or create the performance monitor name"""
     91          from Products.ZenModel.PerformanceConf \
     92              import manage_addPerformanceConf
     93          perfServerObj = self.getDmdRoot("Monitors").Performance
     94          if not hasattr(perfServerObj, monitorName):
     95              manage_addPerformanceConf(perfServerObj, monitorName)
     96          return perfServerObj._getOb(monitorName)
     97
     98
     99 -    def getPerformanceMonitorNames(self):
    100          """return a list of all performance monitor names"""
    101          perfServer = self.getDmdRoot("Monitors").Performance
    102          cnames = perfServer.objectIds(spec=('PerformanceConf'))
    103          cnames.sort()
    104          return cnames
    105
    106
    107 -    def objectSubValues(self):
    108          """get contained objects that are sub classes of sub_class"""
    109          retdata = []
    110          for obj in self.objectValues():
    111              if checkClass(obj.__class__, self.sub_class):
    112                  retdata.append(obj)
    113          return retdata
    114
    115
    116 -    def manage_removeMonitor(self, ids = None, submon = "", REQUEST=None):
    117          'Add an object of sub_class, from a module of the same name'
    118          msg = ''
    119          if type(ids) in types.StringTypes:
    120              ids = (ids,)
    121          child = self._getOb(submon, self)
    122          if ids:
    123              if len(ids) < len(child._objects):
    124                  num = 0
    125                  for id in ids:
    126                      if child.hasObject(id):
    127                          child._delObject(id)
    128                          num += 1
    129                  messaging.IMessageSender(self).sendToBrowser(
    130                      'Monitors Deleted',
    131                      'Deleted monitors: %s' % (', '.join(ids))
    132                  )
    133              else:
    134                  messaging.IMessageSender(self).sendToBrowser(
    135                      'Error',
    136                      'You must have at least one monitor.',
    137                      priority=messaging.WARNING
    138                  )
    139          else:
    140              messaging.IMessageSender(self).sendToBrowser(
    141                  'Error',
    142                  'No monitors were selected.',
    143                  priority=messaging.WARNING
    144              )
    145          if REQUEST:
    146              return self.callZenScreen(REQUEST)
    147
    148
    149 -    def manage_addMonitor(self, id, submon=None, REQUEST=None):
    150          'Remove an object from this one'
    151          values = {}
    152          child = self._getOb(submon) or self
    153          exec('from Products.ZenModel.%s import %s' % (child.sub_class,
    154                                                        child.sub_class), values)
    155          ctor = values[child.sub_class]
    156          if id: child._setObject(id, ctor(id))
    157          if REQUEST:
    158              messaging.IMessageSender(self).sendToBrowser(
    159                  'Monitor Created',
    160                  'Monitor %s was created.' % id
    161              )
    162              return self.callZenScreen(REQUEST)
    163
    164
    165 -    def exportXmlHook(self, ofile, ignorerels):
    166          """patch to export all device components
    167          """
    168          for o in self.objectValues():
    169              if hasattr(aq_base(o), 'exportXml'):
    170                  o.exportXml(ofile, ignorerels)
    171
    172
    173 -    def getAllRRDTemplates(self):
    174          """
    175          Return a list of all RRDTemplates at this level and below.
    176
    177          Note: DeviceClass.getAllRRDTemplates has been rewritted to
    178          use the searchRRDTemplates catalog.  Because there is only
    179          one level of MonitorClass this approach might be overkill for
    180          this situation.  However, if MonitorClasses ever become
    181          hierarchical and contain many RRDTemplates it should probably
    182          be refactored in a similar way.
    183          """
    184          return self.rrdTemplates()
    185
    186
    187 -    def getRRDTemplates(self):
    188          "return the list of RRD Templates available at this level"
    189          return self.rrdTemplates()
    190
    191
    192      security.declareProtected('Add DMD Objects', 'manage_addRRDTemplate')
    193 -    def manage_addRRDTemplate(self, id, REQUEST=None):
    194          """Add an RRDTemplate to this DeviceClass.
    195          """
    196          if not id: return self.callZenScreen(REQUEST)
    197          id = self.prepId(id)
    198          org = RRDTemplate(id)
    199          self.rrdTemplates._setObject(org.id, org)
    200          if REQUEST:
    201              messaging.IMessageSender(self).sendToBrowser(
    202                  'Template Added',
    203                  'Template %s was created.' % id
    204              )
    205              return self.callZenScreen(REQUEST)
    206
    207
    208 -    def manage_deleteRRDTemplates(self, ids=(), paths=(), REQUEST=None):
    209          """Delete RRDTemplates from this MonitorClass
    210          (skips ones in other Classes)
    211          """
    212          if not ids and not paths:
    213              return self.callZenScreen(REQUEST)
    214          for id in ids:
    215              self.rrdTemplates._delObject(id)
    216          for path in paths:
    217              id = path.split('/')[-1]
    218              self.rrdTemplates._delObject(id)
    219          if REQUEST:
    220              messaging.IMessageSender(self).sendToBrowser(
    221                  'Templates Deleted',
    222                  'Templates were deleted: %s' % (', '.join(ids))
    223              )
    224              return self.callZenScreen(REQUEST)
    225
    226 -    def getSubDevicesGen(self):
    227          return []
    228
    229
    230  InitializeClass(MonitorClass)
    231