Skip to content

Commit

Permalink
outputs: add Pager Duty support
Browse files Browse the repository at this point in the history
  • Loading branch information
nsmith5 committed Jan 16, 2022
1 parent dd756e3 commit 3658746
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 4 deletions.
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ outputs:
+ enabled: true
```

**cloudevents**
**Cloud Events**

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

```diff
outputs:
Expand All @@ -187,4 +187,25 @@ outputs:
The `sourceID` fields configures the event source. The resulting event source
in this case would be `github.com/nsmith5/rekor-sidekick:instance-a`. The event
type is `rekor-sidekick.policy.violation.v1`. The `http.url` field configures
an HTTP destination for your emitted events.
an HTTP destination for your emitted events.

**Pager Duty**

The `pagerduty` driver emits [Pager Duty](https://pagerduty.com) events. To
configure Rekor Sidekick to alert to Pager Duty you'll need

- An _API token_. This ca be fetched at _Integrations_ > _API Access keys_.
- An _Integration Key_. This ca be fetched at _Automation_ > _Event Rules_ >
_Your rule set_ > _View_ > _Integration Key_

Configure the driver as follows:

```diff
outputs:
+ pagerduty:
+ apitoken: << api token >>
+ integrationKey: << integration key >>
+ severity: error
```

The severity can be one of `critical`, `warning`, `error`, or `info`.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/nsmith5/rekor-sidekick
go 1.17

require (
github.com/PagerDuty/go-pagerduty v1.4.3
github.com/cloudevents/sdk-go/v2 v2.8.0
github.com/mitchellh/mapstructure v1.4.3
github.com/oklog/run v1.1.0
Expand All @@ -17,6 +18,7 @@ require (
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8=
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/PagerDuty/go-pagerduty v1.4.3 h1:/9uI4BCPu3FNJRculUIMYq0AUn022XWdANRgEX09X3M=
github.com/PagerDuty/go-pagerduty v1.4.3/go.mod h1:W5hSIIPrzSgAkNBDiuymWN5g9yQVzimL7BUBL44f3RY=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -215,6 +217,8 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
Expand Down Expand Up @@ -330,6 +334,7 @@ github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKju
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

// Loading output drivers
_ "github.com/nsmith5/rekor-sidekick/outputs"
_ "github.com/nsmith5/rekor-sidekick/outputs/cloudevents"
_ "github.com/nsmith5/rekor-sidekick/outputs/pagerduty"
_ "github.com/nsmith5/rekor-sidekick/outputs/stdout"
)

Expand Down
79 changes: 79 additions & 0 deletions outputs/pagerduty/pagerduty.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package pagerduty

import (
"errors"

"github.com/mitchellh/mapstructure"
"github.com/nsmith5/rekor-sidekick/outputs"

pd "github.com/PagerDuty/go-pagerduty"
)

const (
driverName = `pagerduty`
)

type config struct {
Severity string
IntegrationKey string
APIToken string
}

type driver struct {
severity string
integrationKey string

client *pd.Client
}

func (d *driver) Send(e outputs.Event) error {
payload := pd.V2Payload{
Summary: e.Policy.Description,
Source: e.Entry.URL,
Severity: d.severity,
Group: e.Policy.Name,
Class: `rekor-sidekick.policy.violation.v1`,
}

event := pd.V2Event{
RoutingKey: d.integrationKey,
Action: `trigger`,
Images: nil,
Client: `rekor-sidekick`,
Payload: &payload,
}

_, err := d.client.ManageEvent(&event)
if err != nil {
return err
}

return nil
}

func (d *driver) Name() string {
return driverName
}

func createDriver(conf map[string]interface{}) (outputs.Output, error) {
var c config
err := mapstructure.Decode(conf, &c)
if err != nil {
return nil, err
}

if c.APIToken == "" {
return nil, errors.New(`pagerduty: API token required`)
}
client := pd.NewClient(c.APIToken)

return &driver{
severity: c.Severity,
integrationKey: c.IntegrationKey,
client: client,
}, nil
}

func init() {
outputs.RegisterDriver(driverName, outputs.CreatorFunc(createDriver))
}

0 comments on commit 3658746

Please sign in to comment.