Documentation
¶
Overview ¶
Package maillog parses Postfix syslog / journald / maillog_file lines and aggregates delivery outcomes per domain.
Index ¶
- Constants
- func AutoBucketSize(span time.Duration) time.Duration
- func Direction(earlySent, earlyDef, lateSent, lateDef, minAttempts int) string
- func FormatBucketSize(d time.Duration) string
- func OpenFile(path string) (io.ReadCloser, error)
- func Scan(r io.Reader, now, since time.Time, fn func(Event), dkim func(DKIMSignature)) error
- type Aggregator
- type Bucket
- type DKIMSeen
- type DKIMSignature
- type DomainStat
- type DomainTrend
- type Event
- type ReasonStat
- type Source
- type Stats
- type Totals
- type Trace
- type TracedMessage
- type Trend
- type TrendAggregator
Constants ¶
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
AutoBucketSize chooses a bucket width from the span of the analysis window.
func Direction ¶ added in v0.2.0
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
FormatBucketSize returns a short label for a duration (15m, 1h, 4h, 1d, …).
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) 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 ¶
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.
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 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.
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 (*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).