doctor

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package doctor ties the queue, log, config and DNS checks together. Both the CLI and the MCP server call into it.

Index

Constants

View Source
const (
	SevProblem = "problem"
	SevWarn    = "warning"
	SevInfo    = "info"
)

Severity of a finding.

Variables

This section is empty.

Functions

func CollectPlaybooks added in v0.2.1

func CollectPlaybooks(q *queue.Summary, st *maillog.Stats, only string) []provider.Hit

CollectPlaybooks matches queue delay reasons and log deferral/bounce texts against the provider playbooks. Either source may be nil.

func ConfigView

func ConfigView(all map[string]string) map[string]string

ConfigView returns the subset of postconf -n that matters for delivery.

func HumanSize added in v0.2.2

func HumanSize(n int64) string

HumanSize formats a byte count: 812 B, 36.8 KB, 4.1 MB.

func WriteDNS

func WriteDNS(w io.Writer, s Style, r dnsauth.Report)

WriteDNS prints DNS checks.

func WriteLog

func WriteLog(w io.Writer, s Style, lr LogResult)

WriteLog prints log stats.

func WriteMessage added in v0.2.2

func WriteMessage(w io.Writer, s Style, r message.Report)

WriteMessage prints one queued message: where it is, who is still waiting and why, the route it took, its authentication and its headers.

func WritePlaybook added in v0.2.1

func WritePlaybook(w io.Writer, s Style, p provider.Playbook)

WritePlaybook prints one playbook in full, without evidence.

func WritePlaybookIndex added in v0.2.1

func WritePlaybookIndex(w io.Writer, s Style)

WritePlaybookIndex lists every built-in playbook.

func WritePlaybooks added in v0.2.1

func WritePlaybooks(w io.Writer, s Style, r PlaybookResult)

WritePlaybooks prints the provider playbooks for what is failing on this server.

func WriteQueue

func WriteQueue(w io.Writer, s Style, q queue.Summary)

WriteQueue prints a queue summary.

func WriteReplyLookup added in v0.2.1

func WriteReplyLookup(w io.Writer, s Style, r ReplyLookup)

WriteReplyLookup prints the result of looking up one reply text.

func WriteReport

func WriteReport(w io.Writer, s Style, r Report)

WriteReport prints the doctor report.

func WriteShape

func WriteShape(w io.Writer, s Style, sh queue.Shape)

WriteShape prints a qshape matrix.

func WriteTrend added in v0.2.0

func WriteTrend(w io.Writer, s Style, tr TrendResult)

WriteTrend prints per-destination deferral trends.

Types

type DNSOptions

type DNSOptions struct {
	Domain    string
	IPs       []string
	Selectors []string
	HELO      string
	// SelectorsFromLog: if no selectors are given, look for opendkim signing lines in the log.
	SelectorsFromLog bool
}

DNSOptions for DNS.

type Env

type Env struct {
	Runner    postfix.Runner
	Logs      postfix.LogSource
	QueueFile string // read postqueue -j output from this file instead of running postqueue
	// MessageFile: read saved "postcat -e -h -q ID" output instead of running postcat.
	MessageFile string
	Resolver    dnsauth.Resolver
	Now         func() time.Time
}

Env is the shared runtime configuration.

func (*Env) Config

func (e *Env) Config(ctx context.Context) (map[string]string, error)

Config returns `postconf -n` (empty map when Postfix is not reachable).

func (*Env) DNS

func (e *Env) DNS(ctx context.Context, o DNSOptions) (dnsauth.Report, error)

DNS runs the authentication checks. Missing domain/IPs are filled from postconf.

func (*Env) Identity

func (e *Env) Identity(ctx context.Context) SenderIdentity

Identity derives the sending domain/IPs from postconf (best effort).

func (*Env) LogStats

func (e *Env) LogStats(ctx context.Context, window time.Duration, domain string, top int) (LogResult, error)

LogStats aggregates the log since now-window.

func (*Env) LogTrend added in v0.2.0

func (e *Env) LogTrend(ctx context.Context, window, bucketSize time.Duration, domain string, top int) (TrendResult, error)

LogTrend aggregates per-destination deferral rates over time buckets. bucketSize 0 selects an automatic width from the window.

func (*Env) Message added in v0.2.2

func (e *Env) Message(ctx context.Context, id string, redact bool) (message.Report, error)

Message reads the envelope and headers of one queued message (postcat -e -h -q ID; never the body) and joins them with its postqueue -j entry for the delay reasons. With redact (always on over MCP) local parts, display names, subjects and other free text are hidden; secret-like headers are removed either way.

func (*Env) ProviderPlaybooks added in v0.2.1

func (e *Env) ProviderPlaybooks(ctx context.Context, window time.Duration, only string) (PlaybookResult, error)

