forked from AcalephStorage/consul-alerts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pagerduty-notifier.go
50 lines (41 loc) · 1.38 KB
/
pagerduty-notifier.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package notifier
import (
"github.com/AcalephStorage/consul-alerts/Godeps/_workspace/src/github.com/darkcrux/gopherduty"
log "github.com/AcalephStorage/consul-alerts/Godeps/_workspace/src/github.com/Sirupsen/logrus"
)
type PagerDutyNotifier struct {
ServiceKey string
ClientName string
ClientUrl string
}
func (pd *PagerDutyNotifier) Notify(messages Messages) bool {
client := gopherduty.NewClient(pd.ServiceKey)
result := true
for _, message := range messages {
incidentKey := message.Node
if message.ServiceId != "" {
incidentKey += ":" + message.ServiceId
}
incidentKey += ":" + message.CheckId
var response *gopherduty.PagerDutyResponse
switch {
case message.IsPassing():
description := incidentKey + " is now HEALTHY"
response = client.Resolve(incidentKey, description, message)
case message.IsWarning():
description := incidentKey + " is UNSTABLE"
response = client.Trigger(incidentKey, description, pd.ClientName, pd.ClientUrl, message)
case message.IsCritical():
description := incidentKey + " is CRITICAL"
response = client.Trigger(incidentKey, description, pd.ClientName, pd.ClientUrl, message)
}
if response.HasErrors() {
for _, err := range response.Errors {
log.Printf("Error sending %s notification to pagerduty: %s\n", incidentKey, err)
}
result = false
}
}
log.Println("PagerDuty notification complete")
return result
}