Trees | Indices | Help |
|
---|
|
1 ############################################################################## 2 # 3 # Copyright (C) Zenoss, Inc. 2008, 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 Globals 12 13 from Acquisition import aq_base 14 from twisted.internet import defer, reactor 15 from ZODB.transact import transact 16 from PerformanceConfig import PerformanceConfig 17 from Products.ZenHub.PBDaemon import translateError 18 from Products.DataCollector.DeviceProxy import DeviceProxy 19 from Products.DataCollector.Plugins import loadPlugins 20 21 import logging 22 log = logging.getLogger('zen.ModelerService')25 26 plugins = None 27123 124 changed = False 125 for map in maps: 126 result = inner(map) 127 changed = changed or result 128 129 if setLastCollection: 130 self._setSnmpLastCollection(device) 131 132 return changed 13329 PerformanceConfig.__init__(self, dmd, instance) 30 self.config = self.dmd.Monitors.Performance._getOb(self.instance) 31 self.methodPriorityMap = { 32 'applyDataMaps': 0.5, 33 }3436 if self.plugins is None: 37 self.plugins = {} 38 for loader in loadPlugins(self.dmd): 39 try: 40 plugin = loader.create() 41 plugin.loader = loader 42 self.plugins[plugin.name()] = plugin 43 except Exception, ex: 44 log.exception(ex) 45 46 result = DeviceProxy() 47 result.id = dev.getId() 48 result.skipModelMsg = skipModelMsg 49 50 if not skipModelMsg: 51 if not dev.manageIp: 52 dev.setManageIp() 53 result.manageIp = dev.manageIp 54 result.plugins = [] 55 for name in dev.zCollectorPlugins: 56 plugin = self.plugins.get(name, None) 57 log.debug('checking plugin %s for device %s' % (name, dev.getId())) 58 if plugin and plugin.condition(dev, log): 59 log.debug('adding plugin %s for device %s' % (name,dev.getId())) 60 result.plugins.append(plugin.loader) 61 plugin.copyDataToProxy(dev, result) 62 result.temp_device = dev.isTempDevice() 63 return result64 65 @translateError67 result = [] 68 for dc in self.dmd.Devices.getSubOrganizers(): 69 localPlugins = getattr(aq_base(dc), 'zCollectorPlugins', False) 70 if not localPlugins: continue 71 result.append((dc.getOrganizerName(), localPlugins)) 72 return result73 74 @translateError76 result = [] 77 for name in names: 78 device = self.getPerformanceMonitor().findDevice(name) 79 if not device: 80 continue 81 device = device.primaryAq() 82 skipModelMsg = '' 83 84 if device.isLockedFromUpdates(): 85 skipModelMsg = "device %s is locked, skipping modeling" % device.id 86 if checkStatus and (device.getPingStatus() > 0 87 or device.getSnmpStatus() > 0): 88 skipModelMsg = "device %s is down skipping modeling" % device.id 89 if (device.productionState < 90 device.getProperty('zProdStateThreshold', 0)): 91 skipModelMsg = "device %s is below zProdStateThreshold" % device.id 92 if skipModelMsg: 93 log.info(skipModelMsg) 94 95 result.append(self.createDeviceProxy(device, skipModelMsg)) 96 return result97 98 @translateError100 if monitor is None: 101 monitor = self.instance 102 monitor = self.dmd.Monitors.Performance._getOb(monitor) 103 return [d.id for d in monitor.devices.objectValuesGen()]104 105 @translateError107 if monitor is None: 108 monitor = self.instance 109 root = self.dmd.Devices.getOrganizer(organizer) 110 return [d.id for d in root.getSubDevicesGen() 111 if d.getPerformanceServerName() == monitor]112 113 @translateError115 from Products.DataCollector.ApplyDataMap import ApplyDataMap 116 device = self.getPerformanceMonitor().findDevice(device) 117 adm = ApplyDataMap(self) 118 adm.setDeviceClass(device, devclass) 119 def inner(map): 120 def action(): 121 return bool(adm._applyDataMap(device, map))122 return self._do_with_retries(action)135 transactional = transact(device.setSnmpLastCollection) 136 return self._do_with_retries(transactional)137 138 @translateError140 device = self.getPerformanceMonitor().findDevice(device) 141 self._setSnmpLastCollection(device)142144 from ZODB.POSException import StorageError 145 max_attempts = 3 146 for attempt_num in range(max_attempts): 147 try: 148 return action() 149 except StorageError as e: 150 if attempt_num == max_attempts-1: 151 msg = "{0}, maximum retries reached".format(e) 152 else: 153 msg = "{0}, retrying".format(e) 154 log.info(msg)155 156 157 @transact 158 @translateError160 device = self.getPerformanceMonitor().findDevice(device) 161 device.updateDevice(zSnmpVer=version, 162 zSnmpPort=port, 163 zSnmpCommunity=community)164 168 169 170 if __name__ == '__main__': 171 from Products.ZenHub.ServiceTester import ServiceTester 172 tester = ServiceTester(ModelerService)175 print "%s (%s) Plugins" % (config.id, config.manageIp) 176 print sorted(x.pluginName for x in config.plugins)177179 if tester.options.device: 180 name = tester.options.device 181 config = tester.service.remote_getDeviceConfig([name]) 182 if config: 183 print "Config for %s =" % name 184 configprinter(config[0]) 185 else: 186 log.warn("No configs found for %s", name) 187 else: 188 collector = tester.options.monitor 189 devices = tester.service.remote_getDeviceListByMonitor(collector) 190 devices = sorted(devices) 191 print "Device list = %s" % devices192 193 showDeviceInfo() 194
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1.1812 on Mon Jul 30 17:11:16 2012 | http://epydoc.sourceforge.net |