ProviderPlaybooks reads the queue and the mail log (window, 0 = all) and returns the provider playbooks for what is failing. It fails only when neither source can be read.

func (*Env) Queue

func (e *Env) Queue(ctx context.Context) ([]queue.Message, error)

Queue loads the queue.

func (*Env) Run

func (e *Env) Run(ctx context.Context, o Options) Report

Run produces a diagnosis. Individual sources may fail; their errors are recorded and the rest of the report is still produced.

func (*Env) Trace

func (e *Env) Trace(ctx context.Context, query string, window time.Duration, limit int) ([]maillog.TracedMessage, string, error)

Trace follows a queue ID or address through the log.

type Finding

type Finding struct {
	Severity string `json:"severity"`
	Area     string `json:"area"` // queue, log, dns, config
	Title    string `json:"title"`
	Detail   string `json:"detail,omitempty"`
	Next     string `json:"next_step,omitempty"`
	// Provider playbook findings (area "provider") carry the full ordered
	// steps and the provider's official references.
	Playbook   string         `json:"playbook,omitempty"`
	Steps      []string       `json:"steps,omitempty"`
	References []provider.Ref `json:"references,omitempty"`
}

Finding is one thing the operator should know.

type LogResult

type LogResult struct {
	Source string        `json:"source"`
	Since  time.Time     `json:"since"`
	Stats  maillog.Stats `json:"stats"`
}

LogResult is log statistics plus where they came from.

type Options

type Options struct {
	Window    time.Duration
	Domain    string
	IPs       []string
	Selectors []string
	SkipDNS   bool
	SkipLog   bool
	Top       int
}

Options for Run.

type PlaybookResult added in v0.2.1

type PlaybookResult struct {
	LogSource  string         `json:"log_source,omitempty"`
	Since      time.Time      `json:"since,omitempty"`
	LogError   string         `json:"log_error,omitempty"`
	QueueError string         `json:"queue_error,omitempty"`
	Provider   string         `json:"provider_filter,omitempty"`
	Playbooks  []provider.Hit `json:"playbooks"`
}

PlaybookResult is the provider playbooks that apply to this server.

type ReplyLookup added in v0.2.1

type ReplyLookup struct {
	Reply        string             `json:"reply"`
	Provider     string             `json:"provider,omitempty"`
	ProviderName string             `json:"provider_name,omitempty"`
	Code         string             `json:"code,omitempty"`
	CodeNote     string             `json:"code_note,omitempty"`
	Temporary    bool               `json:"temporary"`
	Category     string             `json:"category"`
	Hint         string             `json:"hint"`
	Playbook     *provider.Playbook `json:"playbook"`
}

ReplyLookup is the playbook lookup for one pasted reply text.

func LookupReply added in v0.2.1

func LookupReply(text, rcptDomain string) ReplyLookup

LookupReply classifies one SMTP reply or delay reason (as found in the log or in postqueue output) and finds its provider playbook. rcptDomain is an optional hint used when the reply names no host.

type Report

type Report struct {
	GeneratedAt time.Time         `json:"generated_at"`
	Identity    SenderIdentity    `json:"identity"`
	Queue       *queue.Summary    `json:"queue,omitempty"`
	QueueError  string            `json:"queue_error,omitempty"`
	Shape       *queue.Shape      `json:"shape,omitempty"`
	Log         *LogResult        `json:"log,omitempty"`
	LogError    string            `json:"log_error,omitempty"`
	Trend       *TrendResult      `json:"trend,omitempty"`
	Playbooks   []provider.Hit    `json:"provider_playbooks,omitempty"`
	DNS         *dnsauth.Report   `json:"dns,omitempty"`
	DNSError    string            `json:"dns_error,omitempty"`
	Config      map[string]string `json:"config,omitempty"`
	Findings    []Finding         `json:"findings"`
	Problems    int               `json:"problems"`
	Warnings    int               `json:"warnings"`
}

Report is the combined diagnosis.

func (Report) ExitCode

func (r Report) ExitCode() int

ExitCode is 0 when no problems were found, 1 otherwise.

type SenderIdentity

type SenderIdentity struct {
	Hostname string   `json:"myhostname"`
	Domain   string   `json:"sending_domain"`
	IPs      []string `json:"sending_ips"`
}

SenderIdentity is what Postfix presents to the world, from postconf.

type Style

type Style struct{ Color bool }

Style colours terminal output.

func (Style) Bold

func (s Style) Bold(t string) string

Bold text.

func (Style) Dim

func (s Style) Dim(t string) string

Dim text.

func (Style) Mark

func (s Style) Mark(status string) string

Mark returns a coloured status glyph.

type TrendResult added in v0.2.0

type TrendResult struct {
	Source string        `json:"source"`
	Since  time.Time     `json:"since"`
	Trend  maillog.Trend `json:"trend"`
}

TrendResult is per-destination deferral trends plus where they came from.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL