Skip to content

Commit 1feb8a5

Browse files
authored
Add PagerDuty integration platform (#1446)
1 parent cced671 commit 1feb8a5

File tree

11 files changed

+551
-12
lines changed

11 files changed

+551
-12
lines changed

cmd/botkube-agent/main.go

+8
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,14 @@ func run(ctx context.Context) (err error) {
328328

329329
sinkNotifiers = append(sinkNotifiers, wh)
330330
}
331+
if commGroupCfg.PagerDuty.Enabled {
332+
pd, err := sink.NewPagerDuty(commGroupLogger.WithField(sinkLogFieldKey, "PagerDuty"), commGroupMeta.Index, commGroupCfg.PagerDuty, conf.Settings.ClusterName, analyticsReporter)
333+
if err != nil {
334+
return reportFatalError("while creating PagerDuty sink", err)
335+
}
336+
337+
sinkNotifiers = append(sinkNotifiers, pd)
338+
}
331339
}
332340
healthChecker.SetNotifiers(getHealthNotifiers(bots, sinkNotifiers))
333341

go.mod

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/DanielTitkov/go-adaptive-cards v0.2.2
88
github.com/MakeNowJust/heredoc v1.0.0
99
github.com/Masterminds/semver/v3 v3.2.1
10+
github.com/PagerDuty/go-pagerduty v1.8.0
1011
github.com/alexflint/go-arg v1.4.3
1112
github.com/avast/retry-go/v4 v4.3.3
1213
github.com/aws/aws-sdk-go v1.44.122
@@ -15,7 +16,7 @@ require (
1516
github.com/charmbracelet/log v0.2.2
1617
github.com/denisbrodbeck/machineid v1.0.1
1718
github.com/dustin/go-humanize v1.0.1
18-
github.com/fatih/color v1.15.0
19+
github.com/fatih/color v1.16.0
1920
github.com/go-playground/locales v0.14.1
2021
github.com/go-playground/universal-translator v0.18.1
2122
github.com/go-playground/validator/v10 v10.14.0
@@ -43,6 +44,7 @@ require (
4344
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
4445
github.com/pkg/errors v0.9.1
4546
github.com/prometheus/client_golang v1.16.0
47+
github.com/prometheus/common v0.44.0
4648
github.com/r3labs/diff/v3 v3.0.1
4749
github.com/sanity-io/litter v1.5.5
4850
github.com/segmentio/analytics-go v3.1.0+incompatible
@@ -214,7 +216,6 @@ require (
214216
github.com/philhofer/fwd v1.1.2 // indirect
215217
github.com/pmezard/go-difflib v1.0.0 // indirect
216218
github.com/prometheus/client_model v0.4.0 // indirect
217-
github.com/prometheus/common v0.44.0 // indirect
218219
github.com/prometheus/procfs v0.10.1 // indirect
219220
github.com/rivo/uniseg v0.4.4 // indirect
220221
github.com/rogpeppe/go-internal v1.11.0 // indirect
@@ -223,7 +224,7 @@ require (
223224
github.com/segmentio/backo-go v0.0.0-20200129164019-23eae7c10bd3 // indirect
224225
github.com/sergi/go-diff v1.3.1 // indirect
225226
github.com/shopspring/decimal v1.3.1 // indirect
226-
github.com/spf13/cast v1.5.0 // indirect
227+
github.com/spf13/cast v1.6.0 // indirect
227228
github.com/tinylib/msgp v1.1.8 // indirect
228229
github.com/ulikunitz/xz v0.5.10 // indirect
229230
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect

go.sum

+8-6
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYx
224224
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
225225
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
226226
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
227+
github.com/PagerDuty/go-pagerduty v1.8.0 h1:MTFqTffIcAervB83U7Bx6HERzLbyaSPL/+oxH3zyluI=
228+
github.com/PagerDuty/go-pagerduty v1.8.0/go.mod h1:nzIeAqyFSJAFkjWKvMzug0JtwDg+V+UoCWjFrfFH5mI=
227229
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
228230
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
229231
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d h1:UrqY+r/OJnIp5u0s1SbQ8dVfLCZJsnvazdBP5hS4iRs=
@@ -400,8 +402,8 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZM
400402
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
401403
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
402404
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
403-
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
404-
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
405+
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
406+
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
405407
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
406408
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
407409
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
@@ -413,8 +415,8 @@ github.com/foxcpp/go-mockdns v1.0.0 h1:7jBqxd3WDWwi/6WhDvacvH1XsN3rOLXyHM1uhvIx6
413415
github.com/foxcpp/go-mockdns v1.0.0/go.mod h1:lgRN6+KxQBawyIghpnl5CezHFGS9VLzvtVlwxvzXTQ4=
414416
github.com/francoispqt/gojay v1.2.13 h1:d2m3sFjloqoIUQU3TsHBgj6qg/BVGlTBeHDUmyJnXKk=
415417
github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiDsoyrBGkyDY=
416-
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
417-
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
418+
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
419+
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
418420
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
419421
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
420422
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
@@ -1074,8 +1076,8 @@ github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIK
10741076
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA=
10751077
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
10761078
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
1077-
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
1078-
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
1079+
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
1080+
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
10791081
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
10801082
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
10811083
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=

internal/source/scheduler.go

+6
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ func (d *Scheduler) generateConfigs(ctx context.Context) error {
224224
}
225225
}
226226
}
227+
228+
if commGroupCfg.PagerDuty.Enabled {
229+
if err := d.generateSourceConfigs(ctx, false, commGroupCfg.PagerDuty.Bindings.Sources); err != nil {
230+
return err
231+
}
232+
}
227233
}
228234

229235
// Schedule all sources used by actions

pkg/config/config.go

+16
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ const (
102102

103103
// WebhookCommPlatformIntegration defines an outgoing webhook integration.
104104
WebhookCommPlatformIntegration CommPlatformIntegration = "webhook"
105+
106+
// PagerDutyCommPlatformIntegration defines an outgoing PagerDuty integration.
107+
PagerDutyCommPlatformIntegration CommPlatformIntegration = "pagerDuty"
105108
)
106109

107110
func (c CommPlatformIntegration) IsInteractive() bool {
@@ -482,6 +485,7 @@ type Communications struct {
482485
CloudTeams CloudTeams `yaml:"cloudTeams,omitempty"`
483486
Webhook Webhook `yaml:"webhook,omitempty"`
484487
Elasticsearch Elasticsearch `yaml:"elasticsearch,omitempty"`
488+
PagerDuty PagerDuty `yaml:"pagerDuty,omitempty"`
485489
}
486490

487491
// SocketSlack configuration to authentication and send notifications
@@ -594,6 +598,18 @@ type Webhook struct {
594598
Bindings SinkBindings `yaml:"bindings" validate:"required_if=Enabled true"`
595599
}
596600

601+
// PagerDuty describes the PagerDuty sink.
602+
type PagerDuty struct {
603+
// Enabled indicates if the PagerDuty sink is enabled.
604+
Enabled bool `yaml:"enabled"`
605+
// Bindings are the bindings for the PagerDuty sink.
606+
Bindings SinkBindings `yaml:"bindings" validate:"required_if=Enabled true"`
607+
// IntegrationKey is the PagerDuty integration key generated for Events v2 API.
608+
IntegrationKey string `yaml:"integrationKey" validate:"required_if=Enabled true"`
609+
// V2EventsAPIBasePath is the Events v2 API URL base path. Defaults to https://events.pagerduty.com.
610+
V2EventsAPIBasePath string
611+
}
612+
597613
// CfgWatcher describes configuration for watching the configuration.
598614
type CfgWatcher struct {
599615
Enabled bool `yaml:"enabled"`

pkg/plugin/collector.go

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ func (c *Collector) GetAllEnabledAndUsedPlugins(cfg *config.Config) ([]string, [
7777
}
7878
}
7979
}
80+
81+
if commGroupCfg.PagerDuty.Enabled {
82+
for _, name := range commGroupCfg.PagerDuty.Bindings.Sources {
83+
boundSources[name] = struct{}{}
84+
}
85+
}
8086
}
8187

8288
// Collect all used executors/sources by actions

0 commit comments

Comments
 (0)