Package Products :: Package ZenHub :: Package services :: Module ModelerService |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenHub.services.ModelerService

      1  ###########################################################################
      2  #
      3  # This program is part of Zenoss Core, an open source monitoring platform.
      4  # Copyright (C) 2008, 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  from Acquisition import aq_base
     15
     16  from PerformanceConfig import PerformanceConfig
     17  from Products.ZenHub.PBDaemon import translateError
     18  from Products.DataCollector.DeviceProxy import DeviceProxy
     19
     20  from Products.DataCollector.Plugins import loadPlugins
     21
     22  import logging
     23  log = logging.getLogger('zen.ModelerService')
     24
     25 -class ModelerService(PerformanceConfig):
     26
     27      plugins = None
     28
     29 -    def __init__(self, dmd, instance):
     30          PerformanceConfig.__init__(self, dmd, instance)
     31          self.config = self.dmd.Monitors.Performance._getOb(self.instance)
     32          self.methodPriorityMap = {
     33              'applyDataMaps': 0.75,
     34              }
     35
     36 -    def createDeviceProxy(self, dev):
     37          if self.plugins is None:
     38              self.plugins = {}
     39              for loader in loadPlugins(self.dmd):
     40                  try:
     41                      plugin = loader.create()
     42                      plugin.loader = loader
     43                      self.plugins[plugin.name()] = plugin
     44                  except Exception, ex:
     45                      log.exception(ex)
     46
     47          result = DeviceProxy()
     48          result.id = dev.getId()
     49          if not dev.manageIp:
     50              dev.setManageIp()
     51          result.manageIp = dev.manageIp
     52          result.plugins = []
     53          for name in dev.zCollectorPlugins:
     54              plugin = self.plugins.get(name, None)
     55              log.debug('checking plugin %s for device %s' % (name, dev.getId()))
     56              if plugin and plugin.condition(dev, log):
     57                  log.debug('adding plugin %s for device %s' % (name,dev.getId()))
     58                  result.plugins.append(plugin.loader)
     59                  plugin.copyDataToProxy(dev, result)
     60          result.temp_device = dev.isTempDevice()
     61          return result
     62
     63      @translateError
     64 -    def remote_getClassCollectorPlugins(self):
     65          result = []
     66          for dc in self.dmd.Devices.getSubOrganizers():
     67              localPlugins = getattr(aq_base(dc), 'zCollectorPlugins', False)
     68              if not localPlugins: continue
     69              result.append((dc.getOrganizerName(), localPlugins))
     70          return result
     71
     72      @translateError
     73 -    def remote_getDeviceConfig(self, names):
     74          result = []
     75          for name in names:
     76              device = self.getPerformanceMonitor().findDevice(name)
     77              if not device:
     78                  continue
     79              device = device.primaryAq()
     80              if (device.productionState <
     81                  device.getProperty('zProdStateThreshold', 0)):
     82                  continue
     83              result.append(self.createDeviceProxy(device))
     84          return result
     85
     86      @translateError
     87 -    def remote_getDeviceListByMonitor(self, monitor=None):
     88          if monitor is None:
     89              monitor = self.instance
     90          monitor = self.dmd.Monitors.Performance._getOb(monitor)
     91          return [d.id for d in monitor.devices.objectValuesGen()]
     92
     93      @translateError
     94 -    def remote_getDeviceListByOrganizer(self, organizer, monitor=None):
     95          if monitor is None:
     96              monitor = self.instance
     97          root = self.dmd.Devices.getOrganizer(organizer)
     98          return [d.id for d in root.getSubDevicesGen() \
     99              if d.getPerformanceServerName() == monitor]
    100
    101      @translateError
    102 -    def remote_applyDataMaps(self, device, maps, devclass=None):
    103          from Products.DataCollector.ApplyDataMap import ApplyDataMap
    104          device = self.getPerformanceMonitor().findDevice(device)
    105          adm = ApplyDataMap(self)
    106          adm.setDeviceClass(device, devclass)
    107          changed = False
    108          for map in maps:
    109              if adm._applyDataMap(device, map):
    110                  changed = True
    111          return changed
    112
    113      @translateError
    114 -    def remote_setSnmpLastCollection(self, device):
    115          device = self.getPerformanceMonitor().findDevice(device)
    116          device.setSnmpLastCollection()
    117          from transaction import commit
    118          commit()
    119
    120
    121
    122 -    def pushConfig(self, device):
    123          from twisted.internet.defer import succeed
    124          return succeed(device)
    125