Merge branch 'feat/slack' into custom
# Conflicts: # cli/main.go
This commit is contained in:
32
incident.go
32
incident.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user