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

Source Code for Module Products.ZenHub.services.ZenStatusConfig

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