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

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

      1  ###########################################################################
      2  #
      3  # This program is part of Zenoss Core, an open source monitoring platform.
      4  # Copyright (C) 2010, 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  import logging
     14
     15  import Globals
     16
     17  from twisted.spread import pb
     18
     19  from Products.ZenCollector.services.config import CollectorConfigService
     20  from Products.ZenEvents.ZenEventClasses import Status_IpService
     21  from Products.ZenModel.ServiceOrganizer import ServiceOrganizer
     22  from Products.ZenModel.Service import Service
     23
     24  log = logging.getLogger('zen.ZenStatusConfig')
     25
     26
     27 -class ServiceProxy(pb.Copyable, pb.RemoteCopy):
     28      """
     29      Represents a service component. A single DeviceProxy config will have
     30      multiple service proxy components (for each service zenstatus should
     31      monitor)
     32      """
     33 -    def __init__(self, svc, status):
     34          self.device = svc.hostname()
     35          self.component = svc.name()
     36          self.ip = svc.getManageIp()
     37          self.port = svc.getPort()
     38          self.sendString = svc.getSendString()
     39          self.expectRegex = svc.getExpectRegex()
     40          self.timeout = svc.zStatusConnectTimeout
     41          self.failSeverity = svc.getFailSeverity()
     42          self.status = status
     43          self.key = svc.key()
     44          self.deviceManageIp = svc.device().manageIp
     45
     46 -    def __str__(self):
     47          return ' '.join( map(str, [self.device, self.component, self.port]) )
     48
     49  pb.setUnjellyableForClass(ServiceProxy, ServiceProxy)
     50
     51
     52 -class ZenStatusConfig(CollectorConfigService):
     53
     54 -    def __init__(self, dmd, instance):
     55          # Any additional attributes we want to send to daemon should be
     56          # added here
     57          deviceProxyAttributes = ()
     58          CollectorConfigService.__init__(self, dmd,
     59                                          instance,
     60                                          deviceProxyAttributes)
     61
     62 -    def _filterDevice(self, device):
     63          include = CollectorConfigService._filterDevice(self, device)
     64          hasTcpComponents = False
     65          for svc in device.getMonitoredComponents(collector='zenstatus'):
     66              if svc.getProtocol() == "tcp":
     67                  hasTcpComponents = True
     68
     69          return include and hasTcpComponents
     70
     71 -    def _createDeviceProxy(self, device):
     72          proxy = CollectorConfigService._createDeviceProxy(self, device)
     73          proxy.configCycleInterval = self._prefs.statusCycleInterval
     74
     75          # add each component
     76          proxy.components = []
     77          for svc in device.getMonitoredComponents(collector='zenstatus'):
     78              if svc.getProtocol() == 'tcp':
     79                  # get component status
     80                  status = svc.getStatus(Status_IpService)
     81                  proxy.components.append(ServiceProxy(svc, status))
     82
     83          # don't bother adding this device proxy if there aren't any services
     84          # to monitor
     85          if not proxy.components:
     86              log.debug("Device %s skipped because there are no components",
     87                        proxy.id)
     88              return None
     89
     90          return proxy
     91
     92 -    def _getNotifiableClasses(self):
     93          """
     94          When zProperties are changed on either of these two classes we
     95          need to refresh which devices we are monitoring
     96          """
     97          return (Service, ServiceOrganizer)
     98
     99  if __name__ == '__main__':
    100      from Products.ZenHub.ServiceTester import ServiceTester
    101      tester = ServiceTester(ZenStatusConfig)
    102 -    def printer(proxy):
    103          print '\t'.join( ['', 'Hostname', 'Service name', 'Port'] )
    104          for component in proxy.components:
    105              print '\t', component
    106      tester.printDeviceProxy = printer
    107      tester.showDeviceInfo()
    108