Просмотр исходного кода

add timestamp option to slack alerts for jobs

Alexander Belanger 4 лет назад
Родитель
Сommit
b7547ecd30
2 измененных файлов с 12 добавлено и 0 удалено
  1. 1 0
      api/server/handlers/kube_events/create.go
  2. 11 0
      internal/integrations/slack/notifier.go

+ 1 - 0
api/server/handlers/kube_events/create.go

@@ -169,6 +169,7 @@ func notifyPodCrashing(
 			Name:        jobOwner,
 			Namespace:   event.Namespace,
 			Info:        fmt.Sprintf("%s", jobMsg),
+			Timestamp:   &event.Timestamp,
 			URL: fmt.Sprintf(
 				"%s/jobs/%s/%s/%s?project_id=%d",
 				config.ServerConf.ServerURL,

+ 11 - 0
internal/integrations/slack/notifier.go

@@ -49,6 +49,8 @@ type NotifyOpts struct {
 
 	URL string
 
+	Timestamp *time.Time
+
 	Version int
 }
 
@@ -151,6 +153,15 @@ func getSlackBlocks(opts *NotifyOpts) ([]*SlackBlock, []*SlackBlock) {
 		getMarkdownBlock(fmt.Sprintf("*Namespace:* %s", "`"+opts.Namespace+"`")),
 	)
 
+	if opts.Timestamp != nil {
+		res = append(res, getMarkdownBlock(fmt.Sprintf(
+			"*Timestamp:* <!date^%d^Alerted at {date_num} {time_secs}|Alerted at %s>",
+			opts.Timestamp.Unix(),
+			opts.Timestamp.Format("2006-01-02 15:04:05 UTC"),
+		)),
+		)
+	}
+
 	if opts.Status == StatusHelmDeployed || opts.Status == StatusHelmFailed {
 		res = append(res, getMarkdownBlock(fmt.Sprintf("*Version:* %d", opts.Version)))
 	}