maillog

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: 12 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 maillog parses Postfix syslog / journald / maillog_file lines and aggregates delivery outcomes per domain.

Index

Constants

View Source
const (
	DirectionImproving    = "improving"
	DirectionWorsening    = "worsening"
	DirectionFlat         = "flat"
	DirectionInsufficient = "insufficient_data"
)

Trend direction labels for early-vs-late deferral rate comparison.

Variables

This section is empty.

Functions

func AutoBucketSize added in v0.2.0

func AutoBucketSize(span time.Duration) time.Duration

AutoBucketSize chooses a bucket width from the span of the analysis window.

func Direction added in v0.2.0

func Direction(earlySent, earlyDef, lateSent, lateDef, minAttempts int) string

Direction compares early vs late half deferral rates. Needs at least minAttempts delivery attempts (sent+deferred) in each half.

func FormatBucketSize added in v0.2.0

func FormatBucketSize(d time.Duration) string

FormatBucketSize returns a short label for a duration (15m, 1h, 4h, 1d, …).

func OpenFile

func OpenFile(path string) (io.ReadCloser, error)

OpenFile opens a log file, transparently decompressing .gz. "-" is stdin.

func Scan

func Scan(r io.Reader, now, since time.Time, fn func(Event), dkim func(DKIMSignature)) error

Scan reads r line by line, calling fn for every Postfix event whose time is at or after since (zero since = everything). DKIM signature lines are passed to dkim if non-nil.

Types

type Aggregator

type Aggregator struct {
	Domain string // optional recipient-domain filter (suffix with leading ".")
	// contains filtered or unexported fields
}

Aggregator accumulates events into Stats.

func NewAggregator

func NewAggregator(domain string) *Aggregator

NewAggregator returns an empty aggregator.

func (*Aggregator) Add

func (a *Aggregator) Add(ev Event)

Add consumes one event.

func (*Aggregator) AddDKIM

func (a *Aggregator) AddDKIM(d DKIMSignature)

AddDKIM records a signing selector.

func (*Aggregator) Result

func (a *Aggregator) Result(top int) Stats

Result returns the aggregated stats; top limits list lengths (0 = all).

type Bucket added in v0.2.0

type Bucket struct {
	Start    time.Time `json:"start"`
	End      time.Time `json:"end"`
	Sent     int       `json:"sent"`
	Deferred int       `json:"deferred_attempts"`
	Bounced  int       `json:"bounced"`
	Rate     float64   `json:"deferral_rate"` // deferred / (sent+deferred); 0 when none
}

Bucket is one time slice of delivery outcomes for a domain.

type DKIMSeen

type DKIMSeen struct {
	Selector string `json:"selector"`
	Domain   string `json:"domain"`
	Count    int    `json:"count"`
}

DKIMSeen is a selector observed in opendkim/rspamd signing log lines.

type DKIMSignature

type DKIMSignature struct {
	Selector string
	Domain   string
}

DKIMSignature is an "opendkim: ID: DKIM-Signature field added (s=sel, d=dom)" line.

type DomainStat

type DomainStat struct {
	Domain     string    `json:"domain"`
	Sent       int       `json:"sent"`
	Deferred   int       `json:"deferred_attempts"`
	Bounced    int       `json:"bounced"`
	LastStatus string    `json:"last_status"`
	LastDetail string    `json:"last_detail,omitempty"`
	LastTime   time.Time `json:"last_time"`
}

DomainStat counts delivery outcomes for one recipient domain.

type DomainTrend added in v0.2.0

type DomainTrend struct {
	Domain    string   `json:"domain"`
	Sent      int      `json:"sent"`
	Deferred  int      `json:"deferred_attempts"`
	Bounced   int      `json:"bounced"`
	Rate      float64  `json:"deferral_rate"`
	Direction string   `json:"direction"`
	EarlyRate float64  `json:"early_rate"`
	LateRate  float64  `json:"late_rate"`
	Buckets   []Bucket `json:"buckets"`
}

DomainTrend is the per-destination trend over the window.

type Event

type Event struct {
	Time    time.Time         `json:"time"`
	Host    string            `json:"host,omitempty"`
	Program string            `json:"program"` // e.g. postfix/smtp
	QueueID string            `json:"queue_id,omitempty"`
	Fields  map[string]string `json:"fields,omitempty"`
	Status  string            `json:"status,omitempty"` // sent, deferred, bounced, expired, ...
	Detail  string            `json:"detail,omitempty"` // text after status=xxx, without parentheses
	Reject  bool              `json:"reject,omitempty"` // NOQUEUE: reject / milter-reject
	Raw     string            `json:"raw"`
}

