diff --git a/slack.go b/slack.go index 5518965..888ab63 100644 --- a/slack.go +++ b/slack.go @@ -7,7 +7,7 @@ import ( slack "github.com/ashwanthkumar/slack-go-webhook" ) - +var notifications = make(map[string]int) // Slack consist of all the sub components required to use Slack API type Slack struct { Name string `json:"name"` @@ -20,15 +20,17 @@ type Slack struct { func (s Slack) Notify(results []Result) error { for _, result := range results { if !result.Healthy { - s.Send(result) + notifications[result.Title] = 1 + s.Send(result, "danger") + } else if notifications[result.Title] == 1 { + notifications[result.Title] = 0 + s.Send(result, "good") } } return nil } -// Send request via Slack API to create incident -func (s Slack) Send(result Result) error { - color := "danger" +func (s Slack) Send(result Result, color string) error { attach := slack.Attachment{} attach.AddField(slack.Field{Title: result.Title, Value: result.Endpoint}) attach.AddField(slack.Field{Title: "Status", Value: strings.ToUpper(fmt.Sprint(result.Status()))})