|
|
@@ -11,7 +11,6 @@ import (
|
|
|
"github.com/porter-dev/porter/api/types"
|
|
|
porter_agent "github.com/porter-dev/porter/internal/kubernetes/porter_agent/v2"
|
|
|
"github.com/porter-dev/porter/internal/models/integrations"
|
|
|
- goslack "github.com/slack-go/slack"
|
|
|
)
|
|
|
|
|
|
type IncidentsNotifier struct {
|
|
|
@@ -45,7 +44,7 @@ func (s *IncidentsNotifier) NotifyNew(incident *porter_agent.Incident, url strin
|
|
|
getMarkdownBlock(fmt.Sprintf("*Namespace:* %s", "`"+namespace+"`")),
|
|
|
getMarkdownBlock(fmt.Sprintf("*Name:* %s", "`"+incident.ReleaseName+"`")),
|
|
|
getMarkdownBlock(fmt.Sprintf(
|
|
|
- "*Created at:* <!date^%d^Alerted at {date_num} {time_secs}|Alerted at %s>",
|
|
|
+ "*Created at:* <!date^%d^ {date_num} {time_secs}| %s>",
|
|
|
createdAt.Unix(),
|
|
|
createdAt.Format("2006-01-02 15:04:05 UTC"),
|
|
|
)),
|
|
|
@@ -79,7 +78,7 @@ func (s *IncidentsNotifier) NotifyNew(incident *porter_agent.Incident, url strin
|
|
|
}
|
|
|
|
|
|
func (s *IncidentsNotifier) NotifyResolved(incident *porter_agent.Incident, url string) error {
|
|
|
- blockSet := &goslack.Blocks{}
|
|
|
+ res := []*SlackBlock{}
|
|
|
|
|
|
namespace := strings.Split(incident.ID, ":")[2]
|
|
|
createdAt := time.Unix(incident.CreatedAt, 0).UTC()
|
|
|
@@ -91,40 +90,41 @@ func (s *IncidentsNotifier) NotifyResolved(incident *porter_agent.Incident, url
|
|
|
url,
|
|
|
)
|
|
|
|
|
|
- blockSet.BlockSet = append(blockSet.BlockSet, goslack.NewTextBlockObject(
|
|
|
- goslack.MarkdownType, topSectionMarkdwn, false, false,
|
|
|
- ), goslack.NewDividerBlock(), goslack.NewTextBlockObject(
|
|
|
- goslack.MarkdownType,
|
|
|
- fmt.Sprintf("*Name:* %s", "`"+incident.ReleaseName+"`"),
|
|
|
- false, false,
|
|
|
- ), goslack.NewTextBlockObject(
|
|
|
- goslack.MarkdownType,
|
|
|
- fmt.Sprintf("*Namespace:* %s", "`"+namespace+"`"),
|
|
|
- false, false,
|
|
|
- ), goslack.NewTextBlockObject(
|
|
|
- goslack.MarkdownType,
|
|
|
- fmt.Sprintf(
|
|
|
+ res = append(
|
|
|
+ res,
|
|
|
+ getMarkdownBlock(topSectionMarkdwn),
|
|
|
+ getDividerBlock(),
|
|
|
+ getMarkdownBlock(fmt.Sprintf("*Namespace:* %s", "`"+namespace+"`")),
|
|
|
+ getMarkdownBlock(fmt.Sprintf("*Name:* %s", "`"+incident.ReleaseName+"`")),
|
|
|
+ getMarkdownBlock(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"),
|
|
|
- ),
|
|
|
- false, false,
|
|
|
- ), goslack.NewTextBlockObject(
|
|
|
- goslack.MarkdownType,
|
|
|
- fmt.Sprintf(
|
|
|
- "*Resolved at:* <!date^%d^Alerted at {date_num} {time_secs}|Alerted at %s>",
|
|
|
+ )),
|
|
|
+ getMarkdownBlock(fmt.Sprintf(
|
|
|
+ "*Resolved at:* <!date^%d^ {date_num} {time_secs}| %s>",
|
|
|
resolvedAt.Unix(),
|
|
|
resolvedAt.Format("2006-01-02 15:04:05 UTC"),
|
|
|
- ),
|
|
|
- false, false,
|
|
|
- ))
|
|
|
+ )),
|
|
|
+ )
|
|
|
+
|
|
|
+ slackPayload := &SlackPayload{
|
|
|
+ Blocks: res,
|
|
|
+ }
|
|
|
+
|
|
|
+ payload, err := json.Marshal(slackPayload)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ reqBody := bytes.NewReader(payload)
|
|
|
+ client := &http.Client{
|
|
|
+ Timeout: time.Second * 5,
|
|
|
+ }
|
|
|
|
|
|
for _, slackInt := range s.slackInts {
|
|
|
- err := goslack.PostWebhook(string(slackInt.Webhook), &goslack.WebhookMessage{
|
|
|
- Username: "Porter Agent",
|
|
|
- Channel: slackInt.Channel,
|
|
|
- Blocks: blockSet,
|
|
|
- })
|
|
|
+ _, err := client.Post(string(slackInt.Webhook), "application/json", reqBody)
|
|
|
|
|
|
if err != nil {
|
|
|
return err
|