Skip to content

Commit

Permalink
feat: display labels for checks and components in default notification
Browse files Browse the repository at this point in the history
message
  • Loading branch information
adityathebe committed Sep 7, 2023
1 parent 7f73827 commit 6c8af47
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions events/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,30 @@ func (t *NotificationEventProperties) FromMap(m map[string]string) {
_ = json.Unmarshal(b, &t)
}

// labelsTemplate is a helper func to generate the template for displaying labels
func labelsTemplate(field string) string {
return fmt.Sprintf("{{if %s}}**Labels**:\n{{range $k, $v := %s}}`{{$k}}={{$v}}`\n{{end}}{{end}}", field, field)
}

// defaultTitleAndBody returns the default title and body for notification
// based on the given event.
func defaultTitleAndBody(event string) (title string, body string) {
switch event {
case EventCheckPassed:
title = "Check {{.check.name}} has passed"
body = "[Reference]({{.permalink}})"
body = fmt.Sprintf("%s[Reference]({{.permalink}})", labelsTemplate(".check.labels"))

case EventCheckFailed:
title = "Check {{.check.name}} has failed"
body = "[Reference]({{.permalink}})"
body = fmt.Sprintf("%s[Reference]({{.permalink}})", labelsTemplate(".check.labels"))

case EventComponentStatusHealthy, EventComponentStatusUnhealthy, EventComponentStatusInfo, EventComponentStatusWarning, EventComponentStatusError:
title = "Component {{.component.name}} status updated to {{.component.status}}"
body = "Component {{.component.name}} status updated to {{.component.status}}\n\n[Reference]({{.permalink}})"
body = fmt.Sprintf("%s[Reference]({{.permalink}})", labelsTemplate(".component.labels"))

case EventIncidentCommentAdded:
title = "{{.author.name}} left a comment on {{.incident.incident_id}}: {{.incident.title}}"
body = "{{.comment.comment}}\n\n[Reference]({{.permalink}})"
body = fmt.Sprintf("%s[Reference]({{.permalink}})", labelsTemplate(".component.labels"))

case EventIncidentCreated:
title = "{{.incident.incident_id}}: {{.incident.title}} ({{.incident.severity}}) created"
Expand Down

0 comments on commit 6c8af47

Please sign in to comment.