pingerplot 1.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pingerplot/__init__.py +8 -0
- pingerplot/__main__.py +5 -0
- pingerplot/appicon.py +144 -0
- pingerplot/compare.py +257 -0
- pingerplot/ed25519.py +145 -0
- pingerplot/geoip.py +337 -0
- pingerplot/gfx.py +203 -0
- pingerplot/gui.py +1792 -0
- pingerplot/gui_charts.py +409 -0
- pingerplot/gui_history.py +684 -0
- pingerplot/gui_hopinfo.py +125 -0
- pingerplot/gui_recording.py +176 -0
- pingerplot/gui_settings.py +322 -0
- pingerplot/gui_updates.py +270 -0
- pingerplot/gui_widgets.py +248 -0
- pingerplot/headless.py +661 -0
- pingerplot/history.py +823 -0
- pingerplot/icmp.py +305 -0
- pingerplot/icmp_posix.py +456 -0
- pingerplot/investigate.py +205 -0
- pingerplot/launch.py +37 -0
- pingerplot/locating.py +248 -0
- pingerplot/model.py +410 -0
- pingerplot/monitor.py +1404 -0
- pingerplot/places.py +259 -0
- pingerplot/routes.py +112 -0
- pingerplot/selfcheck.py +97 -0
- pingerplot/selftest.py +76 -0
- pingerplot/settings.py +98 -0
- pingerplot/tcpudp.py +479 -0
- pingerplot/theme.py +576 -0
- pingerplot/tkthreads.py +68 -0
- pingerplot/tray.py +373 -0
- pingerplot/trouble.py +129 -0
- pingerplot/update_key.py +8 -0
- pingerplot/updater.py +499 -0
- pingerplot/winplatform.py +366 -0
- pingerplot/worldmap.py +141 -0
- pingerplot/xdg.py +198 -0
- pingerplot-1.6.0.dist-info/METADATA +583 -0
- pingerplot-1.6.0.dist-info/RECORD +45 -0
- pingerplot-1.6.0.dist-info/WHEEL +5 -0
- pingerplot-1.6.0.dist-info/entry_points.txt +5 -0
- pingerplot-1.6.0.dist-info/licenses/LICENSE +21 -0
- pingerplot-1.6.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""What's known about a hop's router: where it is, whose network it's on, and
|
|
2
|
+
which routers have answered at that hop lately.
|
|
3
|
+
|
|
4
|
+
Two witnesses for "where": the router's DNS name (places.py), which for the
|
|
5
|
+
backbone is usually right, and the IP database (geoip.py), which is usually
|
|
6
|
+
right for the edges and often wrong for the backbone. The tables show the
|
|
7
|
+
name's answer when there is one, else the database's unless the round trips
|
|
8
|
+
rule it out (locating.py); the Details window shows both, each with its
|
|
9
|
+
source, so a disagreement is visible rather than hidden.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import time
|
|
14
|
+
import tkinter as tk
|
|
15
|
+
from tkinter import ttk
|
|
16
|
+
from typing import List, Optional, Tuple
|
|
17
|
+
|
|
18
|
+
from . import history, investigate, locating, places
|
|
19
|
+
from .gui_charts import fmt_ms
|
|
20
|
+
from .locating import Where
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _disagree(hint, info) -> bool:
|
|
24
|
+
"""Whether the name's city and the database's are different places: by
|
|
25
|
+
distance, as one metro has many names (New York City for New York,
|
|
26
|
+
Washington for Ashburn); by name where the name's city has no
|
|
27
|
+
coordinates."""
|
|
28
|
+
point = places.coords(hint)
|
|
29
|
+
if point is not None:
|
|
30
|
+
return locating.distance_km(point, (info.lat, info.lon)) > locating.SLACK_KM
|
|
31
|
+
return bool(info.city) and info.city.lower() not in hint.city.lower()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def network(address: Optional[str], geo) -> str:
|
|
35
|
+
info = geo.get(address) if address else None
|
|
36
|
+
return info.network() if info is not None else ""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def facts(address: Optional[str], hostname: Optional[str], where: Where) -> List[Tuple[str, str]]:
|
|
40
|
+
"""Every known fact about the router, as (label, value) rows. ``where``
|
|
41
|
+
is its location (locating.Locator.where)."""
|
|
42
|
+
rows: List[Tuple[str, str]] = [("Address", address or "no reply")]
|
|
43
|
+
rows.append(("Name", hostname or ("looking it up…" if hostname is None and address else "none")))
|
|
44
|
+
hint, info = where.place, where.info
|
|
45
|
+
if hint is not None:
|
|
46
|
+
rows.append(("Where, from its name", f"{hint} (the \"{hint.clue}\" in its name)"))
|
|
47
|
+
if info is not None:
|
|
48
|
+
rows.append(("Where, from the IP database", info.place() or "not known"))
|
|
49
|
+
if where.why:
|
|
50
|
+
rows.append(("", f"{where.why} The tables and the map leave it out."))
|
|
51
|
+
if hint is not None and _disagree(hint, info):
|
|
52
|
+
rows.append(("", "The two disagree: for a carrier's router, the name is usually right."))
|
|
53
|
+
rows.append(("Network", info.network() or "not known"))
|
|
54
|
+
if info.org and info.org != info.isp:
|
|
55
|
+
rows.append(("Block assigned to", info.org))
|
|
56
|
+
elif address:
|
|
57
|
+
rows.append(("Where, from the IP database",
|
|
58
|
+
"not looked up (a private address, or lookups are off or pending)"))
|
|
59
|
+
return rows
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class HopDetails(tk.Toplevel):
|
|
63
|
+
"""One hop, everything known about it."""
|
|
64
|
+
|
|
65
|
+
def __init__(self, app, target: str, ttl: int, address: Optional[str],
|
|
66
|
+
hostname: Optional[str]) -> None:
|
|
67
|
+
super().__init__(app.root)
|
|
68
|
+
look, S = app.look, app.s
|
|
69
|
+
self.title(f"Hop {ttl} of {target}")
|
|
70
|
+
self.transient(app.root)
|
|
71
|
+
self.geometry(f"{S(640)}x{S(520)}")
|
|
72
|
+
look.style_window(self)
|
|
73
|
+
body = ttk.Frame(self, padding=(S(20), S(16)))
|
|
74
|
+
body.pack(fill="both", expand=True)
|
|
75
|
+
ttk.Label(body, text=f"Hop {ttl}", style="Heading.TLabel").pack(anchor="w")
|
|
76
|
+
|
|
77
|
+
grid = ttk.Frame(body)
|
|
78
|
+
grid.pack(fill="x", pady=(S(8), 0))
|
|
79
|
+
grid.columnconfigure(1, weight=1)
|
|
80
|
+
locator = app._locator(target)
|
|
81
|
+
for i, (label, value) in enumerate(facts(address, hostname,
|
|
82
|
+
locator.where(address, hostname, ttl=ttl))):
|
|
83
|
+
ttk.Label(grid, text=label, style="Muted.TLabel").grid(row=i, column=0, sticky="nw",
|
|
84
|
+
padx=(0, S(12)), pady=S(2))
|
|
85
|
+
ttk.Label(grid, text=value, wraplength=S(430), justify="left").grid(
|
|
86
|
+
row=i, column=1, sticky="w", pady=S(2))
|
|
87
|
+
|
|
88
|
+
ttk.Label(body, text="Routers at this hop in the last 24 hours", style="Strong.TLabel").pack(
|
|
89
|
+
anchor="w", pady=(S(16), S(4)))
|
|
90
|
+
cols = (("router", "Router", 140), ("where", "Where", 130), ("share", "Answered", 70),
|
|
91
|
+
("avg", "Avg", 50), ("worst", "Worst", 55))
|
|
92
|
+
tree = ttk.Treeview(body, columns=[c[0] for c in cols], show="headings", height=6)
|
|
93
|
+
for key, title, width in cols:
|
|
94
|
+
tree.heading(key, text=title, anchor="w")
|
|
95
|
+
tree.column(key, width=S(width), anchor="w", stretch=key == "where")
|
|
96
|
+
tree.pack(fill="both", expand=True)
|
|
97
|
+
seen = self._recent_routers(app, target, ttl)
|
|
98
|
+
if not seen:
|
|
99
|
+
tree.insert("", "end", values=("Nothing recorded yet (or history is off).", "", "", "", ""))
|
|
100
|
+
total = sum(r.recv for r in seen) or 1
|
|
101
|
+
for r in seen:
|
|
102
|
+
app.geo.request(r.addr)
|
|
103
|
+
tree.insert("", "end", values=(r.addr, locator.where(r.addr, r.name, r.rtt_min).text,
|
|
104
|
+
f"{r.recv / total * 100:.0f}%", fmt_ms(r.avg),
|
|
105
|
+
fmt_ms(r.rtt_max)))
|
|
106
|
+
ttk.Button(body, text="Close", command=self.destroy).pack(anchor="e", pady=(S(12), 0))
|
|
107
|
+
self.bind("<Escape>", lambda _e: self.destroy())
|
|
108
|
+
|
|
109
|
+
@staticmethod
|
|
110
|
+
def _recent_routers(app, target: str, ttl: int) -> list:
|
|
111
|
+
# No recorder.flush() first: this runs on the window's thread, and a
|
|
112
|
+
# busy writer kept Details from opening for up to 2 s (2026-11
|
|
113
|
+
# review). It reads minute summaries, which reach the file only once
|
|
114
|
+
# their minute is over, so a flush added at most a few seconds' worth.
|
|
115
|
+
reader = history.Reader()
|
|
116
|
+
try:
|
|
117
|
+
now = time.time()
|
|
118
|
+
for hop in investigate.hops(reader, target, now - 86400, now):
|
|
119
|
+
if hop.ttl == ttl:
|
|
120
|
+
return hop.routers
|
|
121
|
+
return []
|
|
122
|
+
except Exception:
|
|
123
|
+
return []
|
|
124
|
+
finally:
|
|
125
|
+
reader.close()
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""The Settings page's Recording section: whether the history is kept, what
|
|
2
|
+
goes into it and for how long, where it is and how big, and clearing it.
|
|
3
|
+
|
|
4
|
+
Recording is on by default and needs no setup; everything here is for
|
|
5
|
+
changing what it keeps. The "what to record" switches sit behind a
|
|
6
|
+
"Choose…" button, as advanced settings: the defaults record everything.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import subprocess
|
|
12
|
+
import sys
|
|
13
|
+
import threading
|
|
14
|
+
import tkinter as tk
|
|
15
|
+
from tkinter import messagebox, ttk
|
|
16
|
+
from typing import Dict
|
|
17
|
+
|
|
18
|
+
from . import history
|
|
19
|
+
from .gui_widgets import section, setting_row
|
|
20
|
+
|
|
21
|
+
_SIZE_REFRESH_MS = 10_000
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class RecordingVars:
|
|
25
|
+
"""Tk variables for the ``recording`` section of settings.json."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, master, saved) -> None:
|
|
28
|
+
self.vars: Dict[str, tk.Variable] = {}
|
|
29
|
+
for key, value in history.normalize(saved).items():
|
|
30
|
+
if isinstance(value, bool):
|
|
31
|
+
self.vars[key] = tk.BooleanVar(master=master, value=value)
|
|
32
|
+
else:
|
|
33
|
+
self.vars[key] = tk.StringVar(master=master, value=str(value))
|
|
34
|
+
|
|
35
|
+
def __getitem__(self, key: str) -> tk.Variable:
|
|
36
|
+
return self.vars[key]
|
|
37
|
+
|
|
38
|
+
def options(self) -> dict:
|
|
39
|
+
"""The options as the recorder takes them. A number field holding
|
|
40
|
+
something else ("7.5", "", a typo) falls back to its default rather
|
|
41
|
+
than raising: the field is validated by being normalised."""
|
|
42
|
+
raw = {}
|
|
43
|
+
for key, var in self.vars.items():
|
|
44
|
+
value = var.get()
|
|
45
|
+
if isinstance(value, str):
|
|
46
|
+
try:
|
|
47
|
+
value = int(float(value.strip()))
|
|
48
|
+
except (ValueError, OverflowError):
|
|
49
|
+
pass
|
|
50
|
+
raw[key] = value
|
|
51
|
+
return history.normalize(raw)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def open_folder(path) -> None:
|
|
55
|
+
"""Show ``path`` in the system's file manager, creating it if need be."""
|
|
56
|
+
path = os.fspath(path)
|
|
57
|
+
try:
|
|
58
|
+
os.makedirs(path, exist_ok=True)
|
|
59
|
+
if sys.platform == "win32":
|
|
60
|
+
os.startfile(path) # type: ignore[attr-defined]
|
|
61
|
+
else:
|
|
62
|
+
subprocess.Popen(["open" if sys.platform == "darwin" else "xdg-open", path])
|
|
63
|
+
except OSError as exc:
|
|
64
|
+
messagebox.showerror("Can't open the folder", f"{path}\n\n{exc}")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _fmt_size(n: int) -> str:
|
|
68
|
+
if n < 1024 * 1024:
|
|
69
|
+
return f"{n / 1024:.0f} KB"
|
|
70
|
+
if n < 1024 ** 3:
|
|
71
|
+
return f"{n / 1024 ** 2:.0f} MB"
|
|
72
|
+
return f"{n / 1024 ** 3:.1f} GB"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def build_section(parent, look, app) -> None:
|
|
76
|
+
"""The Recording card. ``app`` provides ``recording`` (RecordingVars),
|
|
77
|
+
``recorder`` and ``clear_history()``."""
|
|
78
|
+
S = look.S
|
|
79
|
+
rv: RecordingVars = app.recording
|
|
80
|
+
|
|
81
|
+
def switch(var):
|
|
82
|
+
return lambda row: ttk.Checkbutton(row, variable=var, style="Card.Switch.TCheckbutton")
|
|
83
|
+
|
|
84
|
+
def spin(var, lo, hi, step=1):
|
|
85
|
+
return lambda row: ttk.Spinbox(row, from_=lo, to=hi, increment=step, width=7,
|
|
86
|
+
textvariable=var, style="Card.TSpinbox")
|
|
87
|
+
|
|
88
|
+
card = section(parent, look, "Recording")
|
|
89
|
+
setting_row(card, look, "Record history",
|
|
90
|
+
"Everything each target measures goes into a database on this computer: every "
|
|
91
|
+
"probe and the router that answered it, per-minute summaries for each hop, alerts, "
|
|
92
|
+
"reroutes and DNS moves. Nothing is sent anywhere.",
|
|
93
|
+
switch(rv["enabled"]), first=True)
|
|
94
|
+
setting_row(card, look, "Keep every probe for (days)",
|
|
95
|
+
"The full detail. About 25 MB a day for a 15-hop target probed every 2.5 s.",
|
|
96
|
+
spin(rv["probe_days"], 1, 365))
|
|
97
|
+
setting_row(card, look, "Keep minute summaries for (days)",
|
|
98
|
+
"Loss, latency and jitter for each hop and router, minute by minute: small "
|
|
99
|
+
"enough to keep for years.",
|
|
100
|
+
spin(rv["summary_days"], 1, 3650))
|
|
101
|
+
setting_row(card, look, "Keep events and routes for (days)", "",
|
|
102
|
+
spin(rv["event_days"], 1, 3650))
|
|
103
|
+
setting_row(card, look, "Size limit (MB)",
|
|
104
|
+
"Past it, the oldest probes go first, then summaries, then events.",
|
|
105
|
+
spin(rv["max_mb"], 50, 100_000, 50))
|
|
106
|
+
|
|
107
|
+
# Advanced: what to record, behind a button so the defaults (everything)
|
|
108
|
+
# need no reading.
|
|
109
|
+
advanced = ttk.Frame(card, style="Card.TFrame")
|
|
110
|
+
shown = {"open": False}
|
|
111
|
+
|
|
112
|
+
def toggle(button):
|
|
113
|
+
shown["open"] = not shown["open"]
|
|
114
|
+
if shown["open"]:
|
|
115
|
+
advanced.pack(side="top", fill="x", after=choose_row)
|
|
116
|
+
button.configure(text="Hide")
|
|
117
|
+
else:
|
|
118
|
+
advanced.pack_forget()
|
|
119
|
+
button.configure(text="Choose…")
|
|
120
|
+
|
|
121
|
+
def choose(row):
|
|
122
|
+
b = ttk.Button(row, text="Choose…", style="Card.TButton")
|
|
123
|
+
b.configure(command=lambda: toggle(b))
|
|
124
|
+
return b
|
|
125
|
+
choose_row = setting_row(card, look, "What to record",
|
|
126
|
+
"Everything, unless you choose otherwise.", choose)
|
|
127
|
+
setting_row(advanced, look, "Every probe",
|
|
128
|
+
"Off keeps only the minute summaries: far less space, the same picture at "
|
|
129
|
+
"one-minute resolution.", switch(rv["probes"]))
|
|
130
|
+
setting_row(advanced, look, "Minute summaries", "", switch(rv["summaries"]))
|
|
131
|
+
setting_row(advanced, look, "Events", "Alerts, reroutes, DNS moves, warnings and notes.",
|
|
132
|
+
switch(rv["events"]))
|
|
133
|
+
setting_row(advanced, look, "Routes", "Which route each target was on, and when.",
|
|
134
|
+
switch(rv["routes"]))
|
|
135
|
+
|
|
136
|
+
folder = history.default_dir()
|
|
137
|
+
|
|
138
|
+
def storage(row):
|
|
139
|
+
box = ttk.Frame(row, style="Card.TFrame")
|
|
140
|
+
ttk.Button(box, text="Open folder", style="Card.TButton",
|
|
141
|
+
command=lambda: open_folder(folder)).pack(side="left")
|
|
142
|
+
ttk.Button(box, text="Clear history…", style="Card.TButton",
|
|
143
|
+
command=app.clear_history).pack(side="left", padx=(S(6), 0))
|
|
144
|
+
return box
|
|
145
|
+
where = setting_row(card, look, "Stored in", str(folder), storage)
|
|
146
|
+
size = ttk.Label(where, text="", style="Card.Muted.TLabel")
|
|
147
|
+
size.grid(row=2, column=0, sticky="w", pady=(S(2), 0))
|
|
148
|
+
|
|
149
|
+
def refresh():
|
|
150
|
+
try:
|
|
151
|
+
if not size.winfo_exists():
|
|
152
|
+
return
|
|
153
|
+
except tk.TclError:
|
|
154
|
+
return
|
|
155
|
+
used = history.disk_bytes(folder)
|
|
156
|
+
size.configure(text=f"Using {_fmt_size(used)}" if used else "Nothing recorded yet")
|
|
157
|
+
size.after(_SIZE_REFRESH_MS, refresh)
|
|
158
|
+
refresh()
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def clear_history(app) -> None:
|
|
162
|
+
"""Ask, then delete everything recorded. Running targets carry on."""
|
|
163
|
+
if not messagebox.askyesno(
|
|
164
|
+
"Clear history",
|
|
165
|
+
"Delete everything PingerPlot has recorded, for every target?\n\n"
|
|
166
|
+
"This can't be undone. Targets that are running carry on recording.",
|
|
167
|
+
icon="warning", default="no", parent=app.root):
|
|
168
|
+
return
|
|
169
|
+
rec = app.recorder
|
|
170
|
+
if rec is not None:
|
|
171
|
+
rec.clear()
|
|
172
|
+
return
|
|
173
|
+
# Recording is off, but the user still wants the old history gone.
|
|
174
|
+
temp = history.Recorder(program="gui").start()
|
|
175
|
+
temp.clear()
|
|
176
|
+
threading.Thread(target=temp.close, name="history-clear", daemon=True).start()
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"""The settings a target runs with, and the two places they're edited: the
|
|
2
|
+
Settings page (defaults for targets added from now on, plus the app's own
|
|
3
|
+
options) and a target's Edit dialog. One form definition serves both, so a
|
|
4
|
+
setting can't exist in one and be missing from the other."""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import math
|
|
8
|
+
import tkinter as tk
|
|
9
|
+
import webbrowser
|
|
10
|
+
from tkinter import filedialog, messagebox, ttk
|
|
11
|
+
from typing import Callable, Dict
|
|
12
|
+
|
|
13
|
+
from . import __version__, monitor, tcpudp, winplatform
|
|
14
|
+
from .gui_widgets import ScrollFrame, section, setting_row
|
|
15
|
+
|
|
16
|
+
REPO_URL = "https://github.com/jamesccupps/PingerPlot"
|
|
17
|
+
|
|
18
|
+
# start() keyword, kind, default, and the key it has always had in
|
|
19
|
+
# settings.json (the names predate this form, and old files must still load).
|
|
20
|
+
FIELDS = (
|
|
21
|
+
("packet_type", "str", "ICMP", "packet_type"),
|
|
22
|
+
("port", "str", "443", "port"),
|
|
23
|
+
("interval", "str", "2.5", "interval"),
|
|
24
|
+
("timeout_ms", "str", "1000", "timeout_ms"),
|
|
25
|
+
("max_hops", "str", "30", "max_hops"),
|
|
26
|
+
("packet_size", "str", "32", "packet_size"),
|
|
27
|
+
("send_delay_ms", "str", "0", "send_delay_ms"),
|
|
28
|
+
("dscp", "str", "0", "dscp"),
|
|
29
|
+
("source_ip", "str", "", "source_ip"),
|
|
30
|
+
("resolve_names", "bool", True, "resolve_names"),
|
|
31
|
+
("final_hop_only", "bool", False, "final_hop_only"),
|
|
32
|
+
("alert_enabled", "bool", True, "alerts_enabled"),
|
|
33
|
+
("alert_loss_pct", "str", "20", "alert_loss"),
|
|
34
|
+
("alert_latency_ms", "str", "250", "alert_latency"),
|
|
35
|
+
("alert_window", "str", "20", "alert_window"),
|
|
36
|
+
("alert_mos", "str", "0", "alert_mos"),
|
|
37
|
+
("alert_sound", "bool", True, "alert_sound"),
|
|
38
|
+
("log_path", "str", "", "log_path"),
|
|
39
|
+
("webhook_url", "str", "", "webhook_url"),
|
|
40
|
+
)
|
|
41
|
+
NUMBERS = { # what each number field must parse as, and its name in an error
|
|
42
|
+
"interval": (float, "Probe every"), "timeout_ms": (int, "Reply timeout"),
|
|
43
|
+
"max_hops": (int, "Maximum hops"), "packet_size": (int, "Packet size"),
|
|
44
|
+
"send_delay_ms": (int, "Delay between probes"), "port": (int, "Port"),
|
|
45
|
+
"dscp": (int, "DSCP"), "alert_loss_pct": (float, "Packet loss"),
|
|
46
|
+
"alert_latency_ms": (float, "Latency"), "alert_window": (int, "Over the last"),
|
|
47
|
+
"alert_mos": (float, "MOS"),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class OptionVars:
|
|
52
|
+
"""Tk variables for every start() option, and the conversions to and
|
|
53
|
+
from a Monitor's options and the settings file."""
|
|
54
|
+
|
|
55
|
+
def __init__(self, master) -> None:
|
|
56
|
+
self.vars: Dict[str, tk.Variable] = {}
|
|
57
|
+
for key, kind, default, _skey in FIELDS:
|
|
58
|
+
cls = tk.BooleanVar if kind == "bool" else tk.StringVar
|
|
59
|
+
self.vars[key] = cls(master=master, value=default)
|
|
60
|
+
|
|
61
|
+
def __getitem__(self, key: str) -> tk.Variable:
|
|
62
|
+
return self.vars[key]
|
|
63
|
+
|
|
64
|
+
def to_options(self) -> dict:
|
|
65
|
+
"""start() keyword arguments. Raises ValueError naming the field
|
|
66
|
+
whose text isn't a number."""
|
|
67
|
+
out = {}
|
|
68
|
+
for key, kind, _default, _skey in FIELDS:
|
|
69
|
+
v = self.vars[key].get()
|
|
70
|
+
if key in NUMBERS:
|
|
71
|
+
conv, label = NUMBERS[key]
|
|
72
|
+
try:
|
|
73
|
+
f = float(str(v).strip())
|
|
74
|
+
if not math.isfinite(f): # "inf", "1e999", "nan"
|
|
75
|
+
raise ValueError
|
|
76
|
+
v = conv(f)
|
|
77
|
+
except ValueError:
|
|
78
|
+
raise ValueError(f"{label} must be a number (it says {v!r}).") from None
|
|
79
|
+
elif key == "packet_type":
|
|
80
|
+
v = str(v).lower()
|
|
81
|
+
elif kind == "str":
|
|
82
|
+
v = str(v).strip()
|
|
83
|
+
out[key] = v
|
|
84
|
+
return out
|
|
85
|
+
|
|
86
|
+
def load_options(self, opts: dict) -> None:
|
|
87
|
+
"""Show a Monitor's options (Monitor.start_options())."""
|
|
88
|
+
for key, kind, _default, _skey in FIELDS:
|
|
89
|
+
if key not in opts:
|
|
90
|
+
continue
|
|
91
|
+
v = opts[key]
|
|
92
|
+
if key == "packet_type":
|
|
93
|
+
v = str(v).upper()
|
|
94
|
+
elif kind == "bool":
|
|
95
|
+
v = bool(v)
|
|
96
|
+
elif isinstance(v, float):
|
|
97
|
+
v = f"{v:g}"
|
|
98
|
+
self.vars[key].set(v)
|
|
99
|
+
|
|
100
|
+
def load_settings(self, s: dict) -> None:
|
|
101
|
+
for key, kind, _default, skey in FIELDS:
|
|
102
|
+
val = s.get(skey)
|
|
103
|
+
if val is None:
|
|
104
|
+
continue
|
|
105
|
+
if kind == "bool":
|
|
106
|
+
if isinstance(val, bool):
|
|
107
|
+
self.vars[key].set(val)
|
|
108
|
+
else:
|
|
109
|
+
self.vars[key].set(str(val))
|
|
110
|
+
|
|
111
|
+
def save_settings(self, s: dict) -> None:
|
|
112
|
+
for key, kind, _default, skey in FIELDS:
|
|
113
|
+
v = self.vars[key].get()
|
|
114
|
+
s[skey] = bool(v) if kind == "bool" else v
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# --- the form ------------------------------------------------------------------
|
|
118
|
+
|
|
119
|
+
def _spin(look, var, lo, hi, step=1, width=7, fmt=None):
|
|
120
|
+
def make(parent):
|
|
121
|
+
kw = dict(from_=lo, to=hi, increment=step, width=width, textvariable=var)
|
|
122
|
+
if fmt:
|
|
123
|
+
kw["format"] = fmt
|
|
124
|
+
return ttk.Spinbox(parent, style="Card.TSpinbox", **kw)
|
|
125
|
+
return make
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _switch(var):
|
|
129
|
+
return lambda parent: ttk.Checkbutton(parent, variable=var, style="Card.Switch.TCheckbutton")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _entry(var, width=28):
|
|
133
|
+
return lambda parent: ttk.Entry(parent, textvariable=var, width=width, style="Card.TEntry")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def build_option_form(parent, look, ov: OptionVars, browse_log: Callable[[], None]) -> None:
|
|
137
|
+
"""The Probing, Alerts and Logging sections, bound to ``ov``."""
|
|
138
|
+
def probe_type(row):
|
|
139
|
+
box = ttk.Combobox(row, textvariable=ov["packet_type"], values=["ICMP", "TCP", "UDP"],
|
|
140
|
+
state="readonly", width=7, style="Card.TCombobox")
|
|
141
|
+
|
|
142
|
+
def changed(_e=None):
|
|
143
|
+
ptype = ov["packet_type"].get().lower()
|
|
144
|
+
if ptype in tcpudp.DEFAULT_PORTS:
|
|
145
|
+
ov["port"].set(str(tcpudp.DEFAULT_PORTS[ptype]))
|
|
146
|
+
box.bind("<<ComboboxSelected>>", changed)
|
|
147
|
+
return box
|
|
148
|
+
|
|
149
|
+
card = section(parent, look, "Probing")
|
|
150
|
+
setting_row(card, look, "Probe type",
|
|
151
|
+
"ICMP needs no administrator rights. TCP and UDP follow the path a service's traffic "
|
|
152
|
+
"takes; tracing every hop with them needs Administrator on Windows.",
|
|
153
|
+
probe_type, first=True)
|
|
154
|
+
setting_row(card, look, "Port",
|
|
155
|
+
"TCP: the service's port. UDP: the port every probe goes to.",
|
|
156
|
+
_spin(look, ov["port"], 1, 65535))
|
|
157
|
+
setting_row(card, look, "Probe every (seconds)", "", _spin(look, ov["interval"], 0.5, 60, 0.5))
|
|
158
|
+
setting_row(card, look, "Reply timeout (ms)",
|
|
159
|
+
f"TCP waits at least {monitor.TCP_REFUSAL_FLOOR_MS} ms: Windows takes about 2 s to "
|
|
160
|
+
"report a closed port, and a shorter wait can't tell one from an unreachable host.",
|
|
161
|
+
_spin(look, ov["timeout_ms"], 100, 10000, 100))
|
|
162
|
+
setting_row(card, look, "Maximum hops", "", _spin(look, ov["max_hops"], 1, 64))
|
|
163
|
+
setting_row(card, look, "Packet size (bytes)", "", _spin(look, ov["packet_size"], 0, 1472, 8))
|
|
164
|
+
setting_row(card, look, "Delay between probes (ms)",
|
|
165
|
+
"Spreads each round's probes out, for routers that rate-limit.",
|
|
166
|
+
_spin(look, ov["send_delay_ms"], 0, 1000, 5))
|
|
167
|
+
setting_row(card, look, "DSCP",
|
|
168
|
+
"Marks probes as a traffic class: 46 is EF (voice), 34 AF41 (video), 0 best effort. "
|
|
169
|
+
"Windows ignores it on TCP and UDP unless DisableUserTOSSetting is cleared.",
|
|
170
|
+
_spin(look, ov["dscp"], 0, 63))
|
|
171
|
+
setting_row(card, look, "Source address",
|
|
172
|
+
"Blank lets the system choose the interface. An address this computer doesn't "
|
|
173
|
+
"have is refused, never quietly replaced.",
|
|
174
|
+
_entry(ov["source_ip"], 18))
|
|
175
|
+
setting_row(card, look, "Look up hostnames", "Reverse DNS for every hop.", _switch(ov["resolve_names"]))
|
|
176
|
+
setting_row(card, look, "Destination only",
|
|
177
|
+
"Ping just the destination, without mapping the route.", _switch(ov["final_hop_only"]))
|
|
178
|
+
|
|
179
|
+
card = section(parent, look, "Alerts")
|
|
180
|
+
setting_row(card, look, "Alert on the destination",
|
|
181
|
+
"Alerts judge the last hop only: loss at a router in the middle is usually that "
|
|
182
|
+
"router deprioritising ICMP, not a problem on the path.",
|
|
183
|
+
_switch(ov["alert_enabled"]), first=True)
|
|
184
|
+
setting_row(card, look, "Packet loss at or above (%)", "0 turns it off.",
|
|
185
|
+
_spin(look, ov["alert_loss_pct"], 0, 100, 5))
|
|
186
|
+
setting_row(card, look, "Average latency at or above (ms)", "0 turns it off.",
|
|
187
|
+
_spin(look, ov["alert_latency_ms"], 0, 5000, 25))
|
|
188
|
+
setting_row(card, look, "MOS at or below",
|
|
189
|
+
"The voice-quality score, 1 to 5: under 3.6 is poor for a call. 0 turns it off.",
|
|
190
|
+
_spin(look, ov["alert_mos"], 0, 5, 0.1, fmt="%.1f"))
|
|
191
|
+
setting_row(card, look, "Over the last (probes)",
|
|
192
|
+
"How long a problem has to last before it alerts.",
|
|
193
|
+
_spin(look, ov["alert_window"], 2, 300))
|
|
194
|
+
setting_row(card, look, "Play a sound", "", _switch(ov["alert_sound"]))
|
|
195
|
+
|
|
196
|
+
def log_control(row):
|
|
197
|
+
box = ttk.Frame(row, style="Card.TFrame")
|
|
198
|
+
ttk.Entry(box, textvariable=ov["log_path"], width=24, style="Card.TEntry").pack(side="left")
|
|
199
|
+
ttk.Button(box, text="Browse…", style="Card.TButton", command=browse_log).pack(
|
|
200
|
+
side="left", padx=(look.S(6), 0))
|
|
201
|
+
return box
|
|
202
|
+
|
|
203
|
+
card = section(parent, look, "Logging and webhooks")
|
|
204
|
+
setting_row(card, look, "Also log every probe to",
|
|
205
|
+
"Everything is in the history already (see Recording); this adds a plain CSV per "
|
|
206
|
+
"target, flushed as it goes: probe.csv becomes probe_<target>.csv. Rolls over at "
|
|
207
|
+
"25 MB, keeping one backup.", log_control, first=True)
|
|
208
|
+
setting_row(card, look, "Webhook",
|
|
209
|
+
"An http(s) address that gets a JSON POST when an alert starts or ends. Delivery "
|
|
210
|
+
"failures show in the target's Events.", _entry(ov["webhook_url"], 30))
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def browse_log_into(var: tk.Variable, parent=None) -> None:
|
|
214
|
+
path = filedialog.asksaveasfilename(
|
|
215
|
+
parent=parent, title="Log probes to CSV", defaultextension=".csv",
|
|
216
|
+
initialfile="probe.csv", confirmoverwrite=False,
|
|
217
|
+
filetypes=[("CSV files", "*.csv"), ("All files", "*.*")])
|
|
218
|
+
if path:
|
|
219
|
+
var.set(path)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# --- the Settings page -----------------------------------------------------------
|
|
223
|
+
|
|
224
|
+
class SettingsPage(ScrollFrame):
|
|
225
|
+
"""Defaults for new targets, and the app's own options."""
|
|
226
|
+
|
|
227
|
+
def __init__(self, parent, app) -> None:
|
|
228
|
+
super().__init__(parent, app.look)
|
|
229
|
+
look, S = app.look, app.look.S
|
|
230
|
+
body = ttk.Frame(self.inner, padding=(S(24), 0, S(24), S(24)))
|
|
231
|
+
body.pack(fill="both", expand=True)
|
|
232
|
+
ttk.Label(body, text="New targets use these settings. To change a target that's already "
|
|
233
|
+
"running, right-click it and choose Edit settings.",
|
|
234
|
+
style="Muted.TLabel", wraplength=S(680), justify="left").pack(
|
|
235
|
+
side="top", anchor="w", pady=(S(8), 0))
|
|
236
|
+
build_option_form(body, look, app.defaults,
|
|
237
|
+
lambda: browse_log_into(app.defaults["log_path"], app.root))
|
|
238
|
+
from .gui_recording import build_section as build_recording
|
|
239
|
+
build_recording(body, look, app)
|
|
240
|
+
|
|
241
|
+
card = section(body, look, "App")
|
|
242
|
+
|
|
243
|
+
def theme_control(row):
|
|
244
|
+
labels = {"system": winplatform.THEME_LABEL, "dark": "Dark", "light": "Light"}
|
|
245
|
+
shown = tk.StringVar(master=row, value=labels.get(app.theme_var.get(), labels["system"]))
|
|
246
|
+
box = ttk.Combobox(row, textvariable=shown, values=list(labels.values()),
|
|
247
|
+
state="readonly", width=17, style="Card.TCombobox")
|
|
248
|
+
back = {v: k for k, v in labels.items()}
|
|
249
|
+
box.bind("<<ComboboxSelected>>", lambda _e: app._apply_theme(back[shown.get()]))
|
|
250
|
+
app.theme_var.trace_add("write", lambda *_a: shown.set(labels.get(app.theme_var.get(), "")))
|
|
251
|
+
return box
|
|
252
|
+
setting_row(card, look, "Theme", "", theme_control, first=True)
|
|
253
|
+
setting_row(card, look, "Resume targets when the app starts",
|
|
254
|
+
"Each with the settings it was running with.", _switch(app.resume_var))
|
|
255
|
+
setting_row(card, look, "Look up where routers are",
|
|
256
|
+
"Each public router's location and network owner, from ipwho.is, for the hop "
|
|
257
|
+
"table, Details, History and the map. Only hop addresses are sent, the "
|
|
258
|
+
"destination's included (never private or LAN ones), each about once a "
|
|
259
|
+
"month; router names are read for "
|
|
260
|
+
"their city without sending anything. Off, the Map looks up only while open.",
|
|
261
|
+
_switch(app.lookup_var))
|
|
262
|
+
app.build_app_settings(card)
|
|
263
|
+
app.updates.build_section(body)
|
|
264
|
+
|
|
265
|
+
card = section(body, look, "About")
|
|
266
|
+
|
|
267
|
+
def links(row):
|
|
268
|
+
box = ttk.Frame(row, style="Card.TFrame")
|
|
269
|
+
for text, url in (("Project page", REPO_URL),
|
|
270
|
+
("What's new", f"{REPO_URL}/releases"),
|
|
271
|
+
("Report a problem", app.report_url())):
|
|
272
|
+
lab = ttk.Label(box, text=text, style="Card.Link.TLabel", cursor="hand2")
|
|
273
|
+
lab.pack(side="left", padx=(S(14), 0))
|
|
274
|
+
lab.bind("<Button-1>", lambda _e, u=url: webbrowser.open(u))
|
|
275
|
+
return box
|
|
276
|
+
setting_row(card, look, f"PingerPlot {__version__}",
|
|
277
|
+
"MIT licensed. No third-party dependencies.", links, first=True)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
# --- one target's settings ---------------------------------------------------------
|
|
281
|
+
|
|
282
|
+
class EditTargetDialog(tk.Toplevel):
|
|
283
|
+
"""A running (or stopped) target's own settings. Applying restarts it with
|
|
284
|
+
them; its history starts again, as a restart always has."""
|
|
285
|
+
|
|
286
|
+
def __init__(self, app, name: str) -> None:
|
|
287
|
+
super().__init__(app.root)
|
|
288
|
+
self.app, self.name = app, name
|
|
289
|
+
look, S = app.look, app.look.S
|
|
290
|
+
self.title(f"Settings for {name}")
|
|
291
|
+
self.transient(app.root)
|
|
292
|
+
self.geometry(f"{S(720)}x{S(640)}")
|
|
293
|
+
look.style_window(self)
|
|
294
|
+
self.ov = OptionVars(self)
|
|
295
|
+
mon = app._monitors.get(name)
|
|
296
|
+
self.ov.load_options(mon.start_options() if mon is not None else app.defaults.to_options())
|
|
297
|
+
if mon is not None:
|
|
298
|
+
self.ov["log_path"].set(monitor.log_path_template(mon.log_path, name))
|
|
299
|
+
|
|
300
|
+
foot = ttk.Frame(self, padding=(S(24), S(12)))
|
|
301
|
+
foot.pack(side="bottom", fill="x")
|
|
302
|
+
ttk.Button(foot, text="Cancel", command=self.destroy).pack(side="right")
|
|
303
|
+
ttk.Button(foot, text="Apply and restart", style="Accent.TButton",
|
|
304
|
+
command=self.apply).pack(side="right", padx=(0, S(8)))
|
|
305
|
+
ttk.Label(foot, text="Applying restarts the target: its history starts again.",
|
|
306
|
+
style="Muted.TLabel").pack(side="left")
|
|
307
|
+
|
|
308
|
+
scroll = ScrollFrame(self, look)
|
|
309
|
+
scroll.pack(side="top", fill="both", expand=True)
|
|
310
|
+
body = ttk.Frame(scroll.inner, padding=(S(24), 0, S(24), S(16)))
|
|
311
|
+
body.pack(fill="both", expand=True)
|
|
312
|
+
build_option_form(body, look, self.ov, lambda: browse_log_into(self.ov["log_path"], self))
|
|
313
|
+
self.bind("<Escape>", lambda _e: self.destroy())
|
|
314
|
+
|
|
315
|
+
def apply(self) -> None:
|
|
316
|
+
try:
|
|
317
|
+
opts = self.ov.to_options()
|
|
318
|
+
except ValueError as exc:
|
|
319
|
+
messagebox.showwarning("Check the settings", str(exc), parent=self)
|
|
320
|
+
return
|
|
321
|
+
self.destroy()
|
|
322
|
+
self.app._start(self.name, opts)
|