generated from broadinstitute/golang-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_change.go
49 lines (44 loc) · 1.27 KB
/
send_change.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
package pagerduty
import (
"context"
"github.com/PagerDuty/go-pagerduty"
"github.com/broadinstitute/sherlock/internal/config"
"github.com/rs/zerolog/log"
"time"
)
func SendChange(integrationKey string, summary string, sourceLink string) error {
summaryText := summary
if len(summaryText) > 1024 {
summaryText = summaryText[:1024]
}
if config.Config.Bool("pagerduty.enable") {
ctx := context.Background()
log.Info().Msgf("PDTY | sending change '%s' due to pagerduty.enable = true", summaryText)
event := pagerduty.ChangeEvent{
RoutingKey: integrationKey,
Payload: pagerduty.ChangeEventPayload{
Summary: summaryText,
Source: sourceLink,
Timestamp: time.Now().Format(time.RFC3339),
},
Links: []pagerduty.ChangeEventLink{
{
Href: sourceLink,
Text: "Beehive Link",
},
},
}
_, err := client.CreateChangeEventWithContext(ctx, event)
recordMetrics(ctx, "change", err)
return err
} else {
log.Info().Msgf("PDTY | not sending change '%s' due to pagerduty.enable = false", summaryText)
return nil
}
}
func SendChangeSwallowErrors(integrationKey string, summary string, sourceLink string) {
err := SendChange(integrationKey, summary, sourceLink)
if err != nil {
log.Warn().Msgf("PDTY | error sending change: %v", err)
}
}