Skip to content

Commit

Permalink
implement option to disable probing-mail-deletion (closes #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherti committed Jan 8, 2017
1 parent c755fe0 commit 08bb6d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions mailexporter.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ monitoringinterval: 10m
# Time until mail must have arrived after sending for positive outcome
mailchecktimeout: 3m

# Disables the mailexporters function to delete probing mails if filesystem access should be restricted
# to avoid spamming the log with warnings; defaults to false, can be ommitted if unneeded
# disablefiledeletion: false

servers:
- name: localhost # name for internal prometheus-metric
server: localhost # SMTP-server to use
Expand Down
18 changes: 12 additions & 6 deletions mailexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ var globalconf struct {
MonitoringInterval time.Duration
// The time to wait until mail_deliver_success = 0 is reported.
MailCheckTimeout time.Duration
// Disables deletion of probing-mails found
DisableFileDeletion bool

// SMTP-Servers used for probing.
Servers []smtpServerConfig
Expand Down Expand Up @@ -264,18 +266,22 @@ func generateToken(length int) string {
}

// deleteMail delete the given mail to not leave an untidied maildir.
func deleteMail(m email) {
if err := os.Remove(m.filename); err != nil {
logWarn.Println(err)
func deleteMailIfEnabled(m email) {
if globalconf.DisableFileDeletion {
logDebug.Println("file deletion disabled in config, not touching", m.filename)
} else {
if err := os.Remove(m.filename); err != nil {
logWarn.Println("deletion error:", err)
}
logDebug.Println("rm ", m.filename)
}
logDebug.Println("rm ", m.filename)
}

// handleLateMail handles mails that have been so late that they timed out
func handleLateMail(m email) {
logDebug.Printf("got late mail via %s; mail took %d ms\n", m.configname, milliseconds(m.tRecv.Sub(m.tSent)))
lateMails.WithLabelValues(m.configname).Inc()
deleteMail(m)
deleteMailIfEnabled(m)
}

// probe probes if mail gets through the entire chain from specified SMTPServer into Maildir.
Expand All @@ -297,7 +303,7 @@ func probe(c smtpServerConfig, p payload) {
logDebug.Println("checking mail for timeout")

deliverOk.WithLabelValues(c.Name).Set(1)
deleteMail(mail)
deleteMailIfEnabled(mail)

case <-timeout:
logDebug.Println("Getting mail timed out.")
Expand Down
8 changes: 7 additions & 1 deletion man/mailexporter.conf.5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" Automatically generated by Pandoc 1.18
.\" Automatically generated by Pandoc 1.19.1
.\"
.TH "mailexporter" "" "" "" ""
.hy
Expand All @@ -15,6 +15,12 @@ monitoring\-subroutines per server
.PP
\f[B]mailchecktimeout\f[] Timeout until mails are considered "didn\[aq]t
make it"
.PP
\f[B]disablefiledeletion\f[] <false|true> Disables the mailexporters
function to delete probing mails if filesystem access should be
restricted to avoid spamming the log with warnings; defaults to false,
i.e.
detected probing mails are deleted, and can be ommitted if unneeded
.SH SERVER\-OPTIONS
.PP
\f[B]name\f[] name for internal prometheus\-metric \f[B]server\f[]
Expand Down
2 changes: 2 additions & 0 deletions man/mailexporter.conf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ GENERAL OPTIONS

**mailchecktimeout** Timeout until mails are considered "didn't make it"

**disablefiledeletion** <false|true> Disables the mailexporters function to delete probing mails if filesystem access should be restricted to avoid spamming the log with warnings; defaults to false, i.e. detected probing mails are deleted, and can be ommitted if unneeded

SERVER-OPTIONS
==============

Expand Down

0 comments on commit 08bb6d2

Please sign in to comment.