def run(self): filters = self.build_request_args() probes_request = ProbeRequest(return_objects=True, **filters) probes = list(probes_request) if self.arguments.limit: probes = probes[:self.arguments.limit] if self.arguments.ids_only: ids = self.produce_ids_only(probes) sys.stdout.write(ids) return render_args = self._clean_render_args() renderer = Renderer(**render_args) renderer.blob += ( "We found the following probes with the given criteria:\n") if self.arguments.aggregate_by: aggregators = self.get_aggregators() buckets = aggregate(probes, aggregators) renderer.render_aggregation(buckets) else: renderer.on_table_title() for index, probe in enumerate(probes): renderer.on_result(probe) renderer.blob += ( "Total probes found: {}\n".format(probes_request.total_count)) sys.stdout.write(renderer.blob)
def run(self): if not self.arguments.field: self.arguments.field = ( "id", "asn_v4", "asn_v6", "country", "status") if self.arguments.all: self.arguments.limit = None filters = self.build_request_args() if not filters and not self.arguments.all: raise RipeAtlasToolsException(colourise( "Typically you'd want to run this with some arguments to " "filter the probe \nlist, as fetching all of the probes can " "take a Very Long Time. However, if you \ndon't care about " "the wait, you can use --all and go get yourself a coffee.", "blue" )) self.set_aggregators() probes = ProbeRequest( return_objects=True, user_agent=self.user_agent, **filters) if self.arguments.limit: truncated_probes = itertools.islice(probes, self.arguments.limit) else: truncated_probes = probes if self.arguments.ids_only: for probe in truncated_probes: print(probe.id) return hr = self._get_horizontal_rule() print(self._get_filter_display(filters)) print(colourise(self._get_header(), "bold")) print(colourise(hr, "bold")) if self.arguments.aggregate_by: buckets = aggregate(list(truncated_probes), self.aggregators) self.render_aggregation(buckets) else: for probe in truncated_probes: print(self._get_line(probe)) print(colourise(hr, "bold")) # Print total count of found measurements print(("{:>" + str(len(hr)) + "}\n").format( "Showing {} of {} total probes".format( min(self.arguments.limit, probes.total_count) or "all", probes.total_count ) ))