Przeglądaj źródła

update incident styling for resolved incidents

Alexander Belanger 4 lat temu
rodzic
commit
e794a7a9f7
1 zmienionych plików z 40 dodań i 12 usunięć
  1. 40 12
      internal/integrations/slack/incidents_notifier.go

+ 40 - 12
internal/integrations/slack/incidents_notifier.go

@@ -95,32 +95,60 @@ func (s *IncidentsNotifier) NotifyNew(incident *porter_agent.Incident, url strin
 func (s *IncidentsNotifier) NotifyResolved(incident *porter_agent.Incident, url string) error {
 	blockSet := &goslack.Blocks{}
 
+	topSectionMarkdwn := fmt.Sprintf(
+		":white_check_mark: The incident for application %s has been resolved. <%s|View the incident.>",
+		"`"+incident.ReleaseName+"`",
+		url,
+	)
+
 	blockSet.BlockSet = append(blockSet.BlockSet, goslack.NewSectionBlock(
 		goslack.NewTextBlockObject(
-			"plain_text", "✅ Incident resolved for your Porter application", true, false,
+			"mrkdwn", topSectionMarkdwn, true, false,
 		), nil, nil,
 	))
 
 	namespace := strings.Split(incident.ID, ":")[2]
-	createdAt := time.Unix(incident.CreatedAt, 0).UTC().Format(time.RFC850)
-	resolvedAt := time.Unix(incident.UpdatedAt, 0).UTC().Format(time.RFC850)
+	createdAt := time.Unix(incident.CreatedAt, 0).UTC()
+	resolvedAt := time.Unix(incident.UpdatedAt, 0).UTC()
+
+	blockSet.BlockSet = append(blockSet.BlockSet, goslack.NewContextBlock(
+		"", goslack.NewTextBlockObject(
+			"mrkdwn",
+			fmt.Sprintf("*Name:* %s", "`"+incident.ReleaseName+"`"),
+			false, false,
+		),
+	))
 
 	blockSet.BlockSet = append(blockSet.BlockSet, goslack.NewContextBlock(
 		"", goslack.NewTextBlockObject(
-			"plain_text",
-			fmt.Sprintf("Release: %s\nNamespace: %s\nCreated at: %s\nResolved at: %s", incident.ReleaseName, namespace, createdAt, resolvedAt),
+			"mrkdwn",
+			fmt.Sprintf("*Namespace:* %s", "`"+namespace+"`"),
 			false, false,
 		),
 	))
 
-	blockSet.BlockSet = append(blockSet.BlockSet, goslack.NewActionBlock(
-		"", &goslack.ButtonBlockElement{
-			Type: goslack.METButton,
-			Text: goslack.NewTextBlockObject(
-				"plain_text", "View Incident", false, false,
+	blockSet.BlockSet = append(blockSet.BlockSet, goslack.NewContextBlock(
+		"", goslack.NewTextBlockObject(
+			"mrkdwn",
+			fmt.Sprintf(
+				"*Created at:* <!date^%d^Alerted at {date_num} {time_secs}|Alerted at %s>",
+				createdAt.Unix(),
+				createdAt.Format("2006-01-02 15:04:05 UTC"),
 			),
-			URL: url,
-		},
+			false, false,
+		),
+	))
+
+	blockSet.BlockSet = append(blockSet.BlockSet, goslack.NewContextBlock(
+		"", goslack.NewTextBlockObject(
+			"mrkdwn",
+			fmt.Sprintf(
+				"*Resolved at:* <!date^%d^Alerted at {date_num} {time_secs}|Alerted at %s>",
+				resolvedAt.Unix(),
+				resolvedAt.Format("2006-01-02 15:04:05 UTC"),
+			),
+			false, false,
+		),
 	))
 
 	for _, slackInt := range s.slackInts {