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

Source Code for Module Products.ZenHub.services.SnmpPerformanceConfig

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, 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   
 14  __doc__ = '''SnmpPerformanceConfig 
 15   
 16  Provides configuration to zenperfsnmp clients. 
 17  ''' 
 18   
 19  from pprint import pformat 
 20  import logging 
 21  log = logging.getLogger('zen.HubService.SnmpPerformanceConfig') 
 22   
 23  import Globals 
 24  from twisted.spread import pb 
 25  from Products.ZenCollector.services.config import DeviceProxy, CollectorConfigService 
 26   
27 -def get_component_manage_ip(component, default=None):
28 get_manage_ip = getattr(component, "getManageIp", None) 29 if get_manage_ip is None: 30 return default 31 return get_manage_ip()
32
33 -class SnmpDeviceProxy(DeviceProxy, pb.Copyable, pb.RemoteCopy):
34
35 - def __repr__(self):
36 sci = getattr(self, "snmpConnInfo", None) 37 scimi = None if (sci is None) else sci.manageIp 38 return pformat({"id": self.id, 39 "_config_id": getattr(self, "_config_id", None), 40 "manageIp": self.manageIp, 41 "snmpConnInfo.manageIp": scimi, 42 "oids": getattr(self, "oids", None)})
43 44 pb.setUnjellyableForClass(SnmpDeviceProxy, SnmpDeviceProxy) 45 46
47 -class SnmpPerformanceConfig(CollectorConfigService):
48 - def __init__(self, dmd, instance):
49 deviceProxyAttributes = ('zMaxOIDPerRequest', 50 'zSnmpMonitorIgnore', 51 'zSnmpAuthPassword', 52 'zSnmpAuthType', 53 'zSnmpCommunity', 54 'zSnmpPort', 55 'zSnmpPrivPassword', 56 'zSnmpPrivType', 57 'zSnmpSecurityName', 58 'zSnmpTimeout', 59 'zSnmpTries', 60 'zSnmpVer', 61 'zSnmpCollectionInterval', 62 ) 63 CollectorConfigService.__init__(self, dmd, instance, 64 deviceProxyAttributes)
65
66 - def _filterDevice(self, device):
67 include = CollectorConfigService._filterDevice(self, device) 68 69 if getattr(device, 'zSnmpMonitorIgnore', False): 70 self.log.debug("Device %s skipped because zSnmpMonitorIgnore is True", 71 device.id) 72 include = False 73 74 if not device.getManageIp(): 75 self.log.debug("Device %s skipped because its management IP address is blank.", 76 device.id) 77 include = False 78 79 return include
80
81 - def _getComponentConfig(self, comp, perfServer, oids):
82 """ 83 SNMP components can build up the actual OID based on a base OID and 84 the snmpindex of the component. 85 """ 86 if comp.snmpIgnore(): 87 return None 88 89 basepath = comp.rrdPath() 90 for templ in comp.getRRDTemplates(): 91 for ds in templ.getRRDDataSources("SNMP"): 92 if not ds.enabled or not ds.oid: 93 continue 94 95 oid = ds.oid 96 snmpindex = getattr(comp, "ifindex", comp.snmpindex) 97 if snmpindex: 98 oid = "%s.%s" % (oid, snmpindex) 99 oid = oid.strip('.') 100 101 if not oid: 102 log.warn("The data source %s OID is blank -- ignoring", 103 ds.id) 104 continue 105 106 for dp in ds.getRRDDataPoints(): 107 # Everything under ZenModel *should* use titleOrId but it doesn't 108 cname = comp.viewName() if comp.meta_type != "Device" else dp.id 109 oidData = (cname, 110 "/".join((basepath, dp.name())), 111 dp.rrdtype, 112 dp.getRRDCreateCommand(perfServer).strip(), 113 dp.rrdmin, dp.rrdmax) 114 115 # An OID can appear in multiple data sources/data points 116 oids.setdefault(oid, []).append(oidData) 117 118 return comp.getThresholdInstances('SNMP')
119
120 - def _createDeviceProxies(self, device):
121 manage_ips = {device.manageIp: ([], False)} 122 components = device.os.getMonitoredComponents(collector="zenperfsnmp") 123 for component in components: 124 manage_ip = get_component_manage_ip(component, device.manageIp) 125 if manage_ip not in manage_ips: 126 log.debug("Adding manage IP %s from %r" % (manage_ip, component)) 127 manage_ips[manage_ip] = ([], True) 128 manage_ips[manage_ip][0].append(component) 129 proxies = [] 130 for manage_ip, (components, components_only) in manage_ips.items(): 131 proxy = self._createDeviceProxy(device, manage_ip, components, components_only) 132 if proxy is not None: 133 proxies.append(proxy) 134 return proxies
135
136 - def _createDeviceProxy(self, device, manage_ip=None, components=(), components_only=False):
137 proxy = SnmpDeviceProxy() 138 proxy = CollectorConfigService._createDeviceProxy(self, device, proxy) 139 proxy.snmpConnInfo = device.getSnmpConnInfo() 140 if manage_ip is not None and manage_ip != device.manageIp: 141 proxy._config_id = device.id + "_" + manage_ip 142 proxy.snmpConnInfo.manageIp = manage_ip 143 proxy.configCycleInterval = self._prefs.perfsnmpCycleInterval 144 proxy.cycleInterval = getattr(device, 'zSnmpCollectionInterval', 300) 145 proxy.name = device.id 146 proxy.device = device.id 147 proxy.lastmodeltime = device.getLastChangeString() 148 proxy.lastChangeTime = float(device.getLastChange()) 149 150 # Gather the datapoints to retrieve 151 perfServer = device.getPerformanceServer() 152 proxy.oids = {} 153 proxy.thresholds = [] 154 if not components_only: 155 # First for the device.... 156 threshs = self._getComponentConfig(device, perfServer, proxy.oids) 157 if threshs: 158 proxy.thresholds.extend(threshs) 159 # And now for its components 160 for comp in components: 161 threshs = self._getComponentConfig(comp, perfServer, proxy.oids) 162 if threshs: 163 proxy.thresholds.extend(threshs) 164 165 if proxy.oids: 166 return proxy
167 168 169 if __name__ == '__main__': 170 from Products.ZenHub.ServiceTester import ServiceTester 171 tester = ServiceTester(SnmpPerformanceConfig)
172 - def printer(proxy):
173 for oid in sorted(proxy.oids): 174 print oid
175 tester.printDeviceProxy = printer 176 tester.showDeviceInfo() 177