Merge branch 'feat/slack' into custom

# Conflicts:
#	cli/main.go
This commit is contained in:
Christoph Eck
2020-01-27 16:15:33 +01:00
10 changed files with 167 additions and 7 deletions

View File

@@ -93,7 +93,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
}
@@ -136,3 +139,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)
}
}