Skip to content

Commit 17c66b5

Browse files
committed
improve notification layout
new and resolved issues in separate lists
1 parent d673869 commit 17c66b5

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

cmd/cmd_version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88

99
// TODO: insert automatically via build step?
1010
const (
11-
VERSION = "1.0.7"
12-
BUILDDATE = "2018-06-26T00:59:00+02"
11+
VERSION = "1.1.1"
12+
BUILDDATE = "2018-07-04T19:42:00+02"
1313
)
1414

1515
func init() {

core/healthchecks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ func (r CheckResult) EventID() string {
5555

5656
func (r CheckResult) String() string {
5757
if r.Status == CheckOk {
58-
return fmt.Sprintf("%s %s (on sensor %s (%s) with value %s)\n", r.Event, r.Status, r.TargetName, r.Target, r.Value)
58+
return fmt.Sprintf("%s: %s (on sensor %s (%s) with value %s)\n", r.Status, r.Event, r.TargetName, r.Target, r.Value)
5959
} else {
60-
return fmt.Sprintf("%s: %s"+"\n", r.Status, checkers[r.Event].toString(r))
60+
return fmt.Sprintf("%s: %s\n", r.Status, checkers[r.Event].toString(r))
6161
}
6262
}
6363

core/notifier_email.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,34 @@ func (n EmailNotifier) New(config interface{}) (AbstractNotifier, error) {
4747
}
4848

4949
func (n EmailNotifier) ComposeNotification(box *Box, checks []CheckResult) Notification {
50-
resultTexts := []string{}
50+
errTexts := []string{}
51+
resolvedTexts := []string{}
5152
for _, check := range checks {
52-
resultTexts = append(resultTexts, check.String())
53+
if check.Status == CheckErr {
54+
errTexts = append(errTexts, check.String())
55+
} else {
56+
resolvedTexts = append(resolvedTexts, check.String())
57+
}
58+
}
59+
60+
var (
61+
resolved string
62+
resolvedList string
63+
errList string
64+
)
65+
if len(resolvedTexts) != 0 {
66+
resolvedList = fmt.Sprintf("Resolved issue(s):\n\n%s\n\n", strings.Join(resolvedTexts, "\n"))
67+
}
68+
if len(errTexts) != 0 {
69+
errList = fmt.Sprintf("New issue(s):\n\n%s\n\n", strings.Join(errTexts, "\n"))
70+
} else {
71+
resolved = "resolved "
5372
}
5473

5574
return Notification{
56-
Subject: fmt.Sprintf("Issues with your box \"%s\" on opensensemap.org!", box.Name),
57-
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)",
58-
time.Now().Round(time.Minute), box.Name, strings.Join(resultTexts, "\n"), box.Id),
75+
Subject: fmt.Sprintf("Issues %swith your box \"%s\" on opensensemap.org!", resolved, box.Name),
76+
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)",
77+
time.Now().Round(time.Minute), box.Name, errList, resolvedList, box.Id),
5978
}
6079
}
6180

0 commit comments

Comments
 (0)