Commit d44992ac803052af688ba791ff991fad797e1d7f

Authored by Vasiliy Ermolovich
2 parents 0c9d116f 31675f57
Exists in master and in 1 other branch production

Merge pull request #402 from boblail/webhook-notification-service

added a generic "Web Hook" notification service
app/assets/images/webhook_create.png 0 → 100644

3.16 KB

app/assets/images/webhook_goto.png 0 → 100644

3.16 KB

app/assets/images/webhook_inactive.png 0 → 100644

2.49 KB

app/models/notification_services/webhook_service.rb 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +class NotificationServices::WebhookService < NotificationService
  2 + Label = "webhook"
  3 + Fields = [
  4 + [:api_token, {
  5 + :placeholder => 'URL to receive a POST request when an error occurs',
  6 + :label => 'URL'
  7 + }]
  8 + ]
  9 +
  10 + def check_params
  11 + if Fields.detect {|f| self[f[0]].blank? }
  12 + errors.add :base, 'You must specify the URL'
  13 + end
  14 + end
  15 +
  16 + def create_notification(problem)
  17 + HTTParty.post(api_token, :body => {:problem => problem.to_json})
  18 + end
  19 +end
... ...
spec/fabricators/notification_service_fabricator.rb
... ... @@ -11,6 +11,6 @@ Fabricator :gtalk_notification_service, :from =&gt; :notification_service, :class_n
11 11 service { sequence :word }
12 12 end
13 13  
14   -%w(campfire hipchat hoiio pushover hubot).each do |t|
  14 +%w(campfire hipchat hoiio pushover hubot webhook).each do |t|
15 15 Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service"
16 16 end
... ...
spec/models/notification_service/webhook_service_spec.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +require 'spec_helper'
  2 +
  3 +describe NotificationService::WebhookService do
  4 + it "it should send a notification to a user-specified URL" do
  5 + notice = Fabricate :notice
  6 + notification_service = Fabricate :webhook_notification_service, :app => notice.app
  7 + problem = notice.problem
  8 +
  9 + HTTParty.should_receive(:post).with(notification_service.api_token, :body => {:problem => problem.to_json}).and_return(true)
  10 +
  11 + notification_service.create_notification(problem)
  12 + end
  13 +end
... ...