Environment diagnostics and auto-repair — returns structured results.
Define checks and use run/1 to diagnose or fix/1 to repair.
All functions return data structures — the caller decides how to display.
Check definition
config = %{
app_name: "myapp",
checks: [
%{
id: :postgresql,
name: "PostgreSQL",
description: "Database server",
priority: 1,
check: fn -> {:ok, "v14"} end,
fix: fn -> {:ok, "installed"} end,
fix_command: "sudo apt install postgresql-14"
}
]
}Each check/0 returns {:ok, msg}, {:warning, msg} or {:error, msg}.
Each fix/0 returns {:ok, msg}, {:error, msg} or :skipped.
Return values
run/1 returns {:ok, results} — all checks always return ok wrapper,
the individual status is embedded in each result map.
fix/1 returns :ok — repairs are applied silently.
summary/1 returns a map with counts and a passed? boolean.
Summary
Functions
Runs fixes for all checks with errors.
Runs a quick health check and returns a simple pass/fail map.
Runs all checks in parallel and returns structured results.
Summarizes a list of check results into a single map.
Types
@type check_def() :: %{ id: check_id(), name: String.t(), description: String.t(), priority: non_neg_integer(), check: (-> check_result()), fix: (-> fix_result()), fix_command: String.t() | nil }
@type check_id() :: atom()
@type summary() :: %{ ok: non_neg_integer(), warning: non_neg_integer(), error: non_neg_integer(), total: non_neg_integer(), passed?: boolean() }
Functions
@spec fix(config()) :: :ok
Runs fixes for all checks with errors.
Runs a quick health check and returns a simple pass/fail map.
Shorthand for run/1 + summary/1 — returns %{status: :ok | :degraded | :fail, summary: summary()}.
Examples
iex> Doctor.health_check(config)
%{status: :ok, summary: %{ok: 5, warning: 0, error: 0, total: 5, passed?: true}}
Runs all checks in parallel and returns structured results.
Summarizes a list of check results into a single map.