Skip to content

Commit

Permalink
Merge pull request #118 from contactually/feature/pagerduty
Browse files Browse the repository at this point in the history
Adds support for pagerduty notifications
  • Loading branch information
bolshakov committed Aug 18, 2019
2 parents 4c3744f + 8522da0 commit cb24285
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Check out [stoplight-admin][] for controlling your stoplights.
- [Rollbar](#rollbar)
- [Sentry](#sentry)
- [Slack](#slack)
- [Pagerduty](#pagerduty)
- [Rails](#rails-1)
- [Advanced usage](#advanced-usage)
- [Locking](#locking)
Expand Down Expand Up @@ -408,6 +409,22 @@ Stoplight::Light.default_notifiers += [notifier]
# => [#<Stoplight::Notifier::IO:...>, #<Stoplight::Notifier::Slack:...>]
```

#### Pagerduty

Make sure you have [the Pagerduty gem][] (`~> 2.1`) installed before configuring
Stoplight.

``` rb
require 'pagerduty'
# => true
pagerduty = Pagerduty.new('http://www.example.com/webhook-url')
# => #<Pagerduty:...>
notifier = Stoplight::Notifier::Pagerduty.new(pagerduty)
# => #<Stoplight::Notifier::Pagerduty:...>
Stoplight::Light.default_notifiers += [notifier]
# => [#<Stoplight::Notifier::IO:...>, #<Stoplight::Notifier::Pagerduty:...>]
```

### Rails

Stoplight is designed to work seamlessly with Rails. If you want to use the
Expand Down Expand Up @@ -513,6 +530,7 @@ Stoplight is licensed under [the MIT License][].
[the Rollbar gem]: https://rubygems.org/gems/rollbar
[the Sentry gem]: https://rubygems.org/gems/sentry-raven
[the Slack gem]: https://rubygems.org/gems/slack-notifier
[the Pagerduty gem]: https://rubygems.org/gems/pagerduty
[@camdez]: https://github.com/camdez
[@tfausak]: https://github.com/tfausak
[@orgsync]: https://github.com/OrgSync
Expand Down
1 change: 1 addition & 0 deletions lib/stoplight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Stoplight # rubocop:disable Style/Documentation
require 'stoplight/notifier/rollbar'
require 'stoplight/notifier/raven'
require 'stoplight/notifier/slack'
require 'stoplight/notifier/pagerduty'

require 'stoplight/default'

Expand Down
21 changes: 21 additions & 0 deletions lib/stoplight/notifier/pagerduty.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# coding: utf-8

module Stoplight
module Notifier
# @see Base
class Pagerduty < Base
include Generic

# @return [::Slack::Notifier]
def pagerduty
@object
end

private

def put(message)
pagerduty.trigger(message)
end
end
end
end
40 changes: 40 additions & 0 deletions spec/stoplight/notifier/pagerduty_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# coding: utf-8

require 'spec_helper'
require 'pagerduty'

RSpec.describe Stoplight::Notifier::Pagerduty do
it_behaves_like 'a generic notifier'

it 'is a class' do
expect(described_class).to be_a(Class)
end

it 'is a subclass of Base' do
expect(described_class).to be < Stoplight::Notifier::Base
end

describe '#pagerduty' do
it 'reads Pagerduty client' do
pagerduty = Pagerduty.new('WEBHOOK_URL')
expect(described_class.new(pagerduty).pagerduty).to eql(pagerduty)
end
end

describe '#notify' do
let(:light) { Stoplight::Light.new(name, &code) }
let(:name) { ('a'..'z').to_a.shuffle.join }
let(:code) { -> {} }
let(:from_color) { Stoplight::Color::GREEN }
let(:to_color) { Stoplight::Color::RED }
let(:notifier) { described_class.new(pagerduty) }
let(:pagerduty) { double(Pagerduty).as_null_object }

it 'pings Pagerduty' do
error = nil
message = notifier.formatter.call(light, from_color, to_color, error)
expect(pagerduty).to receive(:trigger).with(message)
notifier.notify(light, from_color, to_color, error)
end
end
end
1 change: 1 addition & 0 deletions stoplight.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |gem|
'coveralls' => '0.8',
'fakeredis' => '0.5',
'hipchat' => '1.5',
'pagerduty' => '2.1.1',
'honeybadger' => '2.5',
'sentry-raven' => '1.2',
'rake' => '11.1',
Expand Down

0 comments on commit cb24285

Please sign in to comment.