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

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

      1  ###########################################################################
      2  #
      3  # This program is part of Zenoss Core, an open source monitoring platform.
      4  # Copyright (C) 2009, 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  import re
     15  import sre_constants
     16  import logging
     17  log = logging.getLogger('zen.HubService.ProcessConfig')
     18
     19  import Globals
     20
     21  from Products.ZenCollector.services.config import CollectorConfigService
     22  from Products.ZenUtils.Utils import unused
     23  from Products.ZenCollector.services.config import DeviceProxy
     24  from Products.ZenEvents import Event
     25  from Products.ZenModel.OSProcessClass import OSProcessClass
     26  from Products.ZenModel.OSProcessOrganizer import OSProcessOrganizer
     27  from Products.ZenHub.zodb import onUpdate
     28  unused(DeviceProxy)
     29
     30  from twisted.spread import pb
     31
     32 -class ProcessProxy(pb.Copyable, pb.RemoteCopy):
     33      """
     34      Track process-specific configuration data
     35      """
     36      name = None
     37      originalName = None
     38      ignoreParameters = False
     39      restart = None
     40      regex = None
     41      severity = Event.Warning
     42      cycleTime = None
     43      processClass = None
     44
     45 -    def __init__(self):
     46          pass
     47
     48 -    def __str__(self):
     49          """
     50          Override the Python default to represent ourselves as a string
     51          """
     52          return str(self.name)
     53      __repr__ = __str__
     54
     55
     56  pb.setUnjellyableForClass(ProcessProxy, ProcessProxy)
     57
     58
     59 -class ProcessConfig(CollectorConfigService):
     60
     61 -    def __init__(self, dmd, instance):
     62          deviceProxyAttributes = ('zMaxOIDPerRequest',)
     63          CollectorConfigService.__init__(self, dmd, instance, deviceProxyAttributes)
     64
     65 -    def _filterDevice(self, device):
     66          include = CollectorConfigService._filterDevice(self, device)
     67          include = include and device.snmpMonitorDevice()
     68
     69          return include
     70
     71 -    def _createDeviceProxy(self, device):
     72          procs = device.getMonitoredComponents(collector='zenprocess')
     73          if not procs:
     74              log.debug("Device %s has no monitored processes -- ignoring",
     75                        device.titleOrId())
     76              return None
     77
     78          proxy = CollectorConfigService._createDeviceProxy(self, device)
     79          proxy.configCycleInterval = self._prefs.processCycleInterval
     80
     81          proxy.name = device.id
     82          proxy.lastmodeltime = device.getLastChangeString()
     83          proxy.thresholds = []
     84          proxy.processes = {}
     85          proxy.snmpConnInfo = device.getSnmpConnInfo()
     86          for p in procs:
     87              regex = getattr(p.osProcessClass(), 'regex', False)
     88              if regex:
     89                  try:
     90                      re.compile(regex)
     91                  except sre_constants.error, ex:
     92                      log.warn("OS process class %s has an invalid regex (%s): %s",
     93                               p.getOSProcessClass(), regex, ex)
     94                      continue
     95              proc = ProcessProxy()
     96              proc.regex = regex
     97              proc.name = p.id
     98              proc.originalName = p.name()
     99              proc.ignoreParameters = (
    100                  getattr(p.osProcessClass(), 'ignoreParameters', False))
    101              proc.restart = p.alertOnRestart()
    102              proc.severity = p.getFailSeverity()
    103              proc.processClass = p.getOSProcessClass()
    104              proxy.processes[p.id] = proc
    105              proxy.thresholds.extend(p.getThresholdInstances('SNMP'))
    106
    107          if proxy.processes:
    108              return proxy
    109
    110      @onUpdate(OSProcessClass, OSProcessOrganizer)
    111 -    def processTreeUpdated(self, object, event):
    112          self._reconfigureIfNotify(object)
    113
    114
    115  if __name__ == '__main__':
    116      from Products.ZenHub.ServiceTester import ServiceTester
    117      tester = ServiceTester(ProcessConfig)
    118 -    def printer(config):
    119          for proc in config.processes.values():
    120              print '\t'.join([proc.name, str(proc.ignoreParameters), proc.regex])
    121      tester.printDeviceProxy = printer
    122      tester.showDeviceInfo()
    123