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 or (at your
      8  # option) any later version as published by 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  from twisted.internet import defer, reactor
     16  from ZODB.transact import transact
     17  from PerformanceConfig import PerformanceConfig
     18  from Products.ZenHub.PBDaemon import translateError
     19  from Products.DataCollector.DeviceProxy import DeviceProxy
     20
     21  from Products.DataCollector.Plugins import loadPlugins
     22
     23  import logging
     24  log = logging.getLogger('zen.ModelerService')
     25
     26 -class ModelerService(PerformanceConfig):
     27
     28      plugins = None
     29
     30 -    def __init__(self, dmd, instance):
     31          PerformanceConfig.__init__(self, dmd, instance)
     32          self.config = self.dmd.Monitors.Performance._getOb(self.instance)
     33          self.methodPriorityMap = {
     34              'applyDataMaps': 0.5,
     35              }
     36
     37 -    def createDeviceProxy(self, dev):
     38          if self.plugins is None:
     39              self.plugins = {}
     40              for loader in loadPlugins(self.dmd):
     41                  try:
     42                      plugin = loader.create()
     43                      plugin.loader = loader
     44                      self.plugins[plugin.name()] = plugin
     45                  except Exception, ex:
     46                      log.exception(ex)
     47
     48          result = DeviceProxy()
     49          result.id = dev.getId()
     50          if not dev.manageIp:
     51              dev.setManageIp()
     52          result.manageIp = dev.manageIp
     53          result.plugins = []
     54          for name in dev.zCollectorPlugins:
     55              plugin = self.plugins.get(name, None)
     56              log.debug('checking plugin %s for device %s' % (name, dev.getId()))
     57              if plugin and plugin.condition(dev, log):
     58                  log.debug('adding plugin %s for device %s' % (name,dev.getId()))
     59                  result.plugins.append(plugin.loader)
     60                  plugin.copyDataToProxy(dev, result)
     61          result.temp_device = dev.isTempDevice()
     62          return result
     63
     64      @translateError
     65 -    def remote_getClassCollectorPlugins(self):
     66          result = []
     67          for dc in self.dmd.Devices.getSubOrganizers():
     68              localPlugins = getattr(aq_base(dc), 'zCollectorPlugins', False)
     69              if not localPlugins: continue
     70              result.append((dc.getOrganizerName(), localPlugins))
     71          return result
     72
     73      @translateError
     74 -    def remote_getDeviceConfig(self, names, checkStatus=False):
     75          result = []
     76          for name in names:
     77              device = self.getPerformanceMonitor().findDevice(name)
     78              if not device:
     79                  continue
     80              device = device.primaryAq()
     81              if checkStatus and (device.getPingStatus() > 0
     82                                  or device.getSnmpStatus() > 0):
     83                  log.info("device %s is down skipping modeling", device.id)
     84                  continue
     85
     86              if (device.productionState <
     87                  device.getProperty('zProdStateThreshold', 0)):
     88                  log.info("device %s is below zProdStateThreshold", device.id)
     89                  continue
     90              result.append(self.createDeviceProxy(device))
     91          return result
     92
     93      @translateError
     94 -    def remote_getDeviceListByMonitor(self, monitor=None):
     95          if monitor is None:
     96              monitor = self.instance
     97          monitor = self.dmd.Monitors.Performance._getOb(monitor)
     98          return [d.id for d in monitor.devices.objectValuesGen()]
     99
    100      @translateError
    101 -    def remote_getDeviceListByOrganizer(self, organizer, monitor=None):
    102          if monitor is None:
    103              monitor = self.instance
    104          root = self.dmd.Devices.getOrganizer(organizer)
    105          return [d.id for d in root.getSubDevicesGen() \
    106              if d.getPerformanceServerName() == monitor]
    107
    108      @translateError
    109 -    def remote_applyDataMaps(self, device, maps, devclass=None):
    110          from Products.DataCollector.ApplyDataMap import ApplyDataMap
    111          device = self.getPerformanceMonitor().findDevice(device)
    112          adm = ApplyDataMap(self)
    113          adm.setDeviceClass(device, devclass)
    114          def inner(map):
    115              if adm._applyDataMap(device, map):
    116                  changed = True
    117              else:
    118                  changed = False
    119              return changed
    120          changed = False
    121          for map in maps:
    122              result = inner(map)
    123              changed = changed or result
    124          return changed
    125
    126      @translateError
    127 -    def remote_setSnmpLastCollection(self, device):
    128          device = self.getPerformanceMonitor().findDevice(device)
    129          device.setSnmpLastCollection()
    130          from transaction import commit
    131          commit()
    132
    133      @transact
    134      @translateError
    135 -    def remote_setSnmpConnectionInfo(self, device, version, port, community):
    136          device = self.getPerformanceMonitor().findDevice(device)
    137          device.updateDevice(zSnmpVer=version,
    138                              zSnmpPort=port,
    139                              zSnmpCommunity=community)
    140
    141 -    def pushConfig(self, device):
    142          from twisted.internet.defer import succeed
    143          return succeed(device)
    144