Commit ea5b079557395ee3cc01ce266acf49ca6e34f3e6
Exists in
master
and in
1 other branch
Merge branch 'add_support_for_gtalk' of git://github.com/shukydvir/errbit into s…
…hukydvir-add_support_for_gtalk Conflicts: Gemfile app/models/notification_services/campfire_service.rb spec/fabricators/notification_service_fabricator.rb
Showing
13 changed files
with
86 additions
and
9 deletions
Show diff stats
Gemfile
| @@ -47,6 +47,8 @@ gem 'bitbucket_rest_api' | @@ -47,6 +47,8 @@ gem 'bitbucket_rest_api' | ||
| 47 | gem 'campy' | 47 | gem 'campy' |
| 48 | # Hipchat | 48 | # Hipchat |
| 49 | gem 'hipchat' | 49 | gem 'hipchat' |
| 50 | +# Google Talk | ||
| 51 | +gem 'xmpp4r' | ||
| 50 | # Hoiio (SMS) | 52 | # Hoiio (SMS) |
| 51 | gem 'hoi' | 53 | gem 'hoi' |
| 52 | # Pushover (iOS Push notifications) | 54 | # Pushover (iOS Push notifications) |
Gemfile.lock
| @@ -312,6 +312,7 @@ GEM | @@ -312,6 +312,7 @@ GEM | ||
| 312 | webmock (1.8.7) | 312 | webmock (1.8.7) |
| 313 | addressable (>= 2.2.7) | 313 | addressable (>= 2.2.7) |
| 314 | crack (>= 0.1.7) | 314 | crack (>= 0.1.7) |
| 315 | + xmpp4r (0.5) | ||
| 315 | xpath (0.1.4) | 316 | xpath (0.1.4) |
| 316 | nokogiri (~> 1.3) | 317 | nokogiri (~> 1.3) |
| 317 | yajl-ruby (1.1.0) | 318 | yajl-ruby (1.1.0) |
| @@ -374,4 +375,5 @@ DEPENDENCIES | @@ -374,4 +375,5 @@ DEPENDENCIES | ||
| 374 | unicorn | 375 | unicorn |
| 375 | useragent (~> 0.3.1) | 376 | useragent (~> 0.3.1) |
| 376 | webmock | 377 | webmock |
| 378 | + xmpp4r | ||
| 377 | yajl-ruby | 379 | yajl-ruby |
4.62 KB
4.62 KB
4.07 KB
app/models/notice_observer.rb
| @@ -7,17 +7,16 @@ class NoticeObserver < Mongoid::Observer | @@ -7,17 +7,16 @@ class NoticeObserver < Mongoid::Observer | ||
| 7 | notice.app.notification_service.create_notification(notice.problem) | 7 | notice.app.notification_service.create_notification(notice.problem) |
| 8 | end | 8 | end |
| 9 | 9 | ||
| 10 | - return unless should_notify? notice | ||
| 11 | - | ||
| 12 | - Mailer.err_notification(notice).deliver | 10 | + if notice.app.notification_recipients.any? |
| 11 | + Mailer.err_notification(notice).deliver | ||
| 12 | + end | ||
| 13 | end | 13 | end |
| 14 | 14 | ||
| 15 | private | 15 | private |
| 16 | 16 | ||
| 17 | def should_notify? notice | 17 | def should_notify? notice |
| 18 | app = notice.app | 18 | app = notice.app |
| 19 | - app.notify_on_errs? && | ||
| 20 | - (Errbit::Config.per_app_email_at_notices && app.email_at_notices || Errbit::Config.email_at_notices).include?(notice.problem.notices_count) && | ||
| 21 | - app.notification_recipients.any? | 19 | + app.notify_on_errs? and (app.notification_recipients.any? or !app.notification_service.nil?) and |
| 20 | + (app.email_at_notices or Errbit::Config.email_at_notices).include?(notice.problem.notices_count) | ||
| 22 | end | 21 | end |
| 23 | end | 22 | end |
app/models/notification_service.rb
| @@ -24,6 +24,8 @@ class NotificationService | @@ -24,6 +24,8 @@ class NotificationService | ||
| 24 | def type; self._type; end | 24 | def type; self._type; end |
| 25 | def type=(t); self._type=t; end | 25 | def type=(t); self._type=t; end |
| 26 | 26 | ||
| 27 | + def url; nil; end | ||
| 28 | + | ||
| 27 | # Retrieve tracker label from either class or instance. | 29 | # Retrieve tracker label from either class or instance. |
| 28 | Label = '' | 30 | Label = '' |
| 29 | def self.label; self::Label; end | 31 | def self.label; self::Label; end |
app/models/notification_services/campfire_service.rb
| @@ -20,10 +20,13 @@ if defined? Campy | @@ -20,10 +20,13 @@ if defined? Campy | ||
| 20 | end | 20 | end |
| 21 | end | 21 | end |
| 22 | 22 | ||
| 23 | + def url | ||
| 24 | + "http://campfirenow.com/" | ||
| 25 | + end | ||
| 26 | + | ||
| 23 | def create_notification(problem) | 27 | def create_notification(problem) |
| 24 | # build the campfire client | 28 | # build the campfire client |
| 25 | campy = Campy::Room.new(:account => subdomain, :token => api_token, :room_id => room_id) | 29 | campy = Campy::Room.new(:account => subdomain, :token => api_token, :room_id => room_id) |
| 26 | - | ||
| 27 | # post the issue to the campfire room | 30 | # post the issue to the campfire room |
| 28 | campy.speak "[errbit] #{problem.app.name} #{notification_description problem} - http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}/problems/#{problem.id.to_s}" | 31 | campy.speak "[errbit] #{problem.app.name} #{notification_description problem} - http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s}/problems/#{problem.id.to_s}" |
| 29 | end | 32 | end |
| @@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
| 1 | +class NotificationServices::GtalkService < NotificationService | ||
| 2 | + Label = "gtalk" | ||
| 3 | + Fields = [ | ||
| 4 | + [:subdomain, { | ||
| 5 | + :placeholder => "username@example.com", | ||
| 6 | + :label => "Username" | ||
| 7 | + }], | ||
| 8 | + [:api_token, { | ||
| 9 | + :placeholder => "password", | ||
| 10 | + :label => "Password" | ||
| 11 | + }], | ||
| 12 | + [:room_id, { | ||
| 13 | + :placeholder => "touser@example.com", | ||
| 14 | + :label => "Send To User" | ||
| 15 | + }], | ||
| 16 | + ] | ||
| 17 | + | ||
| 18 | + def check_params | ||
| 19 | + if Fields.detect {|f| self[f[0]].blank? } | ||
| 20 | + errors.add :base, 'You must specify your Username, Password and To User' | ||
| 21 | + end | ||
| 22 | + end | ||
| 23 | + | ||
| 24 | + def url | ||
| 25 | + "http://www.google.com/talk/" | ||
| 26 | + end | ||
| 27 | + | ||
| 28 | + def create_notification(problem) | ||
| 29 | + # build the xmpp client | ||
| 30 | + client = Jabber::Client.new(Jabber::JID.new(subdomain)) | ||
| 31 | + client.connect("talk.google.com") | ||
| 32 | + client.auth(api_token) | ||
| 33 | + | ||
| 34 | + # post the issue to the xmpp room | ||
| 35 | + client.send(Jabber::Message.new(room_id, "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_description problem}")) | ||
| 36 | + end | ||
| 37 | +end | ||
| 0 | \ No newline at end of file | 38 | \ No newline at end of file |
app/views/apps/index.html.haml
| @@ -28,7 +28,11 @@ | @@ -28,7 +28,11 @@ | ||
| 28 | - if any_notification_services? | 28 | - if any_notification_services? |
| 29 | %td.notification_service | 29 | %td.notification_service |
| 30 | - if app.notification_service_configured? | 30 | - if app.notification_service_configured? |
| 31 | - = image_tag("#{app.notification_service.label}_goto.png") | 31 | + - notification_service_img = image_tag("#{app.notification_service.label}_goto.png") |
| 32 | + - if app.notification_service.url | ||
| 33 | + = link_to( notification_service_img, app.notification_service.url, :target => "_blank" ) | ||
| 34 | + - else | ||
| 35 | + = notification_service_img | ||
| 32 | - if any_issue_trackers? | 36 | - if any_issue_trackers? |
| 33 | %td.issue_tracker | 37 | %td.issue_tracker |
| 34 | - if app.issue_tracker_configured? | 38 | - if app.issue_tracker_configured? |
spec/fabricators/notification_service_fabricator.rb
| @@ -5,6 +5,6 @@ Fabricator :notification_service do | @@ -5,6 +5,6 @@ Fabricator :notification_service do | ||
| 5 | subdomain { sequence :word } | 5 | subdomain { sequence :word } |
| 6 | end | 6 | end |
| 7 | 7 | ||
| 8 | -%w(campfire hipchat hoiio pushover).each do |t| | 8 | +%w(campfire gtalk hipchat hoiio pushover).each do |t| |
| 9 | Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service" | 9 | Fabricator "#{t}_notification_service".to_sym, :from => :notification_service, :class_name => "NotificationService::#{t.camelcase}Service" |
| 10 | end | 10 | end |
| @@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe NotificationService::GtalkService do | ||
| 4 | + it "it should send a notification to gtalk" do | ||
| 5 | + # setup | ||
| 6 | + notice = Fabricate :notice | ||
| 7 | + notification_service = Fabricate :gtalk_notification_service, :app => notice.app | ||
| 8 | + problem = notice.problem | ||
| 9 | + | ||
| 10 | + #gtalk stubbing | ||
| 11 | + gtalk = mock('GtalkService') | ||
| 12 | + jid = double("jid") | ||
| 13 | + message = double("message") | ||
| 14 | + Jabber::JID.should_receive(:new).with(notification_service.subdomain).and_return(jid) | ||
| 15 | + Jabber::Client.should_receive(:new).with(jid).and_return(gtalk) | ||
| 16 | + gtalk.should_receive(:connect) | ||
| 17 | + gtalk.should_receive(:auth).with(notification_service.api_token) | ||
| 18 | + Jabber::Message.should_receive(:new).with(notification_service.room_id, "[errbit] http://#{Errbit::Config.host}/apps/#{problem.app.id.to_s} #{notification_service.notification_description problem}").and_return(message) | ||
| 19 | + | ||
| 20 | + #assert | ||
| 21 | + gtalk.should_receive(:send).with(message) | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + notification_service.create_notification(problem) | ||
| 25 | + end | ||
| 26 | +end | ||
| 27 | + |
spec/spec_helper.rb
| @@ -5,6 +5,7 @@ require File.expand_path("../../config/environment", __FILE__) | @@ -5,6 +5,7 @@ require File.expand_path("../../config/environment", __FILE__) | ||
| 5 | require 'rspec/rails' | 5 | require 'rspec/rails' |
| 6 | require 'database_cleaner' | 6 | require 'database_cleaner' |
| 7 | require 'webmock/rspec' | 7 | require 'webmock/rspec' |
| 8 | +require 'xmpp4r' | ||
| 8 | 9 | ||
| 9 | # Requires supporting files with custom matchers and macros, etc, | 10 | # Requires supporting files with custom matchers and macros, etc, |
| 10 | # in ./support/ and its subdirectories. | 11 | # in ./support/ and its subdirectories. |