Skip to content

Commit 24775f3

Browse files
authored
Merge pull request #24 from nsmith5/outputs/pagerduty
outputs: add Pager Duty support
2 parents dd756e3 + 3658746 commit 24775f3

File tree

5 files changed

+113
-4
lines changed

5 files changed

+113
-4
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ outputs:
171171
+ enabled: true
172172
```
173173

174-
**cloudevents**
174+
**Cloud Events**
175175

176-
The `cloudevents` driver emits [cloud events](https://cloudevents.io). An example
177-
of how to configure this output is below.
176+
The `cloudevents` driver emits [cloud events](https://cloudevents.io). An
177+
example of how to configure this output is below.
178178

179179
```diff
180180
outputs:
@@ -187,4 +187,25 @@ outputs:
187187
The `sourceID` fields configures the event source. The resulting event source
188188
in this case would be `github.com/nsmith5/rekor-sidekick:instance-a`. The event
189189
type is `rekor-sidekick.policy.violation.v1`. The `http.url` field configures
190-
an HTTP destination for your emitted events.
190+
an HTTP destination for your emitted events.
191+
192+
**Pager Duty**
193+
194+
The `pagerduty` driver emits [Pager Duty](https://pagerduty.com) events. To
195+
configure Rekor Sidekick to alert to Pager Duty you'll need
196+
197+
- An _API token_. This ca be fetched at _Integrations_ > _API Access keys_.
198+
- An _Integration Key_. This ca be fetched at _Automation_ > _Event Rules_ >
199+
_Your rule set_ > _View_ > _Integration Key_
200+
201+
Configure the driver as follows:
202+
203+
```diff
204+
outputs:
205+
+ pagerduty:
206+
+ apitoken: << api token >>
207+
+ integrationKey: << integration key >>
208+
+ severity: error
209+
```
210+
211+
The severity can be one of `critical`, `warning`, `error`, or `info`.

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/nsmith5/rekor-sidekick
33
go 1.17
44

55
require (
6+
github.com/PagerDuty/go-pagerduty v1.4.3
67
github.com/cloudevents/sdk-go/v2 v2.8.0
78
github.com/mitchellh/mapstructure v1.4.3
89
github.com/oklog/run v1.1.0
@@ -17,6 +18,7 @@ require (
1718
github.com/fsnotify/fsnotify v1.5.1 // indirect
1819
github.com/ghodss/yaml v1.0.0 // indirect
1920
github.com/gobwas/glob v0.2.3 // indirect
21+
github.com/google/go-querystring v1.0.0 // indirect
2022
github.com/google/uuid v1.1.2 // indirect
2123
github.com/hashicorp/hcl v1.0.0 // indirect
2224
github.com/inconshreveable/mousetrap v1.0.0 // indirect

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
5252
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
5353
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
5454
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
55+
github.com/PagerDuty/go-pagerduty v1.4.3 h1:/9uI4BCPu3FNJRculUIMYq0AUn022XWdANRgEX09X3M=
56+
github.com/PagerDuty/go-pagerduty v1.4.3/go.mod h1:W5hSIIPrzSgAkNBDiuymWN5g9yQVzimL7BUBL44f3RY=
5557
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
5658
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
5759
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -215,6 +217,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
215217
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
216218
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
217219
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
220+
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
221+
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
218222
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
219223
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
220224
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -330,6 +334,7 @@ github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKju
330334
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
331335
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
332336
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
337+
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
333338
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
334339
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
335340
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55

66
// Loading output drivers
77
_ "github.com/nsmith5/rekor-sidekick/outputs"
8+
_ "github.com/nsmith5/rekor-sidekick/outputs/cloudevents"
9+
_ "github.com/nsmith5/rekor-sidekick/outputs/pagerduty"
810
_ "github.com/nsmith5/rekor-sidekick/outputs/stdout"
911
)
1012

outputs/pagerduty/pagerduty.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package pagerduty
2+
3+
import (
4+
"errors"
5+
6+
"github.com/mitchellh/mapstructure"
7+
"github.com/nsmith5/rekor-sidekick/outputs"
8+
9+
pd "github.com/PagerDuty/go-pagerduty"
10+
)
11+
12+
const (
13+
driverName = `pagerduty`
14+
)
15+
16+
type config struct {
17+
Severity string
18+
IntegrationKey string
19+
APIToken string
20+
}
21+
22+
type driver struct {
23+
severity string
24+
integrationKey string
25+
26+
client *pd.Client
27+
}
28+
29+
func (d *driver) Send(e outputs.Event) error {
30+
payload := pd.V2Payload{
31+
Summary: e.Policy.Description,
32+
Source: e.Entry.URL,
33+
Severity: d.severity,
34+
Group: e.Policy.Name,
35+
Class: `rekor-sidekick.policy.violation.v1`,
36+
}
37+
38+
event := pd.V2Event{
39+
RoutingKey: d.integrationKey,
40+
Action: `trigger`,
41+
Images: nil,
42+
Client: `rekor-sidekick`,
43+
Payload: &payload,
44+
}
45+
46+
_, err := d.client.ManageEvent(&event)
47+
if err != nil {
48+
return err
49+
}
50+
51+
return nil
52+
}
53+
54+
func (d *driver) Name() string {
55+
return driverName
56+
}
57+
58+
func createDriver(conf map[string]interface{}) (outputs.Output, error) {
59+
var c config
60+
err := mapstructure.Decode(conf, &c)
61+
if err != nil {
62+
return nil, err
63+
}
64+
65+
if c.APIToken == "" {
66+
return nil, errors.New(`pagerduty: API token required`)
67+
}
68+
client := pd.NewClient(c.APIToken)
69+
70+
return &driver{
71+
severity: c.Severity,
72+
integrationKey: c.IntegrationKey,
73+
client: client,
74+
}, nil
75+
}
76+
77+
func init() {
78+
outputs.RegisterDriver(driverName, outputs.CreatorFunc(createDriver))
79+
}

0 commit comments

Comments
 (0)