Skip to content

Commit

Permalink
improve notification layout
Browse files Browse the repository at this point in the history
new and resolved issues in separate lists
  • Loading branch information
noerw committed Jul 4, 2018
1 parent d673869 commit 17c66b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions cmd/cmd_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions core/healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
29 changes: 24 additions & 5 deletions core/notifier_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down

0 comments on commit 17c66b5

Please sign in to comment.