Add slack

This commit is contained in:
Mac Chiang
2019-12-18 11:54:43 +08:00
parent df31238a1f
commit 43510e18e2
8 changed files with 126 additions and 7 deletions

View File

@@ -67,7 +67,10 @@ func (incident *Incident) Send(cfg *CachetMonitor) error {
if resp.StatusCode != 200 {
return fmt.Errorf("Could not create/update incident!")
}
// send slack message
if cfg.SlackWebhook !="" {
sendSlack(cfg)
}
return nil
}
@@ -110,3 +113,30 @@ func (incident *Incident) SetWatching() {
func (incident *Incident) SetFixed() {
incident.Status = 4
}
// Send slack message
func (incident *Incident) sendSlack(cfg *CachetMonitor) {
color:="#bf1932" //red
if incident.ComponentStatus == 1 {
color="#36a64f" //green
}
slack := Slack{
WebhookUrl: cfg.SlackWebhook
Attachments: []Attachments{
Attachments{
Fallback: incident.Name,
Color: color,
Title: incident.Name,
TitleLink: "https://status.easyship.com",
Text: incident.Message,
Footer: "Cachet Monitor",
FooterIcon: "https://i.imgur.com/spck1w6.png",
Ts: time.Now().Unix(),
},
}}
err := slack.SendSlackNotification()
if err != nil {
fmt.Errorf(err)
}
}