Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: default title and body for notifications #535

Merged
merged 16 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions events/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (t *NotificationEventProperties) FromMap(m map[string]string) {

// 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}}<br />{{end}}{{end}}", field, field)
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
Expand All @@ -107,19 +107,19 @@ func defaultTitleAndBody(event string) (title string, body string) {
switch event {
case EventCheckPassed:
title = "Check {{.check.name}} has passed"
body = fmt.Sprintf("%s\n[Reference]({{.permalink}})", labelsTemplate(".check.labels"))
body = fmt.Sprintf("%s\nCanary: {{.canary.name}} \nAgent: {{.agent.name}}\n\n[Reference]({{.permalink}})", labelsTemplate(".check.labels"))

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

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

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

case EventIncidentCreated:
title = "{{.incident.incident_id}}: {{.incident.title}} ({{.incident.severity}}) created"
Expand Down Expand Up @@ -378,8 +378,14 @@ func getEnvForEvent(ctx *api.Context, eventName string, properties map[string]st
check.Latency = summary.Latency
}

var agent models.Agent
if err := ctx.DB().Where("id = ?", check.AgentID).First(&agent).Error; err != nil {
adityathebe marked this conversation as resolved.
Show resolved Hide resolved
return nil, err
}

env["canary"] = canary.AsMap()
env["check"] = check.AsMap()
env["agent"] = agent.AsMap()
env["permalink"] = fmt.Sprintf("%s/health?layout=table&checkId=%s&timeRange=1h", api.PublicWebURL, check.ID)
}

Expand Down
32 changes: 16 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ require (
github.com/containrrr/shoutrrr v0.8.0
github.com/fergusstrange/embedded-postgres v1.23.0
github.com/flanksource/commons v1.11.0
github.com/flanksource/duty v1.0.170
github.com/flanksource/duty v1.0.171
github.com/flanksource/gomplate/v3 v3.20.12
github.com/flanksource/kopper v1.0.6
github.com/gomarkdown/markdown v0.0.0-20230716120725-531d2d74bc12
github.com/google/cel-go v0.17.6
github.com/google/cel-go v0.18.0
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.1
github.com/jackc/pgx/v5 v5.4.3
Expand All @@ -40,7 +40,7 @@ require (
)

require (
ariga.io/atlas v0.13.3 // indirect
ariga.io/atlas v0.14.0 // indirect
cloud.google.com/go/compute v1.23.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v1.1.2 // indirect
Expand Down Expand Up @@ -72,7 +72,7 @@ require (
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/pprof v0.0.0-20230323073829-e72429f035bd // indirect
github.com/google/s2a-go v0.1.5 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.5 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/hairyhenderson/yaml v0.0.0-20220618171115-2d35fca545ce // indirect
Expand Down Expand Up @@ -107,10 +107,10 @@ require (
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/tools v0.13.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
Expand All @@ -125,7 +125,7 @@ require (
k8s.io/apiextensions-apiserver v0.27.4 // indirect
k8s.io/component-base v0.27.4 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230831192431-0d7b43eda7ba // indirect
k8s.io/kube-openapi v0.0.0-20230905202853-d090da108d2f // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
layeh.com/gopher-json v0.0.0-20201124131017-552bb3c4c3bf // indirect
modernc.org/libc v1.24.1 // indirect
Expand All @@ -143,8 +143,8 @@ require (
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/TomOnTime/utfutil v0.0.0-20230223141146-125e65197b36
github.com/antonmedv/expr v1.15.0 // indirect
github.com/aws/aws-sdk-go v1.45.1 // indirect
github.com/antonmedv/expr v1.15.1 // indirect
github.com/aws/aws-sdk-go v1.45.4 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/cjlapao/common-go v0.0.39 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down Expand Up @@ -205,17 +205,17 @@ require (
go.opencensus.io v0.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/crypto v0.12.0
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/crypto v0.13.0
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.138.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/grpc v1.58.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading
Loading