def setupCollector(global_options, collector_client): from ooni.backend_client import CollectorClient if global_options['collector']: collector_client = CollectorClient(global_options['collector']) elif config.reports.get('collector', None) is not None: collector_client = CollectorClient(config.reports['collector']) if not collector_client.isSupported(): raise errors.CollectorUnsupported return collector_client
def get_reachable_collector(collector_address, collector_alternate, preferred_backend): for collector_settings in sort_addresses_by_priority( collector_address, collector_alternate, preferred_backend): collector = CollectorClient(settings=collector_settings) if not collector.isSupported(): log.err( "Unsupported %s collector %s" % (collector_settings['type'], collector_settings['address'])) continue reachable = yield collector.isReachable() if not reachable: log.err( "Unreachable %s collector %s" % (collector_settings['type'], collector_settings['address'])) continue defer.returnValue(collector) raise e.NoReachableCollectors