From 3abd6f4572fb2f2b216dbae6e19bfb21072d0718 Mon Sep 17 00:00:00 2001 From: Thomas Paradis Date: Wed, 7 Apr 2021 15:21:26 +0200 Subject: [PATCH 01/17] Add metric by status for all message processed by smtp --- postfix_exporter.go | 21 ++++++++++++++++++--- postfix_exporter_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 226542d..607b185 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -56,6 +56,8 @@ type PostfixExporter struct { smtpDelays *prometheus.HistogramVec smtpTLSConnects *prometheus.CounterVec smtpConnectionTimedOut prometheus.Counter + smtpProcesses *prometheus.CounterVec + // should be the same as smtpProcesses{status=deferred}, kept for compatibility, but this doesn't work ! smtpDeferreds prometheus.Counter smtpdConnects prometheus.Counter smtpdDisconnects prometheus.Counter @@ -66,6 +68,7 @@ type PostfixExporter struct { smtpdSASLAuthenticationFailures prometheus.Counter smtpdTLSConnects *prometheus.CounterVec unsupportedLogEntries *prometheus.CounterVec + // same as smtpProcesses{status=deferred}, kept for compatibility smtpStatusDeferred prometheus.Counter opendkimSignatureAdded *prometheus.CounterVec } @@ -289,7 +292,7 @@ var ( logLine = regexp.MustCompile(` ?(postfix|opendkim)(/(\w+))?\[\d+\]: (.*)`) lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `) qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `) - smtpStatusDeferredLine = regexp.MustCompile(`, status=deferred`) + smtpStatusLine = regexp.MustCompile(`, status=(\w+) `) smtpTLSLine = regexp.MustCompile(`^(\S+) TLS connection established to \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)`) smtpConnectionTimedOut = regexp.MustCompile(`^connect\s+to\s+(.*)\[(.*)\]:(\d+):\s+(Connection timed out)$`) smtpdFCrDNSErrorsLine = regexp.MustCompile(`^warning: hostname \S+ does not resolve to address `) @@ -359,8 +362,11 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { addToHistogramVec(e.smtpDelays, smtpMatches[3], "queue_manager", "") addToHistogramVec(e.smtpDelays, smtpMatches[4], "connection_setup", "") addToHistogramVec(e.smtpDelays, smtpMatches[5], "transmission", "") - if smtpMatches := smtpStatusDeferredLine.FindStringSubmatch(remainder); smtpMatches != nil { - e.smtpStatusDeferred.Inc() + if smtpStatusMatches := smtpStatusLine.FindStringSubmatch(remainder); smtpStatusMatches != nil { + e.smtpProcesses.WithLabelValues(smtpStatusMatches[1]).Inc() + if smtpStatusMatches[1] == "deferred" { + e.smtpStatusDeferred.Inc() + } } } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(remainder); smtpTLSMatches != nil { e.smtpTLSConnects.WithLabelValues(smtpTLSMatches[1:]...).Inc() @@ -504,6 +510,13 @@ func NewPostfixExporter(showqPath string, logSrc LogSource, logUnsupportedLines Name: "smtp_deferred_messages_total", Help: "Total number of messages that have been deferred on SMTP.", }), + smtpProcesses: prometheus.NewCounterVec( + prometheus.CounterOpts{ + Namespace: "postfix", + Name: "smtp_messages_processed_total", + Help: "Total number of messages that have been processed by the smtp process.", + }, + []string{"status"}), smtpConnectionTimedOut: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: "postfix", Name: "smtp_connection_timed_out_total", @@ -598,6 +611,7 @@ func (e *PostfixExporter) Describe(ch chan<- *prometheus.Desc) { e.smtpDelays.Describe(ch) e.smtpTLSConnects.Describe(ch) ch <- e.smtpDeferreds.Desc() + e.smtpProcesses.Describe(ch) ch <- e.smtpdConnects.Desc() ch <- e.smtpdDisconnects.Desc() ch <- e.smtpdFCrDNSErrors.Desc() @@ -673,6 +687,7 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { e.smtpDelays.Collect(ch) e.smtpTLSConnects.Collect(ch) ch <- e.smtpDeferreds + e.smtpProcesses.Collect(ch) ch <- e.smtpdConnects ch <- e.smtpdDisconnects ch <- e.smtpdFCrDNSErrors diff --git a/postfix_exporter_test.go b/postfix_exporter_test.go index a3426a4..a913ddb 100644 --- a/postfix_exporter_test.go +++ b/postfix_exporter_test.go @@ -23,6 +23,8 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpDelays *prometheus.HistogramVec smtpTLSConnects *prometheus.CounterVec smtpDeferreds prometheus.Counter + smtpStatusDeferred prometheus.Counter + smtpProcesses *prometheus.CounterVec smtpdConnects prometheus.Counter smtpdDisconnects prometheus.Counter smtpdFCrDNSErrors prometheus.Counter @@ -39,6 +41,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { saslFailedCount int outgoingTLS int smtpdMessagesProcessed int + smtpMessagesProcessed int } tests := []struct { name string @@ -117,6 +120,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { fields: fields{ smtpdSASLAuthenticationFailures: prometheus.NewCounter(prometheus.CounterOpts{}), unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), + smtpProcesses: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"status"}), }, }, { @@ -146,10 +150,12 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { removedCount: 0, saslFailedCount: 0, outgoingTLS: 2, + smtpdMessagesProcessed: 0, }, fields: fields{ unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), smtpTLSConnects: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"Verified", "TLSv1.2", "ECDHE-RSA-AES256-GCM-SHA384", "256", "256"}), + smtpProcesses: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"status"}), }, }, { @@ -162,9 +168,29 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { saslFailedCount: 0, outgoingTLS: 0, smtpdMessagesProcessed: 0, + smtpMessagesProcessed: 1, }, fields: fields{ smtpDelays: prometheus.NewHistogramVec(prometheus.HistogramOpts{}, []string{"stage"}), + smtpProcesses: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"status"}), + }, + }, + { + name: "Testing different smtp statuses", + args: args{ + line: []string{ + "Dec 29 02:54:09 mail postfix/smtp[7648]: 732BB407C3: host mail.domain.com[1.1.1.1] said: 451 DT:SPM 163 mx13,P8CowECpNVM_oEVaenoEAQ--.23796S3 1514512449, please try again 15min later (in reply to end of DATA command)", + "Dec 29 02:54:12 mail postfix/smtp[7648]: 732BB407C3: to=, relay=mail.domain.com[1.1.1.1]:25, delay=6.2, delays=0.1/0/5.2/0.87, dsn=4.0.0, status=deferred (host mail.domain.com[1.1.1.1] said: 451 DT:SPM 163 mx40,WsCowAAnEhlCoEVa5GjcAA--.20089S3 1514512452, please try again 15min later (in reply to end of DATA command))", + "Dec 29 03:03:48 mail postfix/smtp[8492]: 732BB407C3: to=, relay=mail.domain.com[1.1.1.1]:25, delay=582, delays=563/16/1.7/0.81, dsn=5.0.0, status=bounced (host mail.domain.com[1.1.1.1] said: 554 DT:SPM 163 mx9,O8CowEDJVFKCokVaRhz+AA--.26016S3 1514513028,please see http://mail.domain.com/help/help_spam.htm?ip= (in reply to end of DATA command))", + "Dec 29 03:03:48 mail postfix/bounce[9321]: 732BB407C3: sender non-delivery notification: 5DE184083C", + }, + smtpMessagesProcessed: 2, + }, + fields: fields{ + unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), + smtpDelays: prometheus.NewHistogramVec(prometheus.HistogramOpts{}, []string{"stage"}), + smtpStatusDeferred: prometheus.NewCounter(prometheus.CounterOpts{}), + smtpProcesses: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"status"}), }, }, } @@ -184,6 +210,8 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpDelays: tt.fields.smtpDelays, smtpTLSConnects: tt.fields.smtpTLSConnects, smtpDeferreds: tt.fields.smtpDeferreds, + smtpStatusDeferred: tt.fields.smtpStatusDeferred, + smtpProcesses: tt.fields.smtpProcesses, smtpdConnects: tt.fields.smtpdConnects, smtpdDisconnects: tt.fields.smtpdDisconnects, smtpdFCrDNSErrors: tt.fields.smtpdFCrDNSErrors, @@ -202,6 +230,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { assertCounterEquals(t, e.smtpdSASLAuthenticationFailures, tt.args.saslFailedCount, "Wrong number of Sasl counter counted") assertCounterEquals(t, e.smtpTLSConnects, tt.args.outgoingTLS, "Wrong number of TLS connections counted") assertCounterEquals(t, e.smtpdProcesses, tt.args.smtpdMessagesProcessed, "Wrong number of smtpd messages processed") + assertCounterEquals(t, e.smtpProcesses, tt.args.smtpMessagesProcessed, "Wrong number of smtp messages processed") }) } } From 6531beb3a753b8e9536883d151fb7413255a4703 Mon Sep 17 00:00:00 2001 From: Thomas Paradis Date: Wed, 7 Apr 2021 15:31:44 +0200 Subject: [PATCH 02/17] Add metric for non delivery notifications from bounce --- postfix_exporter.go | 15 +++++++++++++++ postfix_exporter_test.go | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/postfix_exporter.go b/postfix_exporter.go index 607b185..ccc818c 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -71,6 +71,7 @@ type PostfixExporter struct { // same as smtpProcesses{status=deferred}, kept for compatibility smtpStatusDeferred prometheus.Counter opendkimSignatureAdded *prometheus.CounterVec + bounceNonDelivery prometheus.Counter } // A LogSource is an interface to read log lines. @@ -302,6 +303,7 @@ var ( smtpdSASLAuthenticationFailuresLine = regexp.MustCompile(`^warning: \S+: SASL \S+ authentication failed: `) smtpdTLSLine = regexp.MustCompile(`^(\S+) TLS connection established from \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)`) opendkimSignatureAdded = regexp.MustCompile(`^[\w\d]+: DKIM-Signature field added \(s=(\w+), d=(.*)\)$`) + bounceNonDeliveryLine = regexp.MustCompile(`: sender non-delivery notification: `) ) // CollectFromLogline collects metrict from a Postfix log line. @@ -397,6 +399,12 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { } else { e.addToUnsupportedLine(line, subprocess) } + case "bounce": + if bounceMatches := bounceNonDeliveryLine.FindStringSubmatch(remainder); bounceMatches != nil { + e.bounceNonDelivery.Inc() + } else { + e.addToUnsupportedLine(line, process) + } default: e.addToUnsupportedLine(line, subprocess) } @@ -590,6 +598,11 @@ func NewPostfixExporter(showqPath string, logSrc LogSource, logUnsupportedLines }, []string{"subject", "domain"}, ), + bounceNonDelivery: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: "postfix", + Name: "bounce_non_delivery_notification_total", + Help: "Total number of non delivery notification sent by bounce.", + }), }, nil } @@ -624,6 +637,7 @@ func (e *PostfixExporter) Describe(ch chan<- *prometheus.Desc) { e.unsupportedLogEntries.Describe(ch) e.smtpConnectionTimedOut.Describe(ch) e.opendkimSignatureAdded.Describe(ch) + ch <- e.bounceNonDelivery.Desc() } func (e *PostfixExporter) StartMetricCollection(ctx context.Context) { @@ -700,4 +714,5 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { e.unsupportedLogEntries.Collect(ch) ch <- e.smtpConnectionTimedOut e.opendkimSignatureAdded.Collect(ch) + ch <- e.bounceNonDelivery } diff --git a/postfix_exporter_test.go b/postfix_exporter_test.go index a913ddb..378b67a 100644 --- a/postfix_exporter_test.go +++ b/postfix_exporter_test.go @@ -33,6 +33,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpdRejects *prometheus.CounterVec smtpdSASLAuthenticationFailures prometheus.Counter smtpdTLSConnects *prometheus.CounterVec + bounceNonDelivery prometheus.Counter unsupportedLogEntries *prometheus.CounterVec } type args struct { @@ -42,6 +43,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { outgoingTLS int smtpdMessagesProcessed int smtpMessagesProcessed int + bounceNonDelivery int } tests := []struct { name string @@ -185,12 +187,14 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { "Dec 29 03:03:48 mail postfix/bounce[9321]: 732BB407C3: sender non-delivery notification: 5DE184083C", }, smtpMessagesProcessed: 2, + bounceNonDelivery: 1, }, fields: fields{ unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), smtpDelays: prometheus.NewHistogramVec(prometheus.HistogramOpts{}, []string{"stage"}), smtpStatusDeferred: prometheus.NewCounter(prometheus.CounterOpts{}), smtpProcesses: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"status"}), + bounceNonDelivery: prometheus.NewCounter(prometheus.CounterOpts{}), }, }, } @@ -220,6 +224,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpdRejects: tt.fields.smtpdRejects, smtpdSASLAuthenticationFailures: tt.fields.smtpdSASLAuthenticationFailures, smtpdTLSConnects: tt.fields.smtpdTLSConnects, + bounceNonDelivery: tt.fields.bounceNonDelivery, unsupportedLogEntries: tt.fields.unsupportedLogEntries, logUnsupportedLines: true, } @@ -231,6 +236,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { assertCounterEquals(t, e.smtpTLSConnects, tt.args.outgoingTLS, "Wrong number of TLS connections counted") assertCounterEquals(t, e.smtpdProcesses, tt.args.smtpdMessagesProcessed, "Wrong number of smtpd messages processed") assertCounterEquals(t, e.smtpProcesses, tt.args.smtpMessagesProcessed, "Wrong number of smtp messages processed") + assertCounterEquals(t, e.bounceNonDelivery, tt.args.bounceNonDelivery, "Wrong number of non delivery notifications") }) } } From 8966f650671051c15877a9129d38f86102574d4c Mon Sep 17 00:00:00 2001 From: Thomas Paradis Date: Wed, 7 Apr 2021 15:41:26 +0200 Subject: [PATCH 03/17] Add another metric for mails delivered locally --- postfix_exporter.go | 14 ++++++++++++++ postfix_exporter_test.go | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/postfix_exporter.go b/postfix_exporter.go index ccc818c..f74dabe 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -72,6 +72,7 @@ type PostfixExporter struct { smtpStatusDeferred prometheus.Counter opendkimSignatureAdded *prometheus.CounterVec bounceNonDelivery prometheus.Counter + virtualDelivered prometheus.Counter } // A LogSource is an interface to read log lines. @@ -405,6 +406,12 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { } else { e.addToUnsupportedLine(line, process) } + case "virtual": + if strings.HasSuffix(remainder, ", status=sent (delivered to maildir)") { + e.virtualDelivered.Inc() + } else { + e.addToUnsupportedLine(line, process) + } default: e.addToUnsupportedLine(line, subprocess) } @@ -603,6 +610,11 @@ func NewPostfixExporter(showqPath string, logSrc LogSource, logUnsupportedLines Name: "bounce_non_delivery_notification_total", Help: "Total number of non delivery notification sent by bounce.", }), + virtualDelivered: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: "postfix", + Name: "virtual_delivered_total", + Help: "Total number of mail delivered to a virtual mailbox.", + }), }, nil } @@ -638,6 +650,7 @@ func (e *PostfixExporter) Describe(ch chan<- *prometheus.Desc) { e.smtpConnectionTimedOut.Describe(ch) e.opendkimSignatureAdded.Describe(ch) ch <- e.bounceNonDelivery.Desc() + ch <- e.virtualDelivered.Desc() } func (e *PostfixExporter) StartMetricCollection(ctx context.Context) { @@ -715,4 +728,5 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { ch <- e.smtpConnectionTimedOut e.opendkimSignatureAdded.Collect(ch) ch <- e.bounceNonDelivery + ch <- e.virtualDelivered } diff --git a/postfix_exporter_test.go b/postfix_exporter_test.go index 378b67a..cb646b1 100644 --- a/postfix_exporter_test.go +++ b/postfix_exporter_test.go @@ -34,6 +34,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpdSASLAuthenticationFailures prometheus.Counter smtpdTLSConnects *prometheus.CounterVec bounceNonDelivery prometheus.Counter + virtualDelivered prometheus.Counter unsupportedLogEntries *prometheus.CounterVec } type args struct { @@ -44,6 +45,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpdMessagesProcessed int smtpMessagesProcessed int bounceNonDelivery int + virtualDelivered int } tests := []struct { name string @@ -197,6 +199,18 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { bounceNonDelivery: prometheus.NewCounter(prometheus.CounterOpts{}), }, }, + { + name: "Testing virtual delivered", + args: args{ + line: []string{ + "Apr 7 15:35:20 123-mail postfix/virtual[20235]: 199041033BE: to=, relay=virtual, delay=0.08, delays=0.08/0/0/0, dsn=2.0.0, status=sent (delivered to maildir)", + }, + virtualDelivered: 1, + }, + fields: fields{ + virtualDelivered: prometheus.NewCounter(prometheus.CounterOpts{}), + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -225,6 +239,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpdSASLAuthenticationFailures: tt.fields.smtpdSASLAuthenticationFailures, smtpdTLSConnects: tt.fields.smtpdTLSConnects, bounceNonDelivery: tt.fields.bounceNonDelivery, + virtualDelivered: tt.fields.virtualDelivered, unsupportedLogEntries: tt.fields.unsupportedLogEntries, logUnsupportedLines: true, } @@ -237,6 +252,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { assertCounterEquals(t, e.smtpdProcesses, tt.args.smtpdMessagesProcessed, "Wrong number of smtpd messages processed") assertCounterEquals(t, e.smtpProcesses, tt.args.smtpMessagesProcessed, "Wrong number of smtp messages processed") assertCounterEquals(t, e.bounceNonDelivery, tt.args.bounceNonDelivery, "Wrong number of non delivery notifications") + assertCounterEquals(t, e.virtualDelivered, tt.args.virtualDelivered, "Wrong number of delivered mails") }) } } From 4470123df6d6ef429b5905f38b314d5666343815 Mon Sep 17 00:00:00 2001 From: Thomas Paradis Date: Wed, 14 Apr 2021 10:52:11 +0200 Subject: [PATCH 04/17] Track the number of expired emails form logs --- postfix_exporter.go | 11 +++++++++++ postfix_exporter_test.go | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/postfix_exporter.go b/postfix_exporter.go index f74dabe..6c178b5 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -53,6 +53,7 @@ type PostfixExporter struct { qmgrInsertsNrcpt prometheus.Histogram qmgrInsertsSize prometheus.Histogram qmgrRemoves prometheus.Counter + qmgrExpires prometheus.Counter smtpDelays *prometheus.HistogramVec smtpTLSConnects *prometheus.CounterVec smtpConnectionTimedOut prometheus.Counter @@ -294,6 +295,7 @@ var ( logLine = regexp.MustCompile(` ?(postfix|opendkim)(/(\w+))?\[\d+\]: (.*)`) lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `) qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `) + qmgrExpiredLine = regexp.MustCompile(`:.*, status=(expired|force-expired), returned to sender`) smtpStatusLine = regexp.MustCompile(`, status=(\w+) `) smtpTLSLine = regexp.MustCompile(`^(\S+) TLS connection established to \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)`) smtpConnectionTimedOut = regexp.MustCompile(`^connect\s+to\s+(.*)\[(.*)\]:(\d+):\s+(Connection timed out)$`) @@ -356,6 +358,8 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { addToHistogram(e.qmgrInsertsNrcpt, qmgrInsertMatches[2], "QMGR nrcpt") } else if strings.HasSuffix(remainder, ": removed") { e.qmgrRemoves.Inc() + } else if qmgrExpired := qmgrExpiredLine.FindStringSubmatch(remainder); qmgrExpired != nil { + e.qmgrExpires.Inc() } else { e.addToUnsupportedLine(line, subprocess) } @@ -505,6 +509,11 @@ func NewPostfixExporter(showqPath string, logSrc LogSource, logUnsupportedLines Name: "qmgr_messages_removed_total", Help: "Total number of messages removed from mail queues.", }), + qmgrExpires: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: "postfix", + Name: "qmgr_messages_expired_total", + Help: "Total number of messages expired from mail queues.", + }), smtpDelays: prometheus.NewHistogramVec( prometheus.HistogramOpts{ Namespace: "postfix", @@ -633,6 +642,7 @@ func (e *PostfixExporter) Describe(ch chan<- *prometheus.Desc) { ch <- e.qmgrInsertsNrcpt.Desc() ch <- e.qmgrInsertsSize.Desc() ch <- e.qmgrRemoves.Desc() + ch <- e.qmgrExpires.Desc() e.smtpDelays.Describe(ch) e.smtpTLSConnects.Describe(ch) ch <- e.smtpDeferreds.Desc() @@ -711,6 +721,7 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { ch <- e.qmgrInsertsNrcpt ch <- e.qmgrInsertsSize ch <- e.qmgrRemoves + ch <- e.qmgrExpires e.smtpDelays.Collect(ch) e.smtpTLSConnects.Collect(ch) ch <- e.smtpDeferreds diff --git a/postfix_exporter_test.go b/postfix_exporter_test.go index cb646b1..af26a12 100644 --- a/postfix_exporter_test.go +++ b/postfix_exporter_test.go @@ -20,6 +20,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { qmgrInsertsNrcpt prometheus.Histogram qmgrInsertsSize prometheus.Histogram qmgrRemoves prometheus.Counter + qmgrExpires prometheus.Counter smtpDelays *prometheus.HistogramVec smtpTLSConnects *prometheus.CounterVec smtpDeferreds prometheus.Counter @@ -40,6 +41,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { type args struct { line []string removedCount int + expiredCount int saslFailedCount int outgoingTLS int smtpdMessagesProcessed int @@ -110,6 +112,19 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), }, }, + { + name: "qmgr expired", + args: args{ + line: []string{ + "Apr 10 14:50:16 mail postfix/qmgr[3663]: BACE842E72: from=, status=expired, returned to sender", + "Apr 10 14:50:16 mail postfix/qmgr[3663]: BACE842E73: from=, status=force-expired, returned to sender", + }, + expiredCount: 2, + }, + fields: fields{ + qmgrExpires: prometheus.NewCounter(prometheus.CounterOpts{}), + }, + }, { name: "SASL Failed", args: args{ @@ -225,6 +240,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { qmgrInsertsNrcpt: tt.fields.qmgrInsertsNrcpt, qmgrInsertsSize: tt.fields.qmgrInsertsSize, qmgrRemoves: tt.fields.qmgrRemoves, + qmgrExpires: tt.fields.qmgrExpires, smtpDelays: tt.fields.smtpDelays, smtpTLSConnects: tt.fields.smtpTLSConnects, smtpDeferreds: tt.fields.smtpDeferreds, @@ -247,6 +263,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { e.CollectFromLogLine(line) } assertCounterEquals(t, e.qmgrRemoves, tt.args.removedCount, "Wrong number of lines counted") + assertCounterEquals(t, e.qmgrExpires, tt.args.expiredCount, "Wrong number of qmgr expired lines counted") assertCounterEquals(t, e.smtpdSASLAuthenticationFailures, tt.args.saslFailedCount, "Wrong number of Sasl counter counted") assertCounterEquals(t, e.smtpTLSConnects, tt.args.outgoingTLS, "Wrong number of TLS connections counted") assertCounterEquals(t, e.smtpdProcesses, tt.args.smtpdMessagesProcessed, "Wrong number of smtpd messages processed") From 0523537d20d6927604d7318a220a74d3983fb4ac Mon Sep 17 00:00:00 2001 From: Thomas Paradis Date: Wed, 14 Apr 2021 12:40:02 +0200 Subject: [PATCH 05/17] Expose the severity of unsupported lines --- postfix_exporter.go | 33 ++++++++++++++------------- postfix_exporter_test.go | 49 +++++++++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 22 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 6c178b5..56691cc 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -292,7 +292,7 @@ func CollectShowqFromSocket(path string, ch chan<- prometheus.Metric) error { // Patterns for parsing log messages. var ( - logLine = regexp.MustCompile(` ?(postfix|opendkim)(/(\w+))?\[\d+\]: (.*)`) + logLine = regexp.MustCompile(` ?(postfix|opendkim)(/(\w+))?\[\d+\]: ((?:(warning|error|fatal|panic): )?.*)`) lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `) qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `) qmgrExpiredLine = regexp.MustCompile(`:.*, status=(expired|force-expired), returned to sender`) @@ -316,10 +316,11 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { if logMatches == nil { // Unknown log entry format. - e.addToUnsupportedLine(line, "") + e.addToUnsupportedLine(line, "", "") return } process := logMatches[1] + level := logMatches[5] remainder := logMatches[4] switch process { case "postfix": @@ -332,7 +333,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { } else if strings.Contains(remainder, ": reject: ") { e.cleanupRejects.Inc() } else { - e.addToUnsupportedLine(line, subprocess) + e.addToUnsupportedLine(line, subprocess, level) } case "lmtp": if lmtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(remainder); lmtpMatches != nil { @@ -341,7 +342,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { addToHistogramVec(e.lmtpDelays, lmtpMatches[4], "LMTP sdelay", "connection_setup") addToHistogramVec(e.lmtpDelays, lmtpMatches[5], "LMTP xdelay", "transmission") } else { - e.addToUnsupportedLine(line, subprocess) + e.addToUnsupportedLine(line, subprocess, level) } case "pipe": if pipeMatches := lmtpPipeSMTPLine.FindStringSubmatch(remainder); pipeMatches != nil { @@ -350,7 +351,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { addToHistogramVec(e.pipeDelays, pipeMatches[4], "PIPE sdelay", pipeMatches[1], "connection_setup") addToHistogramVec(e.pipeDelays, pipeMatches[5], "PIPE xdelay", pipeMatches[1], "transmission") } else { - e.addToUnsupportedLine(line, subprocess) + e.addToUnsupportedLine(line, subprocess, level) } case "qmgr": if qmgrInsertMatches := qmgrInsertLine.FindStringSubmatch(remainder); qmgrInsertMatches != nil { @@ -361,7 +362,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { } else if qmgrExpired := qmgrExpiredLine.FindStringSubmatch(remainder); qmgrExpired != nil { e.qmgrExpires.Inc() } else { - e.addToUnsupportedLine(line, subprocess) + e.addToUnsupportedLine(line, subprocess, level) } case "smtp": if smtpMatches := lmtpPipeSMTPLine.FindStringSubmatch(remainder); smtpMatches != nil { @@ -380,7 +381,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { } else if smtpMatches := smtpConnectionTimedOut.FindStringSubmatch(remainder); smtpMatches != nil { e.smtpConnectionTimedOut.Inc() } else { - e.addToUnsupportedLine(line, subprocess) + e.addToUnsupportedLine(line, subprocess, level) } case "smtpd": if strings.HasPrefix(remainder, "connect from ") { @@ -402,40 +403,40 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { } else if smtpdTLSMatches := smtpdTLSLine.FindStringSubmatch(remainder); smtpdTLSMatches != nil { e.smtpdTLSConnects.WithLabelValues(smtpdTLSMatches[1:]...).Inc() } else { - e.addToUnsupportedLine(line, subprocess) + e.addToUnsupportedLine(line, subprocess, level) } case "bounce": if bounceMatches := bounceNonDeliveryLine.FindStringSubmatch(remainder); bounceMatches != nil { e.bounceNonDelivery.Inc() } else { - e.addToUnsupportedLine(line, process) + e.addToUnsupportedLine(line, process, level) } case "virtual": if strings.HasSuffix(remainder, ", status=sent (delivered to maildir)") { e.virtualDelivered.Inc() } else { - e.addToUnsupportedLine(line, process) + e.addToUnsupportedLine(line, process, level) } default: - e.addToUnsupportedLine(line, subprocess) + e.addToUnsupportedLine(line, subprocess, level) } case "opendkim": if opendkimMatches := opendkimSignatureAdded.FindStringSubmatch(remainder); opendkimMatches != nil { e.opendkimSignatureAdded.WithLabelValues(opendkimMatches[1], opendkimMatches[2]).Inc() } else { - e.addToUnsupportedLine(line, process) + e.addToUnsupportedLine(line, process, level) } default: // Unknown log entry format. - e.addToUnsupportedLine(line, "") + e.addToUnsupportedLine(line, process, level) } } -func (e *PostfixExporter) addToUnsupportedLine(line string, subprocess string) { +func (e *PostfixExporter) addToUnsupportedLine(line string, subprocess string, level string) { if e.logUnsupportedLines { log.Printf("Unsupported Line: %v", line) } - e.unsupportedLogEntries.WithLabelValues(subprocess).Inc() + e.unsupportedLogEntries.WithLabelValues(subprocess, level).Inc() } func addToHistogram(h prometheus.Histogram, value, fieldName string) { @@ -600,7 +601,7 @@ func NewPostfixExporter(showqPath string, logSrc LogSource, logUnsupportedLines Name: "unsupported_log_entries_total", Help: "Log entries that could not be processed.", }, - []string{"service"}), + []string{"service", "level"}), smtpStatusDeferred: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: "postfix", Name: "smtp_status_deferred", diff --git a/postfix_exporter_test.go b/postfix_exporter_test.go index af26a12..8f057a8 100644 --- a/postfix_exporter_test.go +++ b/postfix_exporter_test.go @@ -48,6 +48,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpMessagesProcessed int bounceNonDelivery int virtualDelivered int + unsupportedLogEntries []string } tests := []struct { name string @@ -65,7 +66,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { }, fields: fields{ qmgrRemoves: prometheus.NewCounter(prometheus.CounterOpts{}), - unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), + unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"service", "level"}), }, }, { @@ -109,7 +110,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { }, fields: fields{ qmgrRemoves: prometheus.NewCounter(prometheus.CounterOpts{}), - unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), + unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"service", "level"}), }, }, { @@ -138,7 +139,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { }, fields: fields{ smtpdSASLAuthenticationFailures: prometheus.NewCounter(prometheus.CounterOpts{}), - unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), + unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"service", "level"}), smtpProcesses: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"status"}), }, }, @@ -155,7 +156,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpdMessagesProcessed: 2, }, fields: fields{ - unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), + unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"service", "level"}), smtpdProcesses: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"sasl_method"}), }, }, @@ -172,7 +173,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { smtpdMessagesProcessed: 0, }, fields: fields{ - unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), + unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"service", "level"}), smtpTLSConnects: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"Verified", "TLSv1.2", "ECDHE-RSA-AES256-GCM-SHA384", "256", "256"}), smtpProcesses: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"status"}), }, @@ -207,7 +208,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { bounceNonDelivery: 1, }, fields: fields{ - unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"process"}), + unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"service", "level"}), smtpDelays: prometheus.NewHistogramVec(prometheus.HistogramOpts{}, []string{"stage"}), smtpStatusDeferred: prometheus.NewCounter(prometheus.CounterOpts{}), smtpProcesses: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"status"}), @@ -226,6 +227,25 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { virtualDelivered: prometheus.NewCounter(prometheus.CounterOpts{}), }, }, + { + name: "Testing levels of unsupported entries", + args: args{ + line: []string{ + "Feb 14 19:05:25 123-mail postfix/smtpd[1517]: table hash:/etc/postfix/virtual_mailbox_maps(0,lock|fold_fix) has changed -- restarting", + "Mar 16 12:28:02 123-mail postfix/smtpd[16268]: fatal: file /etc/postfix/main.cf: parameter default_privs: unknown user name value: nobody", + "Mar 16 23:30:44 123-mail postfix/qmgr[29980]: warning: please avoid flushing the whole queue when you have", + "Mar 16 23:30:44 123-mail postfix/qmgr[29980]: warning: lots of deferred mail, that is bad for performance", + }, + unsupportedLogEntries: []string{ + `label: label: counter: `, + `label: label: counter: `, + `label: label: counter: `, + }, + }, + fields: fields{ + unsupportedLogEntries: prometheus.NewCounterVec(prometheus.CounterOpts{}, []string{"service", "level"}), + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -270,6 +290,7 @@ func TestPostfixExporter_CollectFromLogline(t *testing.T) { assertCounterEquals(t, e.smtpProcesses, tt.args.smtpMessagesProcessed, "Wrong number of smtp messages processed") assertCounterEquals(t, e.bounceNonDelivery, tt.args.bounceNonDelivery, "Wrong number of non delivery notifications") assertCounterEquals(t, e.virtualDelivered, tt.args.virtualDelivered, "Wrong number of delivered mails") + assertVecMetricsEquals(t, e.unsupportedLogEntries, tt.args.unsupportedLogEntries, "Wrong number of unsupportedLogEntries") }) } } @@ -309,3 +330,19 @@ func assertCounterEquals(t *testing.T, counter prometheus.Collector, expected in } } } +func assertVecMetricsEquals(t *testing.T, counter *prometheus.CounterVec, expected []string, message string) { + if expected != nil { + metricsChan := make(chan prometheus.Metric) + go func() { + counter.Collect(metricsChan) + close(metricsChan) + }() + var res []string + for metric := range metricsChan { + metricDto := io_prometheus_client.Metric{} + metric.Write(&metricDto) + res = append(res, metricDto.String()) + } + assert.Equal(t, expected, res, message) + } +} From 93eaf4786902350f0fc3f17b80a67cbdc21be74c Mon Sep 17 00:00:00 2001 From: svbito Date: Mon, 21 Feb 2022 20:49:40 +0100 Subject: [PATCH 06/17] fix regex for multi-level postfix-subprocesses with slashes and dashes --- postfix_exporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 226542d..44ba0e2 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -286,7 +286,7 @@ func CollectShowqFromSocket(path string, ch chan<- prometheus.Metric) error { // Patterns for parsing log messages. var ( - logLine = regexp.MustCompile(` ?(postfix|opendkim)(/(\w+))?\[\d+\]: (.*)`) + logLine = regexp.MustCompile(` ?(postfix|opendkim)/?(.*/(\w+))?\[\d+\]: (.*)`) lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `) qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `) smtpStatusDeferredLine = regexp.MustCompile(`, status=deferred`) From 17e8e1f61e1860600d778dfb35d13c40814ff576 Mon Sep 17 00:00:00 2001 From: svbito Date: Mon, 21 Feb 2022 20:54:39 +0100 Subject: [PATCH 07/17] add support for bounces --- postfix_exporter.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/postfix_exporter.go b/postfix_exporter.go index 44ba0e2..024262a 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -67,6 +67,7 @@ type PostfixExporter struct { smtpdTLSConnects *prometheus.CounterVec unsupportedLogEntries *prometheus.CounterVec smtpStatusDeferred prometheus.Counter + smtpStatusBounced prometheus.Counter opendkimSignatureAdded *prometheus.CounterVec } @@ -290,6 +291,7 @@ var ( lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `) qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `) smtpStatusDeferredLine = regexp.MustCompile(`, status=deferred`) + smtpStatusBouncedLine = regexp.MustCompile(`, status=bounced`) smtpTLSLine = regexp.MustCompile(`^(\S+) TLS connection established to \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)`) smtpConnectionTimedOut = regexp.MustCompile(`^connect\s+to\s+(.*)\[(.*)\]:(\d+):\s+(Connection timed out)$`) smtpdFCrDNSErrorsLine = regexp.MustCompile(`^warning: hostname \S+ does not resolve to address `) @@ -362,6 +364,9 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { if smtpMatches := smtpStatusDeferredLine.FindStringSubmatch(remainder); smtpMatches != nil { e.smtpStatusDeferred.Inc() } + if smtpMatches := smtpStatusBouncedLine.FindStringSubmatch(remainder); smtpMatches != nil { + e.smtpStatusBounced.Inc() + } } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(remainder); smtpTLSMatches != nil { e.smtpTLSConnects.WithLabelValues(smtpTLSMatches[1:]...).Inc() } else if smtpMatches := smtpConnectionTimedOut.FindStringSubmatch(remainder); smtpMatches != nil { From dbd85fa1c1c21ef6cf04ef743918001953ca95f1 Mon Sep 17 00:00:00 2001 From: svbito Date: Mon, 21 Feb 2022 20:58:14 +0100 Subject: [PATCH 08/17] add support for selektors which contain e.g slashes --- postfix_exporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 024262a..3626869 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -300,7 +300,7 @@ var ( smtpdLostConnectionLine = regexp.MustCompile(`^lost connection after (\w+) from `) smtpdSASLAuthenticationFailuresLine = regexp.MustCompile(`^warning: \S+: SASL \S+ authentication failed: `) smtpdTLSLine = regexp.MustCompile(`^(\S+) TLS connection established from \S+: (\S+) with cipher (\S+) \((\d+)/(\d+) bits\)`) - opendkimSignatureAdded = regexp.MustCompile(`^[\w\d]+: DKIM-Signature field added \(s=(\w+), d=(.*)\)$`) + opendkimSignatureAdded = regexp.MustCompile(`^[\w\d]+: DKIM-Signature field added \(s=(.+), d=(.*)\)$`) ) // CollectFromLogline collects metrict from a Postfix log line. From 588c326297e9b4f8c3a287293544c6a1db139238 Mon Sep 17 00:00:00 2001 From: svbito Date: Mon, 21 Feb 2022 21:52:34 +0100 Subject: [PATCH 09/17] missing else --- postfix_exporter.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 3626869..6a0e14e 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -363,8 +363,7 @@ func (e *PostfixExporter) CollectFromLogLine(line string) { addToHistogramVec(e.smtpDelays, smtpMatches[5], "transmission", "") if smtpMatches := smtpStatusDeferredLine.FindStringSubmatch(remainder); smtpMatches != nil { e.smtpStatusDeferred.Inc() - } - if smtpMatches := smtpStatusBouncedLine.FindStringSubmatch(remainder); smtpMatches != nil { + } else if smtpMatches := smtpStatusBouncedLine.FindStringSubmatch(remainder); smtpMatches != nil { e.smtpStatusBounced.Inc() } } else if smtpTLSMatches := smtpTLSLine.FindStringSubmatch(remainder); smtpTLSMatches != nil { From 6bf8875a0ba7a0b8e4277cc59cdcfc72ab88d060 Mon Sep 17 00:00:00 2001 From: svbito Date: Mon, 21 Feb 2022 21:58:07 +0100 Subject: [PATCH 10/17] add bounces --- postfix_exporter.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/postfix_exporter.go b/postfix_exporter.go index 6a0e14e..97f9541 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -573,6 +573,11 @@ func NewPostfixExporter(showqPath string, logSrc LogSource, logUnsupportedLines Name: "smtp_status_deferred", Help: "Total number of messages deferred.", }), + smtpStatusBounced: prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: "postfix", + Name: "smtp_status_bounced", + Help: "Total number of messages bounced.", + }), opendkimSignatureAdded: prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: "opendkim", @@ -611,6 +616,7 @@ func (e *PostfixExporter) Describe(ch chan<- *prometheus.Desc) { ch <- e.smtpdSASLAuthenticationFailures.Desc() e.smtpdTLSConnects.Describe(ch) ch <- e.smtpStatusDeferred.Desc() + ch <- e.smtpStatusBounced.Desc() e.unsupportedLogEntries.Describe(ch) e.smtpConnectionTimedOut.Describe(ch) e.opendkimSignatureAdded.Describe(ch) From c5d4b8d5eafbed01fd2f1c4ef9fb65a07ebd16fd Mon Sep 17 00:00:00 2001 From: svbito Date: Mon, 21 Feb 2022 22:06:26 +0100 Subject: [PATCH 11/17] collect bounces --- postfix_exporter.go | 1 + 1 file changed, 1 insertion(+) diff --git a/postfix_exporter.go b/postfix_exporter.go index 97f9541..306827f 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -692,6 +692,7 @@ func (e *PostfixExporter) Collect(ch chan<- prometheus.Metric) { ch <- e.smtpdSASLAuthenticationFailures e.smtpdTLSConnects.Collect(ch) ch <- e.smtpStatusDeferred + ch <- e.smtpStatusBounced e.unsupportedLogEntries.Collect(ch) ch <- e.smtpConnectionTimedOut e.opendkimSignatureAdded.Collect(ch) From d369bddf6f366775f178790f2ea0ecf8e3a5c625 Mon Sep 17 00:00:00 2001 From: Piotr Popieluch Date: Wed, 12 May 2021 11:36:22 +0200 Subject: [PATCH 12/17] Update tail from hpcloud/tail to nxadm/tail Currently it does not always detect rotated logfiles. There are many issues in hpcloud/tail which are not addressed, hpcloud/tail looks dead. nxadm/tail is a fork which solved many known issues. --- go.mod | 3 +-- go.sum | 5 +++++ logsource_file.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f35270f..51090de 100644 --- a/go.mod +++ b/go.mod @@ -9,14 +9,13 @@ require ( github.com/docker/docker v1.13.1 github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect - github.com/fsnotify/fsnotify v1.4.7 // indirect github.com/hpcloud/tail v1.0.0 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/nxadm/tail v1.4.8 github.com/opencontainers/go-digest v1.0.0 // indirect github.com/prometheus/client_golang v1.4.1 github.com/prometheus/client_model v0.2.0 github.com/stretchr/testify v1.4.0 gopkg.in/fsnotify.v1 v1.4.7 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect ) diff --git a/go.sum b/go.sum index fedcb99..925c19f 100644 --- a/go.sum +++ b/go.sum @@ -27,6 +27,8 @@ github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= @@ -61,6 +63,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -103,6 +107,7 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/logsource_file.go b/logsource_file.go index b906a84..96348c9 100644 --- a/logsource_file.go +++ b/logsource_file.go @@ -6,7 +6,7 @@ import ( "log" "github.com/alecthomas/kingpin" - "github.com/hpcloud/tail" + "github.com/nxadm/tail" ) // A FileLogSource can read lines from a file. From 4c2498879f889e89be10ed78548318e38abd1542 Mon Sep 17 00:00:00 2001 From: Piotr Popieluch Date: Mon, 16 Aug 2021 10:31:22 +0200 Subject: [PATCH 13/17] remove hpcloud/tail from go.mod --- go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/go.mod b/go.mod index 51090de..94ac294 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/docker/docker v1.13.1 github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect - github.com/hpcloud/tail v1.0.0 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect github.com/nxadm/tail v1.4.8 From d5605041237fc079c998a3ffec642a0ca99de33e Mon Sep 17 00:00:00 2001 From: Yoann Lecuyer Date: Sun, 2 May 2021 23:01:50 +0200 Subject: [PATCH 14/17] Fix: Default for mail log path --- README.md | 2 +- logsource_file.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1be73b8..931ad0b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ These options can be used when starting the `postfix_exporter` | `--web.listen-address` | Address to listen on for web interface and telemetry | `9154` | | `--web.telemetry-path` | Path under which to expose metrics | `/metrics` | | `--postfix.showq_path` | Path at which Postfix places its showq socket | `/var/spool/postfix/public/showq` | -| `--postfix.logfile_path` | Path where Postfix writes log entries | `/var/log/maillog` | +| `--postfix.logfile_path` | Path where Postfix writes log entries | `/var/log/mail.log` | | `--log.unsupported` | Log all unsupported lines | `false` | | `--docker.enable` | Read from the Docker logs instead of a file | `false` | | `--docker.container.id` | The container to read Docker logs from | `postfix` | diff --git a/logsource_file.go b/logsource_file.go index 96348c9..afcfa68 100644 --- a/logsource_file.go +++ b/logsource_file.go @@ -66,7 +66,7 @@ type fileLogSourceFactory struct { } func (f *fileLogSourceFactory) Init(app *kingpin.Application) { - app.Flag("postfix.logfile_path", "Path where Postfix writes log entries.").Default("/var/log/maillog").StringVar(&f.path) + app.Flag("postfix.logfile_path", "Path where Postfix writes log entries.").Default("/var/log/mail.log").StringVar(&f.path) } func (f *fileLogSourceFactory) New(ctx context.Context) (LogSourceCloser, error) { From ca2b7ed1c8e9356752a8df333e1aa35de28698db Mon Sep 17 00:00:00 2001 From: Yoann Lecuyer Date: Sun, 2 May 2021 23:04:26 +0200 Subject: [PATCH 15/17] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae38dde..cad552e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.3 / 2021-05-02 + +* [BUGFIX] Fix default for mail log path (/var/log/mail.log) + ## 0.1.2 / 2018-05-04 * [ENHANCEMENT] Build tag for systemd From 14a6bc49c23d1d6bbf1fd14c72f01a1e5f61d938 Mon Sep 17 00:00:00 2001 From: Dustin Hooten Date: Tue, 31 Aug 2021 12:27:41 -0600 Subject: [PATCH 16/17] Upgrade golang to 1.16 --- .travis.yml | 20 +++++++++++++++++++- Dockerfile | 2 +- build_static.sh | 2 +- go.mod | 6 ++---- go.sum | 17 ++++++++--------- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 95f7b22..d6c3fc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,24 @@ language: go matrix: include: + - go: 1.16.x + env: VET=1 GO111MODULE=on + - go: 1.16.x + env: RACE=1 GO111MODULE=on + - go: 1.16.x + env: RUN386=1 + - go: 1.15.x + env: VET=1 GO111MODULE=on + - go: 1.15.x + env: RACE=1 GO111MODULE=on + - go: 1.15.x + env: RUN386=1 + - go: 1.14.x + env: VET=1 GO111MODULE=on + - go: 1.14.x + env: RACE=1 GO111MODULE=on + - go: 1.14.x + env: RUN386=1 - go: 1.13.x env: VET=1 GO111MODULE=on - go: 1.13.x @@ -21,4 +39,4 @@ addons: env: global: - GO111MODULE: on \ No newline at end of file + GO111MODULE: on diff --git a/Dockerfile b/Dockerfile index d5ee64a..a3327d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.13 AS builder +FROM golang:1.16 AS builder WORKDIR /src # avoid downloading the dependencies on succesive builds diff --git a/build_static.sh b/build_static.sh index 574c3c0..b3233a7 100755 --- a/build_static.sh +++ b/build_static.sh @@ -1,6 +1,6 @@ #!/bin/sh -docker run -i -v `pwd`:/postfix_exporter golang:1.12 /bin/sh << 'EOF' +docker run -i -v `pwd`:/postfix_exporter golang:1.16 /bin/sh << 'EOF' set -ex # Install prerequisites for the build process. diff --git a/go.mod b/go.mod index 94ac294..261c013 100644 --- a/go.mod +++ b/go.mod @@ -1,20 +1,18 @@ module github.com/kumina/postfix_exporter -go 1.13 +go 1.16 require ( + github.com/Microsoft/go-winio v0.5.0 // indirect github.com/alecthomas/kingpin v2.2.6+incompatible github.com/coreos/go-systemd/v22 v22.0.0 github.com/docker/distribution v2.7.1+incompatible // indirect github.com/docker/docker v1.13.1 github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.4.0 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.1 // indirect github.com/nxadm/tail v1.4.8 github.com/opencontainers/go-digest v1.0.0 // indirect github.com/prometheus/client_golang v1.4.1 github.com/prometheus/client_model v0.2.0 github.com/stretchr/testify v1.4.0 - gopkg.in/fsnotify.v1 v1.4.7 // indirect ) diff --git a/go.sum b/go.sum index 925c19f..17fc388 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/Microsoft/go-winio v0.5.0 h1:Elr9Wn+sGKPlkaBvwu4mTrxtmOp3F3yV9qhaHbXGjwU= +github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= github.com/alecthomas/kingpin v2.2.6+incompatible h1:5svnBTFgJjZvGKyYBtMB0+m5wvrbUHiqye8wRJMlnYI= github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -25,8 +27,6 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -44,8 +44,6 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= @@ -68,8 +66,9 @@ github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -89,6 +88,7 @@ github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLk github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -108,17 +108,16 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgmDSfjglYZ3vStQ/gSCU= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From a1a68e74952376f8f25ea060b9fdcb8f0bcba33e Mon Sep 17 00:00:00 2001 From: svbito Date: Mon, 21 Feb 2022 20:49:40 +0100 Subject: [PATCH 17/17] fix regex for multi-level postfix-subprocesses with slashes and dashes --- postfix_exporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postfix_exporter.go b/postfix_exporter.go index 56691cc..3b760c3 100644 --- a/postfix_exporter.go +++ b/postfix_exporter.go @@ -292,7 +292,7 @@ func CollectShowqFromSocket(path string, ch chan<- prometheus.Metric) error { // Patterns for parsing log messages. var ( - logLine = regexp.MustCompile(` ?(postfix|opendkim)(/(\w+))?\[\d+\]: ((?:(warning|error|fatal|panic): )?.*)`) + logLine = regexp.MustCompile(` ?(postfix|opendkim)/?(.*/(\w+))?\[\d+\]: ((?:(warning|error|fatal|panic): )?.*)`) lmtpPipeSMTPLine = regexp.MustCompile(`, relay=(\S+), .*, delays=([0-9\.]+)/([0-9\.]+)/([0-9\.]+)/([0-9\.]+), `) qmgrInsertLine = regexp.MustCompile(`:.*, size=(\d+), nrcpt=(\d+) `) qmgrExpiredLine = regexp.MustCompile(`:.*, status=(expired|force-expired), returned to sender`)