From a242f6be26a6b6df7688ebaab607f2ce150d4366 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Sun, 19 Feb 2023 08:48:30 -0500 Subject: [PATCH] Use same code to produce $SUMMARY and email subject --- monitor/discoveredcert.go | 6 +++--- monitor/healthcheck.go | 18 +++++++++--------- monitor/malformed.go | 6 +++--- monitor/notify.go | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/monitor/discoveredcert.go b/monitor/discoveredcert.go index f6c07d6..f53b399 100644 --- a/monitor/discoveredcert.go +++ b/monitor/discoveredcert.go @@ -83,7 +83,7 @@ func (cert *discoveredCert) save() error { func (cert *discoveredCert) Environ() []string { env := []string{ "EVENT=discovered_cert", - "SUMMARY=certificate discovered for " + cert.WatchItem.String(), + "SUMMARY=" + cert.Summary(), "CERT_PARSEABLE=yes", // backwards compat with pre-0.15.0; not documented "LOG_URI=" + cert.LogEntry.Log.URL, "ENTRY_INDEX=" + fmt.Sprint(cert.LogEntry.Index), @@ -165,6 +165,6 @@ func (cert *discoveredCert) Text() string { return text.String() } -func (cert *discoveredCert) EmailSubject() string { - return fmt.Sprintf("[certspotter] Certificate Discovered for %s", cert.WatchItem) +func (cert *discoveredCert) Summary() string { + return fmt.Sprintf("Certificate Discovered for %s", cert.WatchItem) } diff --git a/monitor/healthcheck.go b/monitor/healthcheck.go index daf530c..51d12ee 100644 --- a/monitor/healthcheck.go +++ b/monitor/healthcheck.go @@ -107,33 +107,33 @@ func (e *backlogEvent) Backlog() uint64 { func (e *staleSTHEvent) Environ() []string { return []string{ "EVENT=error", + "SUMMARY=" + e.Summary(), "TEXT_FILENAME=" + e.TextPath, - "SUMMARY=" + fmt.Sprintf("unable to contact %s since %s", e.Log.URL, e.LastSuccess), } } func (e *backlogEvent) Environ() []string { return []string{ "EVENT=error", + "SUMMARY=" + e.Summary(), "TEXT_FILENAME=" + e.TextPath, - "SUMMARY=" + fmt.Sprintf("backlog of size %d from %s", e.Backlog(), e.Log.URL), } } func (e *staleLogListEvent) Environ() []string { return []string{ "EVENT=error", + "SUMMARY=" + e.Summary(), "TEXT_FILENAME=" + e.TextPath, - "SUMMARY=" + fmt.Sprintf("unable to retrieve log list since %s: %s", e.LastSuccess, e.LastError), } } -func (e *staleSTHEvent) EmailSubject() string { - return fmt.Sprintf("[certspotter] Unable to contact %s since %s", e.Log.URL, e.LastSuccess) +func (e *staleSTHEvent) Summary() string { + return fmt.Sprintf("Unable to contact %s since %s", e.Log.URL, e.LastSuccess) } -func (e *backlogEvent) EmailSubject() string { - return fmt.Sprintf("[certspotter] Backlog of size %d from %s", e.Backlog(), e.Log.URL) +func (e *backlogEvent) Summary() string { + return fmt.Sprintf("Backlog of size %d from %s", e.Backlog(), e.Log.URL) } -func (e *staleLogListEvent) EmailSubject() string { - return fmt.Sprintf("[certspotter] Unable to retrieve log list since %s", e.LastSuccess) +func (e *staleLogListEvent) Summary() string { + return fmt.Sprintf("Unable to retrieve log list since %s", e.LastSuccess) } func (e *staleSTHEvent) Text() string { diff --git a/monitor/malformed.go b/monitor/malformed.go index b8a7efd..35cac00 100644 --- a/monitor/malformed.go +++ b/monitor/malformed.go @@ -44,7 +44,7 @@ func (malformed *malformedLogEntry) save() error { func (malformed *malformedLogEntry) Environ() []string { return []string{ "EVENT=malformed_cert", - "SUMMARY=" + fmt.Sprintf("unable to parse entry %d in %s", malformed.Entry.Index, malformed.Entry.Log.URL), + "SUMMARY=" + malformed.Summary(), "LOG_URI=" + malformed.Entry.Log.URL, "ENTRY_INDEX=" + fmt.Sprint(malformed.Entry.Index), "LEAF_HASH=" + malformed.Entry.LeafHash.Base64String(), @@ -67,6 +67,6 @@ func (malformed *malformedLogEntry) Text() string { return text.String() } -func (malformed *malformedLogEntry) EmailSubject() string { - return fmt.Sprintf("[certspotter] Unable to Parse Entry %d in %s", malformed.Entry.Index, malformed.Entry.Log.URL) +func (malformed *malformedLogEntry) Summary() string { + return fmt.Sprintf("Unable to Parse Entry %d in %s", malformed.Entry.Index, malformed.Entry.Log.URL) } diff --git a/monitor/notify.go b/monitor/notify.go index 2666355..d2194e5 100644 --- a/monitor/notify.go +++ b/monitor/notify.go @@ -23,7 +23,7 @@ var stdoutMu sync.Mutex type notification interface { Environ() []string - EmailSubject() string + Summary() string Text() string } @@ -58,7 +58,7 @@ func sendEmail(ctx context.Context, to []string, notif notification) error { stderr := new(bytes.Buffer) fmt.Fprintf(stdin, "To: %s\n", strings.Join(to, ", ")) - fmt.Fprintf(stdin, "Subject: %s\n", notif.EmailSubject()) + fmt.Fprintf(stdin, "Subject: [certspotter] %s\n", notif.Summary()) fmt.Fprintf(stdin, "Mime-Version: 1.0\n") fmt.Fprintf(stdin, "Content-Type: text/plain; charset=US-ASCII\n") fmt.Fprintf(stdin, "X-Mailer: certspotter\n")