Flag hosts whose reported hostname differs from their registered name

A note on the dashboard row and host page, not a status change, so a token
copied to the wrong machine is visible. Only the first DNS label is compared,
ignoring case, since registered names are usually hostname -s and the agent
reports hostname -f.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Sonnet 5.5 committed 2026-10-29 21:17:40 -04:00
1 parent 313961d70b
commit 63ca790779
4 files changed
+49 -3

No files matched your search

+16 -1
View File
@@ -106,8 +106,19 @@ def agent_outdated(version: str | None) -> bool:
return bool(version) and _version_tuple(version) < _version_tuple(AGENT_VERSION)
def hostname_mismatch(registered: str, report: dict[str, Any]) -> str | None:
"""The hostname the agent reports, if it can't be the machine `registered` names.
Registered names are usually `hostname -s` while the agent reports `hostname -f`,
so only the first DNS label is compared, ignoring case."""
reported = report.get("reported_hostname")
if not reported or reported.split(".")[0].lower() == registered.split(".")[0].lower():
return None
return reported
def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
cfg: Config) -> Status:
cfg: Config, host: str | None = None) -> Status:
status = Status()
if received_at is None or report is None:
status.raise_to("stale", "never reported")
@@ -142,6 +153,10 @@ def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
elif apt_age / 3600 > cfg.apt_stale_after_hours:
status.raise_to("update", f"package lists {apt_age / 86400:.0f}d old; apt update not running?")
if host and (reported := hostname_mismatch(host, report)):
status.note(f"registered as {host} but reports itself as {reported}; "
"token on the wrong machine?")
if agent_outdated(report.get("agent_version")):
status.note(f"agent {report['agent_version']} is older than {AGENT_VERSION}; "
"run agent/deploy.sh")