Behaviour for defining health checks.
Use this behaviour to create custom check modules with consistent structure and built-in support for Botica's health check infrastructure.
Example
defmodule MyApp.DatabaseCheck do
use Botica.Check.Behaviour
@impl true
def check_def(_opts) do
%{
id: :database,
name: "Database",
description: "Database connectivity",
priority: 1,
tags: [:database, :critical],
timeout: 5000,
check: &__MODULE__.do_check/0,
fix: &__MODULE__.do_fix/0,
fix_command: "sudo systemctl restart myapp-db"
}
end
defp do_check do
# Your check logic here
{:ok, "Database is reachable"}
end
defp do_fix do
# Your fix logic here
{:ok, "Database restarted"}
end
endThen in your config:
Botica.Doctor.run(%{
app_name: "myapp",
checks: [MyApp.DatabaseCheck.check_def([])]
})
Summary
Callbacks
Returns a check definition map for this check module.
Optional callback to validate configuration before running checks.
Functions
Macro to use this behaviour in a module.
Callbacks
@callback check_def(opts :: keyword()) :: Botica.Types.check_def()
Returns a check definition map for this check module.
Override this callback to define your check's metadata and behaviour.
Options
timeout- Override the default timeout for this check (in milliseconds)- Any other options your check implementation needs
Optional callback to validate configuration before running checks.
Return :ok if configuration is valid, or {:error, reason} if not.
The default implementation always returns :ok.