Event is one parsed Postfix log line.

func ParseLine

func ParseLine(line string, now time.Time) (Event, bool)

ParseLine parses a single line. ok is false for non-Postfix lines.

type ReasonStat

type ReasonStat struct {
	Reason   string   `json:"reason"`
	Category string   `json:"category"`
	Hint     string   `json:"hint"`
	Count    int      `json:"count"`
	Domains  []string `json:"domains,omitempty"`
	Remotes  []string `json:"remote_hosts,omitempty"`
	Example  string   `json:"example"`
	// Provider is gmail, microsoft or yahoo when the reply came from one of
	// them; Playbook is the id of the matching provider playbook, if any
	// (postsleuth playbook ID).
	Provider string `json:"provider,omitempty"`
	Playbook string `json:"playbook,omitempty"`
}

ReasonStat groups failure texts.

type Source

type Source struct {
	Name string
	R    io.Reader
}

Source is something we can read lines from.

type Stats

type Stats struct {
	First        time.Time    `json:"first_event,omitempty"`
	Last         time.Time    `json:"last_event,omitempty"`
	Events       int          `json:"postfix_lines"`
	Totals       Totals       `json:"totals"`
	Domains      []DomainStat `json:"domains"`
	StillFailing []DomainStat `json:"still_failing"`
	Deferrals    []ReasonStat `json:"deferral_reasons"`
	Bounces      []ReasonStat `json:"bounce_causes"`
	Rejects      []ReasonStat `json:"smtpd_rejects"`
	DKIM         []DKIMSeen   `json:"dkim_selectors_seen,omitempty"`
}

Stats is the result of aggregating a log.

func (Stats) Top added in v0.2.1

func (s Stats) Top(n int) Stats

Top returns a copy with every list cut to at most n entries (0 = all).

type Totals

type Totals struct {
	Received int `json:"received"`
	Sent     int `json:"sent"`
	Deferred int `json:"deferred_attempts"`
	Bounced  int `json:"bounced"`
	Expired  int `json:"expired"`
	Rejected int `json:"rejected"`
}

Totals counts outcomes.

type Trace

type Trace struct {
	Query string
	// contains filtered or unexported fields
}

Trace collects every event for queue IDs matching a query (a queue ID or an email address, matched against to=, orig_to= and from=).

func NewTrace

func NewTrace(query string) *Trace

NewTrace starts a trace.

func (*Trace) Add

func (t *Trace) Add(ev Event)

Add consumes one event.

func (*Trace) Result

func (t *Trace) Result(limit int) []TracedMessage

Result returns timelines for matching queue IDs (at most limit, newest last).

type TracedMessage

type TracedMessage struct {
	QueueID     string   `json:"queue_id"`
	BounceOf    string   `json:"bounce_of,omitempty"`
	FinalStatus string   `json:"final_status"`
	Events      []string `json:"lines"`
}

TracedMessage is the timeline of one queue ID.

type Trend added in v0.2.0

type Trend struct {
	First      time.Time     `json:"first_event,omitempty"`
	Last       time.Time     `json:"last_event,omitempty"`
	BucketSize time.Duration `json:"bucket_size_ns"`
	Bucket     string        `json:"bucket"` // human label, e.g. "1h"
	Domains    []DomainTrend `json:"domains"`
}

Trend is the result of bucketing delivery outcomes by recipient domain.

type TrendAggregator added in v0.2.0

type TrendAggregator struct {
	Domain     string // optional recipient-domain filter
	BucketSize time.Duration
	// WindowStart/End bound empty buckets and the early/late split.
	// Zero means derive from observed events.
	WindowStart time.Time
	WindowEnd   time.Time
	// contains filtered or unexported fields
}

TrendAggregator accumulates timed sent/deferred/bounced events into buckets.

func NewTrendAggregator added in v0.2.0

func NewTrendAggregator(domain string, bucketSize time.Duration) *TrendAggregator

NewTrendAggregator returns an empty aggregator. bucketSize 0 means auto-size from the observed (or window) span when Result is called.

func (*TrendAggregator) Add added in v0.2.0

func (a *TrendAggregator) Add(ev Event)

Add consumes one event (only sent/delivered/deferred/bounced with a recipient).

func (*TrendAggregator) Result added in v0.2.0

func (a *TrendAggregator) Result(top int) Trend

Result finalizes buckets. top limits domains (0 = all).

Jump to

Keyboard shortcuts

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