dnskit 0.1.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.
- dnskit/__init__.py +9 -0
- dnskit/__main__.py +5 -0
- dnskit/cli/__init__.py +1 -0
- dnskit/cli/app.py +955 -0
- dnskit/cli/render.py +1334 -0
- dnskit/core/__init__.py +349 -0
- dnskit/core/adapters.py +521 -0
- dnskit/core/batch.py +211 -0
- dnskit/core/compare.py +168 -0
- dnskit/core/config.py +248 -0
- dnskit/core/connectivity.py +139 -0
- dnskit/core/diagnosis.py +100 -0
- dnskit/core/dnssec.py +767 -0
- dnskit/core/doctor.py +836 -0
- dnskit/core/integrity.py +232 -0
- dnskit/core/local.py +725 -0
- dnskit/core/lookup.py +218 -0
- dnskit/core/mail.py +1346 -0
- dnskit/core/nameservers.py +223 -0
- dnskit/core/outside.py +113 -0
- dnskit/core/propagation.py +277 -0
- dnskit/core/reach.py +255 -0
- dnskit/core/reverse.py +61 -0
- dnskit/core/serialize.py +64 -0
- dnskit/core/trace.py +591 -0
- dnskit/core/watch.py +167 -0
- dnskit/py.typed +0 -0
- dnskit-0.1.0.dist-info/METADATA +362 -0
- dnskit-0.1.0.dist-info/RECORD +32 -0
- dnskit-0.1.0.dist-info/WHEEL +4 -0
- dnskit-0.1.0.dist-info/entry_points.txt +2 -0
- dnskit-0.1.0.dist-info/licenses/LICENSE +21 -0
dnskit/core/doctor.py
ADDED
|
@@ -0,0 +1,836 @@
|
|
|
1
|
+
"""A full health check: this computer's DNS setup, then one domain, from the other checks.
|
|
2
|
+
|
|
3
|
+
Nothing here queries DNS itself: `doctor()` runs `local_check`, `lookup`, `compare`,
|
|
4
|
+
`reach`, `email_check` and `dnssec_check` in parallel and turns their results into
|
|
5
|
+
`Issue`s, each about either this computer or the domain, ranked by `Impact`. The score
|
|
6
|
+
starts at 100 and loses points per issue.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import time
|
|
10
|
+
from collections.abc import Callable, Sequence
|
|
11
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
12
|
+
from concurrent.futures import TimeoutError as FuturesTimeout
|
|
13
|
+
from dataclasses import dataclass, replace
|
|
14
|
+
from enum import StrEnum
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from dnskit.core.compare import CompareReport, ResolverAnswer, compare
|
|
18
|
+
from dnskit.core.connectivity import ConnectAttempt, tcp_connect
|
|
19
|
+
from dnskit.core.diagnosis import Diagnosis, explain
|
|
20
|
+
from dnskit.core.dnssec import (
|
|
21
|
+
ClockState,
|
|
22
|
+
DnssecReport,
|
|
23
|
+
DnssecStatus,
|
|
24
|
+
clock_diagnosis,
|
|
25
|
+
dnssec_check,
|
|
26
|
+
explain_dnssec,
|
|
27
|
+
)
|
|
28
|
+
from dnskit.core.local import LocalReport, Problem, ProblemKind, Severity, local_check
|
|
29
|
+
from dnskit.core.lookup import LookupReport, LookupResult, LookupStatus, lookup
|
|
30
|
+
from dnskit.core.mail import CheckStatus, EmailReport, email_check
|
|
31
|
+
from dnskit.core.nameservers import choose_nameserver, system_nameservers
|
|
32
|
+
from dnskit.core.reach import (
|
|
33
|
+
DEFAULT_PORT,
|
|
34
|
+
ReachReport,
|
|
35
|
+
ReachVerdict,
|
|
36
|
+
explain_reach,
|
|
37
|
+
parse_target,
|
|
38
|
+
reach,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Seconds per query for the domain checks. Lower than the single commands' 5 s: a doctor
|
|
42
|
+
# run waits for its slowest check.
|
|
43
|
+
DOCTOR_TIMEOUT_S = 3.0
|
|
44
|
+
# Public resolvers asked to confirm that a name doesn't exist, when this computer's DNS
|
|
45
|
+
# server says so. (`dnssec_check` has its own fallback for servers that strip signatures.)
|
|
46
|
+
FALLBACK_RESOLVERS: tuple[str, ...] = ("8.8.8.8", "1.1.1.1")
|
|
47
|
+
# Seconds for each connection to a resolver's answer, when resolvers give different
|
|
48
|
+
# addresses (doctor checks that every one of them works).
|
|
49
|
+
ANSWER_CONNECT_TIMEOUT_S = 2.0
|
|
50
|
+
# How long the domain checks wait for the lookup before starting anyway. "Doesn't exist"
|
|
51
|
+
# comes back fast; a slow lookup is a timeout or a failure, so waiting longer only adds time.
|
|
52
|
+
LOOKUP_WAIT_S = 0.5
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class Check(StrEnum):
|
|
56
|
+
LOCAL = "local"
|
|
57
|
+
LOOKUP = "lookup"
|
|
58
|
+
COMPARE = "compare"
|
|
59
|
+
REACH = "reach"
|
|
60
|
+
EMAIL = "email"
|
|
61
|
+
DNSSEC = "dnssec"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
CHECK_LABELS: dict[Check, str] = {
|
|
65
|
+
Check.LOCAL: "This computer: adapters, DNS servers, VPN, hijacking, interception, IPv6",
|
|
66
|
+
Check.LOOKUP: "Records (A, AAAA, MX, CNAME, NS, TXT)",
|
|
67
|
+
Check.COMPARE: "Answers from public resolvers and this computer's DNS servers",
|
|
68
|
+
Check.REACH: "Connection to the domain (port 443)",
|
|
69
|
+
Check.EMAIL: "Email: MX, SPF, DMARC, DKIM",
|
|
70
|
+
Check.DNSSEC: "DNSSEC chain of trust",
|
|
71
|
+
}
|
|
72
|
+
# Skipped by --quick: each makes many queries or waits on far-away servers.
|
|
73
|
+
SLOW_CHECKS: tuple[Check, ...] = (Check.COMPARE, Check.EMAIL, Check.DNSSEC)
|
|
74
|
+
# Need the domain to exist: skipped when the lookup says it doesn't.
|
|
75
|
+
NEEDS_DOMAIN: tuple[Check, ...] = (Check.COMPARE, Check.REACH, Check.EMAIL, Check.DNSSEC)
|
|
76
|
+
SKIP_QUICK = "--quick"
|
|
77
|
+
SKIP_NO_DOMAIN = "domain doesn't exist"
|
|
78
|
+
# How the verdict names a skipped check.
|
|
79
|
+
_SHORT_NAMES: dict[Check, str] = {
|
|
80
|
+
Check.COMPARE: "the resolver comparison",
|
|
81
|
+
Check.EMAIL: "email",
|
|
82
|
+
Check.DNSSEC: "DNSSEC",
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class CheckState(StrEnum):
|
|
87
|
+
PENDING = "pending"
|
|
88
|
+
RUNNING = "running"
|
|
89
|
+
DONE = "done"
|
|
90
|
+
SKIPPED = "skipped" # --quick, or the domain doesn't exist (CheckRun.reason)
|
|
91
|
+
ERROR = "error" # the check itself crashed; its result is missing
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@dataclass(frozen=True)
|
|
95
|
+
class CheckRun:
|
|
96
|
+
check: Check
|
|
97
|
+
state: CheckState
|
|
98
|
+
elapsed_ms: float = 0.0
|
|
99
|
+
error: str | None = None
|
|
100
|
+
reason: str = "" # why it was skipped: SKIP_QUICK or SKIP_NO_DOMAIN
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class Area(StrEnum):
|
|
104
|
+
MACHINE = "machine" # this computer or its network
|
|
105
|
+
DOMAIN = "domain" # the domain's own DNS or servers
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class Impact(StrEnum):
|
|
109
|
+
CRITICAL = "critical" # something doesn't work at all
|
|
110
|
+
MAJOR = "major" # works badly, or for some people
|
|
111
|
+
MINOR = "minor" # worth tidying up
|
|
112
|
+
NOTE = "note" # good to know, nothing to fix: costs no points
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
IMPACT_PENALTY: dict[Impact, int] = {
|
|
116
|
+
Impact.CRITICAL: 40,
|
|
117
|
+
Impact.MAJOR: 15,
|
|
118
|
+
Impact.MINOR: 5,
|
|
119
|
+
Impact.NOTE: 0,
|
|
120
|
+
}
|
|
121
|
+
# One check can't take more than this off the score, so a handful of email warnings
|
|
122
|
+
# doesn't outweigh a broken website.
|
|
123
|
+
MAX_PENALTY_PER_CHECK = 40
|
|
124
|
+
_IMPACT_ORDER = list(Impact)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@dataclass(frozen=True)
|
|
128
|
+
class Issue:
|
|
129
|
+
area: Area
|
|
130
|
+
impact: Impact
|
|
131
|
+
title: str
|
|
132
|
+
detail: str
|
|
133
|
+
fix: str
|
|
134
|
+
check: Check # where it was found
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
@dataclass(frozen=True)
|
|
138
|
+
class DoctorReport:
|
|
139
|
+
name: str
|
|
140
|
+
quick: bool
|
|
141
|
+
runs: tuple[CheckRun, ...] # in Check order
|
|
142
|
+
issues: tuple[Issue, ...] # most important first
|
|
143
|
+
elapsed_ms: float
|
|
144
|
+
local: LocalReport | None = None
|
|
145
|
+
lookup: LookupReport | None = None
|
|
146
|
+
compare: CompareReport | None = None
|
|
147
|
+
reach: ReachReport | None = None
|
|
148
|
+
email: EmailReport | None = None
|
|
149
|
+
dnssec: DnssecReport | None = None
|
|
150
|
+
# NXDOMAIN, and no public resolver found the name either (or none could be asked).
|
|
151
|
+
name_missing: bool = False
|
|
152
|
+
# This computer's DNS said NXDOMAIN, but this public resolver found the name.
|
|
153
|
+
found_by: str | None = None
|
|
154
|
+
# One connection per distinct address answer in `compare`, when they differ.
|
|
155
|
+
answer_checks: tuple[ConnectAttempt, ...] = ()
|
|
156
|
+
|
|
157
|
+
@property
|
|
158
|
+
def problems(self) -> tuple[Issue, ...]:
|
|
159
|
+
"""The issues that need fixing (not notes)."""
|
|
160
|
+
return tuple(i for i in self.issues if i.impact is not Impact.NOTE)
|
|
161
|
+
|
|
162
|
+
@property
|
|
163
|
+
def machine_issues(self) -> tuple[Issue, ...]:
|
|
164
|
+
return tuple(i for i in self.issues if i.area is Area.MACHINE)
|
|
165
|
+
|
|
166
|
+
@property
|
|
167
|
+
def domain_issues(self) -> tuple[Issue, ...]:
|
|
168
|
+
return tuple(i for i in self.issues if i.area is Area.DOMAIN)
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def dns_broken_here(self) -> bool:
|
|
172
|
+
"""This computer can't use DNS at all, so the domain couldn't really be checked."""
|
|
173
|
+
return self.local is not None and self.local.has_errors
|
|
174
|
+
|
|
175
|
+
@property
|
|
176
|
+
def skipped(self) -> tuple[Check, ...]:
|
|
177
|
+
return tuple(r.check for r in self.runs if r.state is CheckState.SKIPPED)
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def quick_skipped(self) -> tuple[Check, ...]:
|
|
181
|
+
return tuple(r.check for r in self.runs if r.reason == SKIP_QUICK)
|
|
182
|
+
|
|
183
|
+
@property
|
|
184
|
+
def dnssec_via(self) -> str | None:
|
|
185
|
+
"""The public resolver DNSSEC was checked through, because this computer's strips it."""
|
|
186
|
+
if self.dnssec and self.dnssec.stripped_by and not self.dnssec.signatures_stripped:
|
|
187
|
+
return self.dnssec.nameserver
|
|
188
|
+
return None
|
|
189
|
+
|
|
190
|
+
@property
|
|
191
|
+
def score(self) -> int:
|
|
192
|
+
"""100 minus each issue's penalty, at most MAX_PENALTY_PER_CHECK per check; 0 for a
|
|
193
|
+
domain that doesn't exist."""
|
|
194
|
+
if self.name_missing:
|
|
195
|
+
return 0
|
|
196
|
+
per_check: dict[Check, int] = {}
|
|
197
|
+
for issue in self.issues:
|
|
198
|
+
per_check[issue.check] = per_check.get(issue.check, 0) + IMPACT_PENALTY[issue.impact]
|
|
199
|
+
lost = sum(min(p, MAX_PENALTY_PER_CHECK) for p in per_check.values())
|
|
200
|
+
return max(0, 100 - lost)
|
|
201
|
+
|
|
202
|
+
def failed(self, check: Check) -> bool:
|
|
203
|
+
"""Whether `check` itself failed, even when another issue explains it (say a lookup
|
|
204
|
+
that fails because of broken DNSSEC), so it isn't shown as OK."""
|
|
205
|
+
match check:
|
|
206
|
+
case Check.LOOKUP:
|
|
207
|
+
ok = (LookupStatus.OK, LookupStatus.NO_ANSWER)
|
|
208
|
+
return self.lookup is not None and not any(
|
|
209
|
+
r.status in ok for r in self.lookup.results
|
|
210
|
+
)
|
|
211
|
+
case Check.REACH:
|
|
212
|
+
return self.reach is not None and self.reach.verdict is not ReachVerdict.REACHABLE
|
|
213
|
+
case Check.EMAIL:
|
|
214
|
+
return self.email is not None and self.email.domain_status is not LookupStatus.OK
|
|
215
|
+
case Check.DNSSEC:
|
|
216
|
+
return self.dnssec is not None and self.dnssec.status is DnssecStatus.BOGUS
|
|
217
|
+
case Check.LOCAL:
|
|
218
|
+
return self.dns_broken_here
|
|
219
|
+
return False
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def healthy(self) -> bool:
|
|
223
|
+
"""No critical or major issue."""
|
|
224
|
+
return all(i.impact in (Impact.MINOR, Impact.NOTE) for i in self.issues)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
Progress = Callable[[Check, CheckState], None]
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def doctor(
|
|
231
|
+
target: str,
|
|
232
|
+
quick: bool = False,
|
|
233
|
+
timeout: float = DOCTOR_TIMEOUT_S,
|
|
234
|
+
on_progress: Progress | None = None,
|
|
235
|
+
resolvers: Sequence[tuple[str, str]] | None = None,
|
|
236
|
+
local: LocalReport | None = None,
|
|
237
|
+
) -> DoctorReport:
|
|
238
|
+
"""Check this computer and `target` (a domain or URL) and rank what's wrong.
|
|
239
|
+
|
|
240
|
+
This computer and the lookup start first; the other domain checks start when the lookup
|
|
241
|
+
shows the domain exists, or after LOOKUP_WAIT_S. A domain that doesn't exist skips them
|
|
242
|
+
(CheckState.SKIPPED, reason SKIP_NO_DOMAIN); if a slow lookup only says so after they
|
|
243
|
+
started, their results are dropped and they're reported as skipped all the same.
|
|
244
|
+
`on_progress(check, state)` is called from worker threads as each starts and finishes,
|
|
245
|
+
and for each skipped check. A check that crashes is reported as CheckState.ERROR, not
|
|
246
|
+
raised. An invalid name raises ValueError.
|
|
247
|
+
|
|
248
|
+
`resolvers` replaces the comparison's public resolvers. A `local` report (one check of
|
|
249
|
+
this computer shared by several doctor runs, as in `dnskit batch`) is used as is.
|
|
250
|
+
"""
|
|
251
|
+
name = parse_target(target)
|
|
252
|
+
notify = on_progress or (lambda check, state: None)
|
|
253
|
+
planned = [c for c in Check if not (quick and c in SLOW_CHECKS)]
|
|
254
|
+
skipped = {c: SKIP_QUICK for c in Check if c not in planned}
|
|
255
|
+
for check in Check:
|
|
256
|
+
notify(check, CheckState.SKIPPED if check in skipped else CheckState.PENDING)
|
|
257
|
+
|
|
258
|
+
jobs: dict[Check, Callable[[], Any]] = {
|
|
259
|
+
# Ghost servers are ignored anyway: probing them only waits for the dead ones.
|
|
260
|
+
Check.LOCAL: lambda: local or local_check(probe_ghosts=False),
|
|
261
|
+
Check.LOOKUP: lambda: lookup(name, timeout=timeout),
|
|
262
|
+
Check.COMPARE: lambda: _compare_and_connect(name, timeout, resolvers),
|
|
263
|
+
Check.REACH: lambda: reach(name, timeout=timeout),
|
|
264
|
+
Check.EMAIL: lambda: email_check(name, timeout=timeout),
|
|
265
|
+
Check.DNSSEC: lambda: dnssec_check(name, timeout=timeout),
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
def run(check: Check) -> tuple[Any, CheckRun]:
|
|
269
|
+
notify(check, CheckState.RUNNING)
|
|
270
|
+
begun = time.perf_counter()
|
|
271
|
+
try:
|
|
272
|
+
result, state, error = jobs[check](), CheckState.DONE, None
|
|
273
|
+
except Exception as exc: # one broken check mustn't sink the whole report
|
|
274
|
+
result, state, error = None, CheckState.ERROR, str(exc) or type(exc).__name__
|
|
275
|
+
notify(check, state)
|
|
276
|
+
return result, CheckRun(check, state, (time.perf_counter() - begun) * 1000, error)
|
|
277
|
+
|
|
278
|
+
start = time.perf_counter()
|
|
279
|
+
with ThreadPoolExecutor(max_workers=len(planned)) as pool:
|
|
280
|
+
futures = {Check.LOCAL: pool.submit(run, Check.LOCAL)}
|
|
281
|
+
# Pick the system nameserver once, so the domain checks share the cached choice
|
|
282
|
+
# instead of each probing every server at the same time.
|
|
283
|
+
_warm_resolver_choice()
|
|
284
|
+
futures[Check.LOOKUP] = pool.submit(run, Check.LOOKUP)
|
|
285
|
+
try:
|
|
286
|
+
looked_up = futures[Check.LOOKUP].result(timeout=LOOKUP_WAIT_S)[0]
|
|
287
|
+
missing, found_by = _confirm_missing(looked_up, timeout)
|
|
288
|
+
decided = True
|
|
289
|
+
except FuturesTimeout:
|
|
290
|
+
missing, found_by, decided = False, None, False
|
|
291
|
+
for check in planned:
|
|
292
|
+
if check in futures:
|
|
293
|
+
continue
|
|
294
|
+
if missing and check in NEEDS_DOMAIN:
|
|
295
|
+
skipped[check] = SKIP_NO_DOMAIN
|
|
296
|
+
notify(check, CheckState.SKIPPED)
|
|
297
|
+
else:
|
|
298
|
+
futures[check] = pool.submit(run, check)
|
|
299
|
+
done = {check: future.result() for check, future in futures.items()}
|
|
300
|
+
|
|
301
|
+
if not decided:
|
|
302
|
+
missing, found_by = _confirm_missing(done[Check.LOOKUP][0], timeout)
|
|
303
|
+
if missing:
|
|
304
|
+
for check in NEEDS_DOMAIN:
|
|
305
|
+
if done.pop(check, None) is not None:
|
|
306
|
+
skipped[check] = SKIP_NO_DOMAIN
|
|
307
|
+
notify(check, CheckState.SKIPPED)
|
|
308
|
+
results = {check: result for check, (result, _) in done.items()}
|
|
309
|
+
runs = tuple(
|
|
310
|
+
done[c][1] if c in done else CheckRun(c, CheckState.SKIPPED, reason=skipped[c])
|
|
311
|
+
for c in Check
|
|
312
|
+
)
|
|
313
|
+
compared, answer_checks = results.get(Check.COMPARE) or (None, ())
|
|
314
|
+
report = DoctorReport(
|
|
315
|
+
name=name,
|
|
316
|
+
quick=quick,
|
|
317
|
+
runs=runs,
|
|
318
|
+
issues=(),
|
|
319
|
+
elapsed_ms=(time.perf_counter() - start) * 1000,
|
|
320
|
+
local=results.get(Check.LOCAL),
|
|
321
|
+
lookup=results.get(Check.LOOKUP),
|
|
322
|
+
compare=compared,
|
|
323
|
+
reach=results.get(Check.REACH),
|
|
324
|
+
email=results.get(Check.EMAIL),
|
|
325
|
+
dnssec=results.get(Check.DNSSEC),
|
|
326
|
+
name_missing=missing,
|
|
327
|
+
found_by=found_by,
|
|
328
|
+
answer_checks=answer_checks,
|
|
329
|
+
)
|
|
330
|
+
return replace(report, issues=find_issues(report, timeout))
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
_ANSWERED = (LookupStatus.OK, LookupStatus.NO_ANSWER)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _confirm_missing(report: LookupReport | None, timeout: float) -> tuple[bool, str | None]:
|
|
337
|
+
"""Whether the name doesn't exist, and the public resolver that found it if this
|
|
338
|
+
computer's DNS server wrongly says it doesn't (a filter, or a stale cached answer)."""
|
|
339
|
+
if report is None:
|
|
340
|
+
return False, None
|
|
341
|
+
statuses = {r.status for r in report.results}
|
|
342
|
+
if LookupStatus.NXDOMAIN not in statuses or statuses & set(_ANSWERED):
|
|
343
|
+
return False, None
|
|
344
|
+
for server in FALLBACK_RESOLVERS:
|
|
345
|
+
status = lookup(report.name, ("A",), nameserver=server, timeout=timeout).results[0].status
|
|
346
|
+
if status in _ANSWERED:
|
|
347
|
+
return False, server
|
|
348
|
+
if status is LookupStatus.NXDOMAIN:
|
|
349
|
+
return True, None
|
|
350
|
+
return True, None # no public resolver could be asked: trust this computer's answer
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def _compare_and_connect(
|
|
354
|
+
name: str, timeout: float, resolvers: Sequence[tuple[str, str]] | None = None
|
|
355
|
+
) -> tuple[CompareReport, tuple[ConnectAttempt, ...]]:
|
|
356
|
+
"""`compare`, then a connection to each different address answer, to see they all work."""
|
|
357
|
+
report = compare(name, "A", resolvers=resolvers)
|
|
358
|
+
addresses = [_first_address(a.result) for a in _distinct_address_answers(report)]
|
|
359
|
+
if len(addresses) < 2:
|
|
360
|
+
return report, ()
|
|
361
|
+
connect_timeout = min(timeout, ANSWER_CONNECT_TIMEOUT_S)
|
|
362
|
+
with ThreadPoolExecutor(max_workers=len(addresses)) as pool:
|
|
363
|
+
attempts = pool.map(lambda a: tcp_connect(a, DEFAULT_PORT, connect_timeout), addresses)
|
|
364
|
+
return report, tuple(attempts)
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _warm_resolver_choice() -> None:
|
|
368
|
+
try:
|
|
369
|
+
candidates = system_nameservers()
|
|
370
|
+
if candidates:
|
|
371
|
+
choose_nameserver(candidates)
|
|
372
|
+
except Exception: # the checks themselves will report what's wrong
|
|
373
|
+
pass
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
# --- issues ---------------------------------------------------------------------------------
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def find_issues(report: DoctorReport, timeout: float = DOCTOR_TIMEOUT_S) -> tuple[Issue, ...]:
|
|
380
|
+
"""Every issue in `report`'s results, most important first (this computer first on ties)."""
|
|
381
|
+
issues: list[Issue] = []
|
|
382
|
+
if report.local is not None:
|
|
383
|
+
issues += [_local_issue(p) for p in report.local.problems]
|
|
384
|
+
broken_here = report.dns_broken_here
|
|
385
|
+
name_fails = False # the name itself doesn't resolve: later checks would only repeat it
|
|
386
|
+
# Validating resolvers fail a domain whose DNSSEC is broken: that issue explains it.
|
|
387
|
+
bogus = report.dnssec is not None and report.dnssec.status is DnssecStatus.BOGUS
|
|
388
|
+
if report.found_by is not None and report.lookup is not None:
|
|
389
|
+
issues.append(_missing_here_issue(report.name, report.lookup.nameserver, report.found_by))
|
|
390
|
+
name_fails = True # through this computer's DNS: its issue explains everything else
|
|
391
|
+
elif report.lookup is not None:
|
|
392
|
+
found, name_fails = _lookup_issues(report.lookup, broken_here, bogus, timeout)
|
|
393
|
+
issues += found
|
|
394
|
+
if report.reach is not None:
|
|
395
|
+
issues += _reach_issues(report.reach, name_fails, broken_here)
|
|
396
|
+
if report.compare is not None and not name_fails:
|
|
397
|
+
issues += _compare_issues(report.compare, report.answer_checks, bogus)
|
|
398
|
+
# When the name doesn't resolve, email's "couldn't check" findings only repeat that.
|
|
399
|
+
if report.email is not None and not broken_here and not name_fails:
|
|
400
|
+
issues += _email_issues(report.email)
|
|
401
|
+
if report.dnssec is not None and not broken_here:
|
|
402
|
+
issues += _dnssec_issues(report.dnssec, name_fails)
|
|
403
|
+
for run in report.runs:
|
|
404
|
+
if run.state is CheckState.ERROR:
|
|
405
|
+
issues.append(
|
|
406
|
+
Issue(
|
|
407
|
+
Area.MACHINE,
|
|
408
|
+
Impact.MINOR,
|
|
409
|
+
f"The {run.check.value} check couldn't run",
|
|
410
|
+
f"It stopped with an error: {run.error}.",
|
|
411
|
+
f"Run dnskit {run.check.value} {report.name} on its own to see more.",
|
|
412
|
+
run.check,
|
|
413
|
+
)
|
|
414
|
+
)
|
|
415
|
+
order = {issue: n for n, issue in enumerate(issues)}
|
|
416
|
+
return tuple(
|
|
417
|
+
sorted(
|
|
418
|
+
issues,
|
|
419
|
+
key=lambda i: (_IMPACT_ORDER.index(i.impact), i.area is not Area.MACHINE, order[i]),
|
|
420
|
+
)
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
_LOCAL_IMPACT: dict[ProblemKind, Impact] = {
|
|
425
|
+
ProblemKind.NO_ADAPTER: Impact.CRITICAL,
|
|
426
|
+
ProblemKind.NO_DNS_SERVERS: Impact.CRITICAL,
|
|
427
|
+
ProblemKind.NO_RESPONSE: Impact.CRITICAL,
|
|
428
|
+
ProblemKind.HIJACK: Impact.MAJOR,
|
|
429
|
+
ProblemKind.INTERCEPTION: Impact.MAJOR,
|
|
430
|
+
ProblemKind.IPV6_BROKEN: Impact.MAJOR,
|
|
431
|
+
ProblemKind.SERVER_FAILED: Impact.MAJOR,
|
|
432
|
+
# dnskit and the OS already work around these; the user needn't change anything.
|
|
433
|
+
ProblemKind.GHOST: Impact.NOTE,
|
|
434
|
+
ProblemKind.VPN_BLOCKED: Impact.NOTE,
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
def _local_issue(problem: Problem) -> Issue:
|
|
439
|
+
impact = _LOCAL_IMPACT.get(problem.kind, Impact.MINOR)
|
|
440
|
+
if problem.severity is Severity.ERROR:
|
|
441
|
+
impact = Impact.CRITICAL
|
|
442
|
+
return Issue(Area.MACHINE, impact, problem.title, problem.detail, problem.fix, Check.LOCAL)
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
# Lookup failures that mean "couldn't ask", as opposed to an answer about the domain.
|
|
446
|
+
_UNREACHABLE = {LookupStatus.TIMEOUT, LookupStatus.NO_NETWORK, LookupStatus.NO_NAMESERVERS}
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
def _lookup_issues(
|
|
450
|
+
report: LookupReport, broken_here: bool, bogus: bool, timeout: float
|
|
451
|
+
) -> tuple[list[Issue], bool]:
|
|
452
|
+
"""Issues from the record lookups, and whether the name itself fails to resolve."""
|
|
453
|
+
name = report.name
|
|
454
|
+
statuses = [r.status for r in report.results]
|
|
455
|
+
answered = [s for s in statuses if s in (LookupStatus.OK, LookupStatus.NO_ANSWER)]
|
|
456
|
+
if answered:
|
|
457
|
+
failed = [
|
|
458
|
+
r for r in report.results if r.status not in (LookupStatus.OK, LookupStatus.NO_ANSWER)
|
|
459
|
+
]
|
|
460
|
+
if not failed or broken_here:
|
|
461
|
+
return [], False
|
|
462
|
+
types = ", ".join(f"{r.rtype} ({r.status.value.replace('_', ' ')})" for r in failed)
|
|
463
|
+
return [
|
|
464
|
+
Issue(
|
|
465
|
+
Area.DOMAIN,
|
|
466
|
+
Impact.MINOR,
|
|
467
|
+
"Some record lookups failed",
|
|
468
|
+
f"{name} answers, but these lookups failed: {types}.",
|
|
469
|
+
f"Run dnskit lookup {name} again; if the same types keep failing, check them "
|
|
470
|
+
"with the domain's DNS host.",
|
|
471
|
+
Check.LOOKUP,
|
|
472
|
+
)
|
|
473
|
+
], False
|
|
474
|
+
|
|
475
|
+
# Nothing answered: the name doesn't resolve at all.
|
|
476
|
+
status = statuses[0] if len(set(statuses)) == 1 else _worst_failure(statuses)
|
|
477
|
+
if status in _UNREACHABLE and broken_here:
|
|
478
|
+
return [], True # this computer's DNS is the problem, already reported
|
|
479
|
+
if bogus and status is not LookupStatus.NXDOMAIN:
|
|
480
|
+
return [], True # the DNSSEC issue says why resolvers fail it
|
|
481
|
+
diagnosis = explain(status, name, "A", timeout)
|
|
482
|
+
assert diagnosis is not None
|
|
483
|
+
return [
|
|
484
|
+
Issue(
|
|
485
|
+
Area.DOMAIN,
|
|
486
|
+
Impact.CRITICAL,
|
|
487
|
+
f"{name}: {_lower_first(diagnosis.title)}",
|
|
488
|
+
diagnosis.explanation,
|
|
489
|
+
diagnosis.suggestion,
|
|
490
|
+
Check.LOOKUP,
|
|
491
|
+
)
|
|
492
|
+
], True
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
def _worst_failure(statuses: list[LookupStatus]) -> LookupStatus:
|
|
496
|
+
for status in (LookupStatus.NXDOMAIN, LookupStatus.SERVFAIL, LookupStatus.TIMEOUT):
|
|
497
|
+
if status in statuses:
|
|
498
|
+
return status
|
|
499
|
+
return statuses[0]
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def _reach_issues(report: ReachReport, name_fails: bool, broken_here: bool) -> list[Issue]:
|
|
503
|
+
issues: list[Issue] = []
|
|
504
|
+
if report.hosts_entries:
|
|
505
|
+
pointed = ", ".join(f"{e.ip} (line {e.line})" for e in report.hosts_entries)
|
|
506
|
+
issues.append(
|
|
507
|
+
Issue(
|
|
508
|
+
Area.MACHINE,
|
|
509
|
+
Impact.MAJOR,
|
|
510
|
+
f"This computer's hosts file overrides {report.name}",
|
|
511
|
+
f"The hosts file points {report.name} at {pointed}, so browsers and most apps "
|
|
512
|
+
"on this computer go there instead of where DNS says.",
|
|
513
|
+
"If that's not intended, remove or comment out the line (needs administrator "
|
|
514
|
+
"rights), then flush the DNS cache.",
|
|
515
|
+
Check.REACH,
|
|
516
|
+
)
|
|
517
|
+
)
|
|
518
|
+
verdict = report.verdict
|
|
519
|
+
if verdict is ReachVerdict.REACHABLE:
|
|
520
|
+
return issues
|
|
521
|
+
if verdict is ReachVerdict.DNS and not report.blocked_by_dns and (name_fails or broken_here):
|
|
522
|
+
return issues # the lookup issue (or this computer's) already says it
|
|
523
|
+
diagnosis = explain_reach(report)
|
|
524
|
+
area = Area.MACHINE if report.blocked_by_dns else Area.DOMAIN
|
|
525
|
+
issues.append(
|
|
526
|
+
Issue(
|
|
527
|
+
area,
|
|
528
|
+
Impact.MAJOR,
|
|
529
|
+
diagnosis.title,
|
|
530
|
+
diagnosis.explanation,
|
|
531
|
+
diagnosis.suggestion,
|
|
532
|
+
Check.REACH,
|
|
533
|
+
)
|
|
534
|
+
)
|
|
535
|
+
return issues
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def _missing_here_issue(name: str, server: str, found_by: str) -> Issue:
|
|
539
|
+
return Issue(
|
|
540
|
+
Area.MACHINE,
|
|
541
|
+
Impact.MAJOR,
|
|
542
|
+
f"This computer's DNS server says {name} doesn't exist, but public resolvers find it",
|
|
543
|
+
f"{server} answered that {name} doesn't exist (NXDOMAIN), while {found_by} found it. "
|
|
544
|
+
"The DNS server is probably blocking it (an ad blocker, parental controls or a "
|
|
545
|
+
'company filter), or still has an old "doesn\'t exist" answer cached from before '
|
|
546
|
+
"the domain was set up. The domain checks were done through this computer's DNS, so "
|
|
547
|
+
"they couldn't see it either.",
|
|
548
|
+
"If the site should be allowed, ask whoever runs the filter to unblock it. Otherwise "
|
|
549
|
+
"flush the DNS cache (dnskit local shows how) and restart the router, or use 1.1.1.1 "
|
|
550
|
+
"or 8.8.8.8 as the DNS server.",
|
|
551
|
+
Check.LOOKUP,
|
|
552
|
+
)
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
# Answers that mean "can't find it" or "can't answer", against resolvers that give addresses.
|
|
556
|
+
_NOT_FOUND = (LookupStatus.NXDOMAIN, LookupStatus.NO_ANSWER)
|
|
557
|
+
_ERRORS = (LookupStatus.SERVFAIL, LookupStatus.NO_NAMESERVERS)
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
def _compare_issues(
|
|
561
|
+
report: CompareReport, attempts: tuple[ConnectAttempt, ...], bogus: bool
|
|
562
|
+
) -> list[Issue]:
|
|
563
|
+
"""Different answers only matter when some resolvers can't find the name (or fail) while
|
|
564
|
+
others answer, or when an answer's address doesn't work. Different working addresses are
|
|
565
|
+
normal for a CDN, so they're a note. Timeouts aren't counted: a VPN or firewall blocking
|
|
566
|
+
the public resolvers is `local`'s business."""
|
|
567
|
+
name = report.name
|
|
568
|
+
answering = [a for a in report.responded if a.result.status is LookupStatus.OK]
|
|
569
|
+
odd = [a for a in report.responded if a.result.status in _NOT_FOUND]
|
|
570
|
+
odd += [a for a in report.failed if a.result.status in _ERRORS]
|
|
571
|
+
if answering and odd:
|
|
572
|
+
if bogus and all(a.result.status is LookupStatus.SERVFAIL for a in odd):
|
|
573
|
+
return [] # validating resolvers failing a broken DNSSEC domain: that issue says so
|
|
574
|
+
mine = all(_is_system(a) for a in odd)
|
|
575
|
+
listed = ", ".join(f"{a.label} ({_answer_text(a.result)})" for a in odd)
|
|
576
|
+
counted = f"{len(answering)} resolver{'s' if len(answering) > 1 else ''}"
|
|
577
|
+
detail = f"{counted} answered with an address, but {listed}."
|
|
578
|
+
if mine:
|
|
579
|
+
return [
|
|
580
|
+
Issue(
|
|
581
|
+
Area.MACHINE,
|
|
582
|
+
Impact.MAJOR,
|
|
583
|
+
f"This computer's DNS server can't find {name}, but public resolvers can",
|
|
584
|
+
f"{detail} The DNS server is probably filtering this name, or has an old "
|
|
585
|
+
"answer cached.",
|
|
586
|
+
"If the site should be allowed, ask whoever runs the filter to unblock it. "
|
|
587
|
+
"Otherwise flush the DNS cache and restart the router, or use 1.1.1.1 or "
|
|
588
|
+
"8.8.8.8 as the DNS server.",
|
|
589
|
+
Check.COMPARE,
|
|
590
|
+
)
|
|
591
|
+
]
|
|
592
|
+
return [
|
|
593
|
+
Issue(
|
|
594
|
+
Area.DOMAIN,
|
|
595
|
+
Impact.MAJOR,
|
|
596
|
+
f"Some resolvers can't find {name}",
|
|
597
|
+
f"{detail} So some people can't reach it. Usually one of the domain's "
|
|
598
|
+
"nameservers is out of date or not serving it, or the record was created "
|
|
599
|
+
"moments ago and some resolvers still remember that it didn't exist.",
|
|
600
|
+
f"Run dnskit trace {name} a few times to find a nameserver that fails, and "
|
|
601
|
+
"check that every nameserver at the DNS host has the record.",
|
|
602
|
+
Check.COMPARE,
|
|
603
|
+
)
|
|
604
|
+
]
|
|
605
|
+
|
|
606
|
+
distinct = _distinct_address_answers(report)
|
|
607
|
+
if len(distinct) < 2:
|
|
608
|
+
return []
|
|
609
|
+
by_address = {a.address: a for a in attempts}
|
|
610
|
+
tried = [(a, by_address.get(_first_address(a.result))) for a in distinct]
|
|
611
|
+
works = [a for a, attempt in tried if attempt is not None and attempt.ok]
|
|
612
|
+
dead = [(a, attempt) for a, attempt in tried if attempt is not None and not attempt.ok]
|
|
613
|
+
if works and dead:
|
|
614
|
+
# Every resolver that gave the same answer as a dead one is affected.
|
|
615
|
+
dead_keys = {_answer_key(a.result) for a, _ in dead}
|
|
616
|
+
affected = [a for a in answering if _answer_key(a.result) in dead_keys]
|
|
617
|
+
listed = ", ".join(
|
|
618
|
+
f"{a.label} ({_first_address(a.result)}: {attempt.error or 'failed'})"
|
|
619
|
+
for a, attempt in dead
|
|
620
|
+
)
|
|
621
|
+
mine = all(_is_system(a) for a in affected)
|
|
622
|
+
fix = (
|
|
623
|
+
"This computer's DNS server has an address that doesn't work: flush the DNS cache "
|
|
624
|
+
"and restart the router, or use 1.1.1.1 or 8.8.8.8 as the DNS server."
|
|
625
|
+
if mine
|
|
626
|
+
else "If you moved the site recently, the old address is still cached: keep the "
|
|
627
|
+
"old server running until the record's TTL has passed. Otherwise check the "
|
|
628
|
+
"addresses at the DNS host."
|
|
629
|
+
)
|
|
630
|
+
return [
|
|
631
|
+
Issue(
|
|
632
|
+
Area.MACHINE if mine else Area.DOMAIN,
|
|
633
|
+
Impact.MAJOR,
|
|
634
|
+
f"Some resolvers send visitors of {name} to an address that doesn't respond",
|
|
635
|
+
f"Resolvers give different addresses for {name}, and not all of them work on "
|
|
636
|
+
f"port {DEFAULT_PORT}: {listed}. Others answered with addresses that do.",
|
|
637
|
+
fix,
|
|
638
|
+
Check.COMPARE,
|
|
639
|
+
)
|
|
640
|
+
]
|
|
641
|
+
return [
|
|
642
|
+
Issue(
|
|
643
|
+
Area.DOMAIN,
|
|
644
|
+
Impact.NOTE,
|
|
645
|
+
f"Resolvers give different addresses for {name}",
|
|
646
|
+
"Every resolver answered, with addresses that work. That's normal for a site on a "
|
|
647
|
+
"CDN, which gives each resolver servers near it.",
|
|
648
|
+
"Nothing to do.",
|
|
649
|
+
Check.COMPARE,
|
|
650
|
+
)
|
|
651
|
+
]
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
def _is_system(answer: ResolverAnswer) -> bool:
|
|
655
|
+
"""One of this computer's DNS servers that isn't also a public resolver."""
|
|
656
|
+
return answer.label.startswith("System #")
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
def _answer_key(result: LookupResult) -> frozenset[str]:
|
|
660
|
+
return frozenset(r.value.lower() for r in result.records)
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
def _distinct_address_answers(report: CompareReport) -> list[ResolverAnswer]:
|
|
664
|
+
"""One resolver per different address answer, in the report's order."""
|
|
665
|
+
seen: dict[frozenset[str], ResolverAnswer] = {}
|
|
666
|
+
for answer in report.responded:
|
|
667
|
+
if answer.result.status is LookupStatus.OK and answer.result.records:
|
|
668
|
+
seen.setdefault(_answer_key(answer.result), answer)
|
|
669
|
+
return list(seen.values())
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def _first_address(result: LookupResult) -> str:
|
|
673
|
+
return min(r.value for r in result.records)
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
def _answer_text(result: LookupResult) -> str:
|
|
677
|
+
if result.status is LookupStatus.OK:
|
|
678
|
+
return ", ".join(r.value for r in result.records)
|
|
679
|
+
return {
|
|
680
|
+
LookupStatus.NXDOMAIN: "it doesn't exist",
|
|
681
|
+
LookupStatus.NO_ANSWER: "no address",
|
|
682
|
+
LookupStatus.SERVFAIL: "server failure",
|
|
683
|
+
LookupStatus.NO_NAMESERVERS: "refused",
|
|
684
|
+
}.get(result.status, result.status.value)
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
def _email_issues(report: EmailReport) -> list[Issue]:
|
|
688
|
+
if report.domain_status is not LookupStatus.OK:
|
|
689
|
+
return [] # the lookup issue already says the name doesn't resolve
|
|
690
|
+
no_mail = report.mx is not None and report.mx.lookup_status is LookupStatus.NO_ANSWER
|
|
691
|
+
# DNS can't list a domain's DKIM selectors, so none at the common ones proves nothing.
|
|
692
|
+
no_dkim_found = report.dkim is not None and not any(s.found for s in report.dkim.selectors)
|
|
693
|
+
issues = []
|
|
694
|
+
for label, section in report.checks:
|
|
695
|
+
for finding in section.findings:
|
|
696
|
+
if finding.status is CheckStatus.PASS:
|
|
697
|
+
continue
|
|
698
|
+
impact = Impact.MAJOR if finding.status is CheckStatus.FAIL else Impact.MINOR
|
|
699
|
+
if no_mail:
|
|
700
|
+
impact = Impact.MINOR # a domain that doesn't take email
|
|
701
|
+
if label == "DKIM" and finding.status is CheckStatus.WARN and no_dkim_found:
|
|
702
|
+
impact = Impact.NOTE
|
|
703
|
+
issues.append(
|
|
704
|
+
Issue(
|
|
705
|
+
Area.DOMAIN,
|
|
706
|
+
impact,
|
|
707
|
+
f"Email ({label}): {_lower_first(finding.title)}",
|
|
708
|
+
finding.explanation,
|
|
709
|
+
finding.fix or f"Run dnskit email {report.domain} for details.",
|
|
710
|
+
Check.EMAIL,
|
|
711
|
+
)
|
|
712
|
+
)
|
|
713
|
+
return issues
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
def _dnssec_issues(report: DnssecReport, name_fails: bool) -> list[Issue]:
|
|
717
|
+
if report.signatures_stripped:
|
|
718
|
+
# This computer's DNS strips signatures and no fallback could stand in: that's about
|
|
719
|
+
# the network, not the domain.
|
|
720
|
+
return [_from_diagnosis(explain_dnssec(report), Area.MACHINE, Impact.NOTE, Check.DNSSEC)]
|
|
721
|
+
clock = clock_diagnosis(report.clock)
|
|
722
|
+
clock_wrong = report.clock.state is ClockState.WRONG
|
|
723
|
+
issues = []
|
|
724
|
+
status = report.status
|
|
725
|
+
if status is DnssecStatus.BOGUS:
|
|
726
|
+
diagnosis = explain_dnssec(report)
|
|
727
|
+
issues.append(
|
|
728
|
+
Issue(
|
|
729
|
+
Area.MACHINE if clock_wrong else Area.DOMAIN,
|
|
730
|
+
Impact.CRITICAL,
|
|
731
|
+
diagnosis.title,
|
|
732
|
+
diagnosis.explanation,
|
|
733
|
+
diagnosis.suggestion,
|
|
734
|
+
Check.DNSSEC,
|
|
735
|
+
)
|
|
736
|
+
)
|
|
737
|
+
elif clock_wrong and clock is not None:
|
|
738
|
+
issues.append(_from_diagnosis(clock, Area.MACHINE, Impact.MAJOR, Check.DNSSEC))
|
|
739
|
+
if name_fails or report.name_missing:
|
|
740
|
+
return issues # nothing of its own to protect: the lookup issue says why
|
|
741
|
+
if status is DnssecStatus.INSECURE or (
|
|
742
|
+
status is DnssecStatus.UNKNOWN and report.blocking is None
|
|
743
|
+
):
|
|
744
|
+
diagnosis = explain_dnssec(report)
|
|
745
|
+
issues.append(_from_diagnosis(diagnosis, Area.DOMAIN, Impact.MINOR, Check.DNSSEC))
|
|
746
|
+
return issues
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
def _from_diagnosis(diagnosis: Diagnosis, area: Area, impact: Impact, check: Check) -> Issue:
|
|
750
|
+
return Issue(area, impact, diagnosis.title, diagnosis.explanation, diagnosis.suggestion, check)
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
def _lower_first(text: str) -> str:
|
|
754
|
+
"""Lower-case a title's first letter to follow a prefix, unless it starts a name."""
|
|
755
|
+
if len(text) > 1 and text[1].isupper(): # e.g. "MX records", "SPF …"
|
|
756
|
+
return text
|
|
757
|
+
return text[:1].lower() + text[1:]
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
# --- verdict --------------------------------------------------------------------------------
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
def doctor_verdict(report: DoctorReport) -> Diagnosis:
|
|
764
|
+
"""A short plain-English summary of the result, with the next step."""
|
|
765
|
+
name = report.name
|
|
766
|
+
skipped = [_SHORT_NAMES.get(c, c.value) for c in report.quick_skipped]
|
|
767
|
+
listed = (
|
|
768
|
+
", ".join(skipped[:-1]) + (" and " if len(skipped) > 1 else "") + skipped[-1]
|
|
769
|
+
if skipped
|
|
770
|
+
else ""
|
|
771
|
+
)
|
|
772
|
+
quick = f" This was a quick check, so {listed} weren't checked." if skipped else ""
|
|
773
|
+
if report.name_missing:
|
|
774
|
+
nxdomain = explain(LookupStatus.NXDOMAIN, name, "A")
|
|
775
|
+
assert nxdomain is not None
|
|
776
|
+
here = [i for i in report.problems if i.area is Area.MACHINE]
|
|
777
|
+
machine = (
|
|
778
|
+
f" Separately, this computer has {len(here)} issue{'s' if len(here) > 1 else ''}."
|
|
779
|
+
if here
|
|
780
|
+
else ""
|
|
781
|
+
)
|
|
782
|
+
return Diagnosis(
|
|
783
|
+
title=f"{name} doesn't exist",
|
|
784
|
+
explanation="DNS says there's no such domain (NXDOMAIN), so it can't work for "
|
|
785
|
+
"anyone, and the checks that need it (the resolver comparison, the connection, "
|
|
786
|
+
f"email and DNSSEC) were skipped. The score is 0.{machine}",
|
|
787
|
+
suggestion=nxdomain.suggestion,
|
|
788
|
+
)
|
|
789
|
+
if report.dns_broken_here:
|
|
790
|
+
top = report.machine_issues[0]
|
|
791
|
+
return Diagnosis(
|
|
792
|
+
title="This computer can't use DNS",
|
|
793
|
+
explanation=f"{top.title}. Until DNS works here, {name} can't be checked, so "
|
|
794
|
+
"any failures for it are probably not the domain's fault." + quick,
|
|
795
|
+
suggestion=top.fix,
|
|
796
|
+
)
|
|
797
|
+
problems = report.problems
|
|
798
|
+
if not problems:
|
|
799
|
+
notes = len(report.issues)
|
|
800
|
+
noted = (
|
|
801
|
+
f" {notes} note{'' if notes == 1 else 's'} below for information; nothing needs "
|
|
802
|
+
"changing."
|
|
803
|
+
if notes
|
|
804
|
+
else ""
|
|
805
|
+
)
|
|
806
|
+
return Diagnosis(
|
|
807
|
+
title="Healthy: no problems found",
|
|
808
|
+
explanation=f"This computer's DNS setup and {name} both checked out.{noted}" + quick,
|
|
809
|
+
suggestion="Nothing to do.",
|
|
810
|
+
)
|
|
811
|
+
|
|
812
|
+
def summary(issues: tuple[Issue, ...], where: str) -> str:
|
|
813
|
+
if not issues:
|
|
814
|
+
return f"{where} looks fine."
|
|
815
|
+
count = f"{len(issues)} issue" + ("" if len(issues) == 1 else "s")
|
|
816
|
+
return f"{where} has {count}; the most important: {_lower_first(issues[0].title)}."
|
|
817
|
+
|
|
818
|
+
parts = (
|
|
819
|
+
summary(tuple(i for i in problems if i.area is Area.MACHINE), "This computer"),
|
|
820
|
+
summary(tuple(i for i in problems if i.area is Area.DOMAIN), name),
|
|
821
|
+
)
|
|
822
|
+
score = report.score
|
|
823
|
+
critical = any(i.impact is Impact.CRITICAL for i in problems)
|
|
824
|
+
if critical:
|
|
825
|
+
title = "Something is broken"
|
|
826
|
+
elif score >= 90:
|
|
827
|
+
title = "Healthy, with a few things to tidy up"
|
|
828
|
+
elif score >= 70:
|
|
829
|
+
title = "Mostly healthy, but some things need fixing"
|
|
830
|
+
else:
|
|
831
|
+
title = "Several problems need fixing"
|
|
832
|
+
return Diagnosis(
|
|
833
|
+
title=title,
|
|
834
|
+
explanation=" ".join(parts) + quick,
|
|
835
|
+
suggestion=f"Start at the top of the list: {problems[0].fix}",
|
|
836
|
+
)
|