/usr/lib/python2.7/dist-packages/ripe/atlas/tools/commands/measurement.py is in ripe-atlas-tools 1.2.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | # Copyright (c) 2015 RIPE NCC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function, absolute_import
from ripe.atlas.cousteau import Measurement
from ripe.atlas.cousteau.exceptions import APIResponseError
from .base import Command as BaseCommand, MetaDataMixin
from ..exceptions import RipeAtlasToolsException
from ..helpers.colours import colourise
from ..helpers.sanitisers import sanitise
class Command(MetaDataMixin, BaseCommand):
NAME = "measurement"
DESCRIPTION = (
"Returns the meta data for one measurement"
)
def add_arguments(self):
self.parser.add_argument("id", type=int, help="The measurement id")
def run(self):
try:
measurement = Measurement(
id=self.arguments.id, user_agent=self.user_agent)
except APIResponseError:
raise RipeAtlasToolsException(
"That measurement does not appear to exist")
self.render_basic(measurement)
getattr(self, "render_{}".format(measurement.type.lower()))(measurement)
@classmethod
def render_basic(cls, measurement):
url_template = "https://atlas.ripe.net/measurements/{}/"
cls._render(measurement, (
("id", "ID"),
("id", "URL", lambda _: colourise(url_template.format(_), "cyan")),
("type", "Type", lambda _: cls._prettify_type(_["name"])),
("status", "Status", lambda _: _["name"]),
("description", "Description", sanitise),
("af", "Address Family"),
("is_public", "Public?", cls._prettify_boolean),
("is_oneoff", "One-off?", cls._prettify_boolean),
("destination_name", "Destination Name", sanitise),
("destination_address", "Destination Address", sanitise),
("destination_asn", "Destination ASN"),
("interval", "Interval"),
("spread", "Spread"),
("creation_time", "Created", cls._prettify_time),
("start_time", "Started", cls._prettify_time),
("stop_time", "Stopped", cls._prettify_time),
("probes_requested", "Probes Requested"),
("probes_scheduled", "Probes Scheduled"),
("probes_currently_involved", "Probes Involved"),
("participant_count", "Participant Count"),
("is_all_scheduled", "Fully Scheduled?", cls._prettify_boolean),
("resolved_ips", "Resolved IPs", lambda _: ", ".join(_)),
("resolve_on_probe", "Resolve on the Probe", cls._prettify_boolean),
))
@classmethod
def render_ping(cls, measurement):
cls._render(measurement, (
("packets", "Packets"),
("size", "Size"),
))
@classmethod
def render_traceroute(cls, measurement):
cls._render(measurement, (
("packets", "Packets"),
("protocol", "Protocol"),
("dont_fragment", "Don't Fragment", cls._prettify_boolean),
("paris", "Paris"),
("first_hop", "First Hop"),
("max_hops", "Maximum Hops"),
("timeout", "Timeout"),
("size", "Size"),
("destination_option_size", "Destination Option Size"),
("hop_by_hop_option_size", "Hop-by-hop Option Size"),
("gap_limit", "Gap Limit"),
))
@classmethod
def render_dns(cls, measurement):
cls._render(measurement, (
("query", "Query", cls._prettify_query),
("retry", "Retry Times"),
("include_qbuf", "Include the Qbuf?", cls._prettify_boolean),
("include_abuf", "Include the Abuf?", cls._prettify_boolean),
("protocol", "Protocol"),
("prepend_probe_id", "Prepend the Probe ID?"),
("udp_payload_size", "UDP Payload Size"),
(
"use_probe_resolver",
"Use the Probe's Resolver?",
cls._prettify_boolean
),
("set_do_bit", "Set the DO Bit?", cls._prettify_boolean),
("set_nsid_bit", "Set the NSID Bit?", cls._prettify_boolean),
("set_rd_bit", "Set the RD Bit?", cls._prettify_boolean),
("set_cd_bit", "Set the CD Bit?", cls._prettify_boolean),
))
@classmethod
def render_sslcert(cls, measurement):
cls._render(measurement, (
("port", "Port"),
))
@classmethod
def render_http(cls, measurement):
cls._render(measurement, (
("header_bytes", "Header Bytes"),
("version", "Version"),
("method", "Method"),
("port", "Port"),
("path", "Path", sanitise),
("query_string", "Query String", sanitise),
("user_agent", "User-Agent"),
("max_bytes_read", "Body Bytes"),
))
timing_verbosity = 0
if "extended_timing" in measurement.meta_data:
if measurement.meta_data["extended_timing"]:
timing_verbosity = 1
if "more_extended_timing" in measurement.meta_data:
if measurement.meta_data["more_extended_timing"]:
timing_verbosity = 2
cls._render_line("Timing Verbosity", timing_verbosity)
@classmethod
def render_ntp(cls, measurement):
cls._render(measurement, (
("packets", "Packets"),
("timeout", "Timeout"),
))
@staticmethod
def _prettify_type(kind):
types = {
"ping": "Ping",
"traceroute": "Traceroute",
"dns": "DNS",
"sslcert": "SSL Certificate",
"http": "HTTP",
"ntp": "NTP"
}
if kind in types:
return colourise(colourise(types[kind], "bold"), "blue")
return colourise("Unknown", "red")
@staticmethod
def _prettify_query(query):
return sanitise(
"{} {} {}".format(query["class"], query["type"], query["value"]))
@classmethod
def _render(cls, measurement, keys):
for prop in keys:
value = None
if prop[0] in measurement.meta_data:
value = measurement.meta_data[prop[0]]
if value is None:
value = "-"
elif len(prop) == 3:
value = prop[2](value)
cls._render_line(prop[1], value)
|