From 17c66b51002993b6797ca10f585ee8b40320a4c0 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Wed, 4 Jul 2018 19:43:20 +0200 Subject: [PATCH] improve notification layout new and resolved issues in separate lists --- cmd/cmd_version.go | 4 ++-- core/healthchecks.go | 4 ++-- core/notifier_email.go | 29 ++++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/cmd/cmd_version.go b/cmd/cmd_version.go index e59b1a2..53252eb 100644 --- a/cmd/cmd_version.go +++ b/cmd/cmd_version.go @@ -8,8 +8,8 @@ import ( // TODO: insert automatically via build step? const ( - VERSION = "1.0.7" - BUILDDATE = "2018-06-26T00:59:00+02" + VERSION = "1.1.1" + BUILDDATE = "2018-07-04T19:42:00+02" ) func init() { diff --git a/core/healthchecks.go b/core/healthchecks.go index 36792cb..6192b68 100644 --- a/core/healthchecks.go +++ b/core/healthchecks.go @@ -55,9 +55,9 @@ func (r CheckResult) EventID() string { func (r CheckResult) String() string { if r.Status == CheckOk { - return fmt.Sprintf("%s %s (on sensor %s (%s) with value %s)\n", r.Event, r.Status, r.TargetName, r.Target, r.Value) + return fmt.Sprintf("%s: %s (on sensor %s (%s) with value %s)\n", r.Status, r.Event, r.TargetName, r.Target, r.Value) } else { - return fmt.Sprintf("%s: %s"+"\n", r.Status, checkers[r.Event].toString(r)) + return fmt.Sprintf("%s: %s\n", r.Status, checkers[r.Event].toString(r)) } } diff --git a/core/notifier_email.go b/core/notifier_email.go index fdc7a0f..1ba2eab 100644 --- a/core/notifier_email.go +++ b/core/notifier_email.go @@ -47,15 +47,34 @@ func (n EmailNotifier) New(config interface{}) (AbstractNotifier, error) { } func (n EmailNotifier) ComposeNotification(box *Box, checks []CheckResult) Notification { - resultTexts := []string{} + errTexts := []string{} + resolvedTexts := []string{} for _, check := range checks { - resultTexts = append(resultTexts, check.String()) + if check.Status == CheckErr { + errTexts = append(errTexts, check.String()) + } else { + resolvedTexts = append(resolvedTexts, check.String()) + } + } + + var ( + resolved string + resolvedList string + errList string + ) + if len(resolvedTexts) != 0 { + resolvedList = fmt.Sprintf("Resolved issue(s):\n\n%s\n\n", strings.Join(resolvedTexts, "\n")) + } + if len(errTexts) != 0 { + errList = fmt.Sprintf("New issue(s):\n\n%s\n\n", strings.Join(errTexts, "\n")) + } else { + resolved = "resolved " } return Notification{ - Subject: fmt.Sprintf("Issues with your box \"%s\" on opensensemap.org!", box.Name), - Body: fmt.Sprintf("A check at %s identified the following issue(s) with your box %s:\n\n%s\n\nYou may visit https://opensensemap.org/explore/%s for more details.\n\n--\nSent automatically by osem_notify (https://github.com/noerw/osem_notify)", - time.Now().Round(time.Minute), box.Name, strings.Join(resultTexts, "\n"), box.Id), + Subject: fmt.Sprintf("Issues %swith your box \"%s\" on opensensemap.org!", resolved, box.Name), + Body: fmt.Sprintf("A check at %s identified the following updates for your box \"%s\":\n\n%s%sYou may visit https://opensensemap.org/explore/%s for more details.\n\n--\nSent automatically by osem_notify (https://github.com/noerw/osem_notify)", + time.Now().Round(time.Minute), box.Name, errList, resolvedList, box.Id), } }