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

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

      1  ###########################################################################
      2  #
      3  # This program is part of Zenoss Core, an open source monitoring platform.
      4  # Copyright (C) 2007, 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 PerformanceConfig import PerformanceConfig
     15  from ZODB.POSException import POSError
     16  from Products.ZenRRD.zencommand import Cmd, DeviceConfig, DataPointConfig
     17  from Products.ZenHub.PBDaemon import translateError
     18  from Products.DataCollector.Plugins import getParserLoader
     19  import logging
     20  log = logging.getLogger('zen.CommandConfig')
     21
     22 -def getComponentCommands(comp, commandCache, commandSet, dmd):
     23      """Return list of command definitions.
     24      """
     25      perfServer = comp.device().getPerformanceServer()
     26      for templ in comp.getRRDTemplates():
     27          basepath = comp.rrdPath()
     28          for ds in templ.getRRDDataSources('COMMAND'):
     29              if not ds.enabled: continue
     30              parserName = getattr(ds, "parser", "Auto")
     31              ploader = getParserLoader(dmd, parserName)
     32              if ploader is None:
     33                  log.error("Could not load %s plugin", parserName)
     34                  continue
     35              component_name = ds.getComponent(comp)
     36              parser = ploader.create()
     37              points = []
     38              for dp in ds.getRRDDataPoints():
     39                  dpc = DataPointConfig()
     40                  dpc.id = dp.id
     41                  dpc.component = component_name
     42                  dpc.rrdPath = "/".join((basepath, dp.name()))
     43                  dpc.rrdType = dp.rrdtype
     44                  dpc.rrdCreateCommand = dp.getRRDCreateCommand(perfServer)
     45                  dpc.rrdMin = dp.rrdmin
     46                  dpc.rrdMax = dp.rrdmax
     47                  dpc.data = parser.dataForParser(comp, dp)
     48                  points.append(dpc)
     49              cmd = Cmd()
     50              cmd.useSsh = getattr(ds, 'usessh', False)
     51              cmd.cycleTime = ds.cycletime
     52              cmd.component = component_name
     53              cmd.eventClass = ds.eventClass
     54              cmd.eventKey = ds.eventKey or ds.id
     55              cmd.severity = ds.severity
     56              cmd.parser = ploader
     57              cmd.command = ds.getCommand(comp)
     58              cmd = commandCache.setdefault(cmd.commandKey(), cmd)
     59              cmd.points.extend(points)
     60              commandSet.add(cmd)
     61      return comp.getThresholdInstances('COMMAND')
     62
     63
     64 -def getDeviceCommands(dev):
     65      if not dev.monitorDevice():
     66          return None
     67      cache = {}
     68      cmds = set()
     69      threshs = getComponentCommands(dev, cache, cmds, dev.getDmd())
     70      for o in dev.getMonitoredComponents(collector="zencommand"):
     71          threshs.extend(getComponentCommands(o, cache, cmds, dev.getDmd()))
     72      if cmds:
     73          d = DeviceConfig()
     74          d.lastChange = dev.getLastChange()
     75          d.device = dev.id
     76          d.ipAddress = dev.getManageIp()
     77          d.port = dev.getProperty('zCommandPort')
     78          d.username = dev.getProperty('zCommandUsername')
     79          d.password = dev.getProperty('zCommandPassword')
     80          d.loginTimeout = dev.getProperty('zCommandLoginTimeout')
     81          d.commandTimeout = dev.getProperty('zCommandCommandTimeout')
     82          d.keyPath = dev.getProperty('zKeyPath')
     83          d.maxOids = dev.getProperty('zMaxOIDPerRequest')
     84          d.concurrentSessions = dev.getProperty('zSshConcurrentSessions')
     85          d.commands = list(cmds)
     86          d.thresholds = threshs
     87          return d
     88      return None
     89
     90
     91 -class CommandConfig(PerformanceConfig):
     92
     93      @translateError
     94 -    def remote_getDataSourceCommands(self, devices = None):
     95          return self.getDataSourceCommands(devices)
     96
     97
     98 -    def getDeviceConfig(self, device):
     99          return getDeviceCommands(device)
    100
    101
    102 -    def sendDeviceConfig(self, listener, config):
    103          return listener.callRemote('updateConfig', config)
    104
    105
    106 -    def getDataSourceCommands(self, devices = None):
    107          '''Get the command configuration for all devices.
    108          '''
    109          result = []
    110          for dev in self.config.devices():
    111              if devices and dev.id not in devices: continue
    112              dev = dev.primaryAq()
    113              try:
    114                  cmdinfo = getDeviceCommands(dev)
    115                  if not cmdinfo: continue
    116                  result.append(cmdinfo)
    117              except POSError: raise
    118              except:
    119                  self.log.exception("device %s", dev.id)
    120          return result
    121
    122 -    def update(self, object):
    123          from Products.ZenModel.RRDDataSource import RRDDataSource
    124          if isinstance(object, RRDDataSource):
    125              if object.sourcetype != 'COMMAND':
    126                  return
    127
    128          PerformanceConfig.update(self, object)
    129