Skip to content

Commit

Permalink
feat: add uptime and latency to check in notification template
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Sep 7, 2023
1 parent 30d3aca commit 7f73827
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions events/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/flanksource/commons/template"
"github.com/flanksource/commons/utils"
"github.com/flanksource/duty"
"github.com/flanksource/duty/models"
"github.com/flanksource/incident-commander/api"
pkgNotification "github.com/flanksource/incident-commander/notification"
Expand Down Expand Up @@ -352,6 +353,8 @@ func getEnvForEvent(ctx *api.Context, eventName string, properties map[string]st
env := make(map[string]any)

if strings.HasPrefix(eventName, "check.") {
checkID := properties["id"]

var check models.Check
if err := ctx.DB().Where("id = ?", properties["id"]).Find(&check).Error; err != nil {
return nil, err
Expand All @@ -362,6 +365,14 @@ func getEnvForEvent(ctx *api.Context, eventName string, properties map[string]st
return nil, err
}

summary, err := duty.CheckSummary(ctx, checkID)
if err != nil {
return nil, err
} else if summary != nil {
check.Uptime = summary.Uptime
check.Latency = summary.Latency
}

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

0 comments on commit 7f73827

Please sign in to comment.