Skip to content

Doctor

End-to-end diagnostics for a configured Moodle environment.

Composes the existing configuration, session, compatibility, and site-info building blocks into a single, read-only health report for a Moodle environment. Never mutates remote state and never surfaces raw secret values (password, webservice token, sesskey) in any check message.

Classes:

Name Description
CheckStatus

Outcome of a single diagnostic check.

CheckResult

Result of a single diagnostic check.

DoctorReport

Aggregate result of running all doctor checks for one environment.

Functions:

Name Description
run_diagnostics

Run all doctor checks for a Moodle environment.

Attributes:

Name Type Description
CRITICAL_CHECKS

Attributes

CRITICAL_CHECKS module-attribute

CRITICAL_CHECKS = frozenset(
    {"base_url", "login", "sesskey"}
)

Classes

CheckStatus

Bases: str, Enum

Outcome of a single diagnostic check.

Attributes:

Name Type Description
PASS
WARN
FAIL

Attributes

PASS class-attribute instance-attribute
PASS = 'pass'
WARN class-attribute instance-attribute
WARN = 'warn'
FAIL class-attribute instance-attribute
FAIL = 'fail'

CheckResult dataclass

CheckResult(name: str, status: CheckStatus, message: str)

Result of a single diagnostic check.

Attributes:

Name Type Description
name str

Short machine-friendly identifier (e.g. "login").

status CheckStatus

One of CheckStatus.PASS/WARN/FAIL.

message str

Human-readable detail. MUST NOT contain raw secret values (password, webservice token, sesskey).

Attributes

name instance-attribute
name: str
status instance-attribute
status: CheckStatus
message instance-attribute
message: str

DoctorReport dataclass

DoctorReport(env: str, checks: List[CheckResult] = list())

Aggregate result of running all doctor checks for one environment.

Methods:

Name Description
as_dicts

Return checks as plain dicts for JSON/YAML rendering.

Attributes:

Name Type Description
env str
checks List[CheckResult]
exit_code int

Return 1 if any check FAILed, else 0.

Attributes

env instance-attribute
env: str
checks class-attribute instance-attribute
checks: List[CheckResult] = field(default_factory=list)
exit_code property
exit_code: int

Return 1 if any check FAILed, else 0.

Methods:

as_dicts
as_dicts() -> List[dict]

Return checks as plain dicts for JSON/YAML rendering.

Functions:

run_diagnostics

run_diagnostics(env: str) -> DoctorReport

Run all doctor checks for a Moodle environment.

Parameters:

Name Type Description Default
env str

Environment key passed to load_settings/MoodleSession.get.

required

Returns:

Name Type Description
DoctorReport DoctorReport

Aggregate report. Individual checks never raise;

DoctorReport

each failure is captured as a CheckResult with status FAIL/WARN.

Raises:

Type Description
ValueError

If load_settings(env) cannot resolve required configuration (propagated so the CLI can map it to exit code 2, distinct from a failed check).