def discoverDevices(self, ips, devicepath="/Discovered", prodState=1000): """ Discover devices by active ips that are not associated with a device. @param ips: list of IP addresses @type ips: list of strings @param devicepath: where in the DMD to put any discovered devices @type devicepath: string @param prodState: production state (see Admin Guide for a description) @type prodState: integer @return: Twisted/Zenoss Python iterable @rtype: Python iterable """ def discoverDevice(ip): """ Discover a particular device NB: Wrapper around self.discoverDevice() @param ip: IP address @type ip: string @return: Twisted/Zenoss Python iterable @rtype: Python iterable """ return self.discoverDevice(ip, devicepath, prodState) return NJobs(self.options.parallel, discoverDevice, ips).start()
def discoverRanges(self, driver): """ Ping all IPs in the range and create devices for the ones that come back. @param ranges: list of ranges to discover @type ranges: list """ if isinstance(self.options.range, basestring): self.options.range = [self.options.range] # in case someone uses 10.0.0.0-5,192.168.0.1-5 instead of # --range 10.0.0.0-5 --range 192.168.0.1-5 if (isinstance(self.options.range, list) and self.options.range[0].find(",") > -1): self.options.range = [ n.strip() for n in self.options.range[0].split(',') ] ips = [] goodCount = 0 for iprange in self.options.range: # Parse to find ips included ips.extend(parse_iprange(iprange)) yield NJobs(self.options.chunkSize, self.ping, ips).start() results = driver.next() goodips = [v.ipaddr for v in results if not isinstance(v, Failure)] badips = [v.value.ipaddr for v in results if isinstance(v, Failure)] goodCount += len(goodips) self.log.debug("Got %d good IPs and %d bad IPs", len(goodips), len(badips)) yield self.discoverDevices(goodips) yield succeed("Discovered %d active IPs" % goodCount) driver.next()
def _collectCallback(self): jobs = NJobs(self._preferences.options.parallel, self._collectJMX, self._taskConfig.jmxDataSourceConfigs.values()) deferred = jobs.start() return deferred
def doPeriodic(driver): """ Generator function to create deferred jobs. """ yield self.getDevicePingIssues() self.downDevices = Set([d[0] for d in driver.next()]) self.scanning = NJobs(self.parallelJobs, self.oneDevice, self.devices().values()) yield self.scanning.start() driver.next()
def inner(driver): """ Twisted driver class to iterate through devices @param driver: Zenoss driver @type driver: Zenoss driver @return: successful result is a list of IPs that were added @rtype: Twisted deferred """ ips = [] goodCount = 0 # it would be nice to interleave ping/discover for net in nets: if self.options.subnets and len(net.children()) > 0: continue if not getattr(net, "zAutoDiscover", False): self.log.info( "Skipping network %s because zAutoDiscover is False" % net.getNetworkName()) continue self.log.info("Discover network '%s'", net.getNetworkName()) yield NJobs(self.options.chunkSize, self.ping, net.fullIpList()).start() results = driver.next() goodips = [ v.ipaddr for v in results if not isinstance(v, Failure) ] badips = [ v.value.ipaddr for v in results if isinstance(v, Failure) ] goodCount += len(goodips) self.log.debug("Got %d good IPs and %d bad IPs", len(goodips), len(badips)) yield self.config().callRemote('pingStatus', net, goodips, badips, self.options.resetPtr, self.options.addInactive) ips += driver.next() self.log.info("Discovered %s active ips", goodCount) # make sure this is the return result for the driver yield succeed(ips) driver.next()
def doCollection(driver): self.log.debug("doCollection(): starting collection cycle") reactor.callLater(self.options.dataCollectInterval, self.runCollection) if not self.options.cycle: self.stop() if self.running: self.log.error("last appengine collection is still running") return self.running = True jobs = NJobs(200, self.collectAppEngine, self.datasourceMap.keys()) yield jobs.start() driver.next() self.log.debug("doCollection(): exiting collection cycle") self.sendEvents( self.rrdStats.gauge( 'instances', self.options.dataCollectInterval, len(self.datasourceMap)) + self.rrdStats.counter( 'dataPoints', self.options.dataCollectInterval, self.rrd.dataPoints) + self.rrdStats.gauge('cyclePoints', self.options. dataCollectInterval, self.rrd.endCycle()))
self.log.exception("Error performing net discovery on %s", ex) def discoverDevice(ip): """ Discover a particular device NB: Wrapper around self.discoverDevice() @param ip: IP address @type ip: string @return: Twisted/Zenoss Python iterable @rtype: Python iterable """ return self.discoverDevice(ip, self.options.deviceclass, self.options.productionState) yield NJobs(self.options.parallel, discoverDevice, devices).start() yield succeed("Discovered %d devices" % count) driver.next() def printResults(self, results): """ Display the results that we've obtained @param results: what we've discovered @type results: string """ if isinstance(results, Failure): if results.type is NoIPAddress: self.log.error("Error: %s", results.value) else: self.log.error("Error: %s", results)