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

# Source Code for Module Products.ZenModel.MonitorClass

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