Trees | Indices | Help |
|
---|
|
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__ = """PingConfig 15 16 Provides configuration to zenping per-device based on: 17 * the zPingMonitorIgnore 18 * whether the datasource is enabled or not for the interface 19 """ 20 21 import logging 22 log = logging.getLogger('zen.HubService.PingPerformanceConfig') 23 24 from ipaddr import IPAddress 25 from twisted.spread import pb 26 27 import Globals 28 from Products.ZenCollector.services.config import CollectorConfigService 29 from Products.ZenEvents.ZenEventClasses import Error, Clear 30 from Products.ZenUtils.IpUtil import ipunwrap, ipstrip 31 3234 """ 35 Represents a pingable IP address on an IP interface. A single 36 DeviceProxy config will have multiple IP address proxy components 37 (for each IP address on each IP interface zenping should monitor) 38 """68 69 pb.setUnjellyableForClass(IpAddressProxy, IpAddressProxy) 70 7139 - def __init__(self, ip, ipVersion=4, iface='', basepath='', ds=None, 40 perfServer='localhost'):41 self.ip = ipunwrap(ip) 42 self.ipVersion = ipVersion 43 self.iface = iface 44 self.cycleTime = getattr(ds, 'cycleTime', 60) 45 self.tries = getattr(ds, 'attempts', 2) 46 self.sampleSize = getattr(ds, 'sampleSize', 1) 47 self.points = [] 48 49 if not ds: 50 # Don't need the datapoints to get the IP monitored 51 return 52 53 log.debug("Using the %s template settings for IP %s", 54 ds.rrdTemplate().getPrimaryUrlPath(), self.ip) 55 for dp in ds.getRRDDataPoints(): 56 ipdData = (dp.id, 57 "/".join((basepath, dp.name())), 58 dp.rrdtype, 59 dp.getRRDCreateCommand(perfServer).strip(), 60 dp.rrdmin, dp.rrdmax) 61 62 self.points.append(ipdData)6365 return "IPv%d %s iface: '%s' cycleTime: %ss attempts: %d" % ( 66 self.ipVersion, self.ip, self.iface, self.cycleTime, 67 self.tries)184 185 186 if __name__ == '__main__': 187 from Products.ZenHub.ServiceTester import ServiceTester 188 tester = ServiceTester(PingPerformanceConfig) 192 tester.printDeviceProxy = printer 193 tester.showDeviceInfo() 19474 deviceProxyAttributes = ( 75 'zPingMonitorIgnore', 76 ) 77 CollectorConfigService.__init__(self, dmd, instance, 78 deviceProxyAttributes)7981 include = CollectorConfigService._filterDevice(self, device) 82 83 if not device.monitorDevice(): 84 include = False 85 86 if device.zPingMonitorIgnore: 87 include = False 88 89 if not device.getManageIp(): 90 self.log.debug("Device %s skipped because its management IP address is blank.", 91 device.id) 92 include = False 93 94 return include9597 """ 98 All IP addresses on all IP interfaces can be pingable. 99 """ 100 basepath = iface.rrdPath() 101 title = iface.titleOrId() 102 for templ in iface.getRRDTemplates(): 103 for ipAddress in iface.ipaddresses(): 104 ip = ipAddress.id 105 if not ip or ip in ('127.0.0.1', '0.0.0.0', '::', '::1'): 106 log.debug("The %s interface IP is '%s' -- ignoring", 107 title, ip) 108 continue 109 110 dsList = [ds for ds in templ.getRRDDataSources('PING') \ 111 if ds.enabled] 112 if dsList: 113 ipVersion = getattr(ipAddress, 'version', 4) 114 ipProxy = IpAddressProxy(ip, ipVersion=ipVersion, 115 iface=title, ds=dsList[0], 116 basepath=basepath, perfServer=perfServer) 117 monitoredIps.append(ipProxy)118120 """ 121 Add the management IP and any associated datapoints to the IPs to monitor. 122 """ 123 basepath = device.rrdPath() 124 title = '' 125 ip = device.manageIp 126 if not ip or ip in ('127.0.0.1', '0.0.0.0', '::', '::1'): 127 return 128 ipObj = IPAddress(ipstrip(ip)) 129 130 # Look for device-level templates with PING datasources 131 addedIp = False 132 for templ in device.getRRDTemplates(): 133 dsList = [ds for ds in templ.getRRDDataSources('PING') \ 134 if ds.enabled] 135 if dsList: 136 ipProxy = IpAddressProxy(ip, ipVersion=ipObj.version, 137 iface=title, ds=dsList[0], 138 basepath=basepath, perfServer=perfServer) 139 proxy.monitoredIps.append(ipProxy) 140 addedIp = True 141 142 threshs = device.getThresholdInstances('PING') 143 if threshs: 144 proxy.thresholds.extend(threshs) 145 146 # Add without datapoints if nothing's defined.... 147 if not addedIp: 148 ipProxy = IpAddressProxy(ip, ipVersion=ipObj.version, 149 iface=title, 150 basepath=basepath, perfServer=perfServer) 151 proxy.monitoredIps.append(ipProxy)152154 proxy = CollectorConfigService._createDeviceProxy(self, device) 155 156 proxy.name = device.id 157 proxy.device = device.id 158 proxy.lastmodeltime = device.getLastChangeString() 159 proxy.lastChangeTime = float(device.getLastChange()) 160 161 perfServer = device.getPerformanceServer() 162 proxy.thresholds = [] 163 proxy.monitoredIps = [] 164 for iface in device.os.interfaces(): 165 self._getComponentConfig(iface, perfServer, proxy.monitoredIps) 166 threshs = iface.getThresholdInstances('PING') 167 if threshs: 168 proxy.thresholds.extend(threshs) 169 170 if not proxy.monitoredIps: 171 log.debug("%s has no interface templates -- just using management IP %s", 172 device.titleOrId(), device.manageIp) 173 self._addManageIp(device, perfServer, proxy) 174 175 elif device.manageIp not in [x.ip for x in proxy.monitoredIps]: 176 # Note: most commonly occurs for SNMP fakeout devices which replay 177 # data from real devices, but from a different IP address 178 # than what captured the data 179 log.debug("%s doesn't have an interface for management IP %s", 180 device.titleOrId(), device.manageIp) 181 self._addManageIp(device, perfServer, proxy) 182 183 return proxy
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1.1812 on Tue Oct 11 12:52:01 2011 | http://epydoc.sourceforge.net |