Add slack to exception-notification gem - ruby-on-rails-3

I have a Rails 3.2.8 app using Ruby 1.9.3. I am trying to configure slack integration to work with execption_notification. execption_notification works fine for mail, but after adding slack integration based on the readme HERE I get this error when trying to start the server...
exception_notifier.rb:102:in `rescue in create_and_register_notifier': No notifier named 'slack' was found. Please, revise your configuration options. Cause: uninitialized constant ExceptionNotifier::SlackNotifier (ExceptionNotifier::UndefinedNotifierError)
Here are the relevant lines in my config/env/production.rb
#email notifications for exception in app
MyApp::Application.config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[Exception] ",
:sender_address => %{"notifier" <notifier#example.com>},
:exception_recipients => %w{email},
},
:slack => {
:webhook_url => "[mySlackHook",
:channel => "#exceptions",
:additional_parameters => {
:icon_url => "error.png"
}
}

Slack integration hasn't been added in the current version of the exception_notification gem on RubyGems (https://rubygems.org/gems/exception_notification)
Try using the git repo version:
In your Gemfile:
gem 'exception_notifications', git: 'https://github.com/smartinez87/exception_notification.git'
or specifying the '4.1.0rc1' version in your Gemfile

Related

Airbrake not catching errors for Sidekiq in Rails app on an environment other than development

I'm using Sidekiq and Airbrake in my Rails application. I would like Airbrake to catch any errors that occur during Sidekiq jobs. As per instructions I found online, I've added the following to sidekiq.rb:
config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) }
Airbrake then was able to catch errors when they occurred in my development environment. However, once I deployed to a higher environment, Airbrake stopped being able to catch Sidekiq errors. Is there any reason this would happen? Is there anything else I need to configure inside my app?
I'm using sidekiq gem version ~>3.0.2, airbrake gem version ~>4.0.0, and rails 3.2.18
Here is my full sidekiq.rb:
require 'sidekiq'
require 'sidekiq-status'
redis_connection = "redis://127.0.0.1:6379/0"
Sidekiq.configure_server do |config|
config.redis = { :url => redis_connection, :namespace => 'sidekiq' }
config.server_middleware do |chain|
chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes
end
config.client_middleware do |chain|
chain.add Sidekiq::Status::ClientMiddleware
end
config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) }
end
Sidekiq.configure_client do |config|
config.redis = { :url => redis_connection, :namespace => 'sidekiq' }
config.client_middleware do |chain|
chain.add Sidekiq::Status::ClientMiddleware
end
end
And here is my full airbrake.rb:
Airbrake.configure do |config|
config.user_attributes = [:id, :email]
config.api_key = '*my_api_key*'
end
It turns out that if your app is also using rubber, then you also have to change your rubber sidekiq initializer (config/rubber/common/initializers/sidekiq) to include the line:
config.error_handlers << Proc.new { |ex,context| Airbrake.notify_or_ignore(ex, parameters: context) }
The rubber sidekiq initializer is used for all non-development environments, whereas the sidekiq.rb file is used for development environment.

How to get contact list from yahoo in rails using OAuth

I can successfully get the contacts from google using OAuth gem in rails. my gmail configuration is :
:google=>{
:key=>"***",
:secret=>"***",
:expose => true,
:scope=>"https://www.google.com/m8/feeds/"
}
now i want to get contact from yahoo and hot mail. How to get that contact I have given following configuration in my oauth_consumer.rb file
:yahoo=>{
:client=>:oauth_gem,
:expose => true,
:allow_login => true,
:key=>"**",
:secret=>"**",
:scope=>"https://me.yahoo.com"
}
:hotmail=>{
:client=>:oauth_gem,
:expose => true,
:allow_login => true,
:key=>"**",
:secret=>"**"
}
when i am trying to do same like what is done in google it gives error like undefined methoddowncase' for nil:NilClass`
I have also tried contacts gem but fail to load contacts.
Please try to use OmniContacts https://github.com/Diego81/omnicontacts this will help you alot.
In your gemfile
gem "omnicontacts"
Create config/initializers/omnicontacts.rb
require "omnicontacts"
Rails.application.middleware.use OmniContacts::Builder do
importer :gmail, "client_id", "client_secret", {:redirect_path => "/oauth2callback", :ssl_ca_file => "/etc/ssl/certs/curl-ca-bundle.crt"}
importer :yahoo, "consumer_id", "consumer_secret", {:callback_path => '/callback'}
importer :hotmail, "client_id", "client_secret"
importer :facebook, "client_id", "client_secret"
end
Create an app to yahoo https://developer.apps.yahoo.com/projects
This will ask to verify your domain. So, just change your domain of localhost:3000 to local.appname.com:3000 or prefer your live server... (change host in local --- sudo gedit /etc/hosts)
in your controller
#contacts = request.env['omnicontacts.contacts']
#user = request.env['omnicontacts.user']
puts "List of contacts of #{user[:name]} obtained from #{params[:importer]}:"
#contacts.each do |contact|
puts "Contact found: name => #{contact[:name]}, email => #{contact[:email]}"
end

How Do You Expire A Memcached Entry On Heroku

I am using action caching on my Rails 3 app on Heroku with the :expires_in option. I've tried calling expire_action, directly in the controller upon update, and within a sweeper. Nothing seems to expire the cache entry properly.
In my controller:
caches_action :embed, :if => Proc.new { |c| c.request.format.js? || c.request.format.rss? }, :expires_in => 5.minutes
In my action:
expire_action :action => :embed, :format => :js
And I've also attempted it in a sweeper, attempting to use the url generator to get the exact key:
expire_action obj_embed_url(#obj.unique_token)
I wonder if it is Heroku using the Varnish cache layer, which you can't expire. (The cache clearly expires after the 5 minutes, because I can see the content update.) It appears that I have the memcached add-on configured correctly (using the Dalli gem; config.cache_store = :dalli_store), and I can see the appropriate environment variables...
$ heroku config |grep MEM
MEMCACHE_PASSWORD => xxxxxxxxxxxxxxxxx
MEMCACHE_SERVERS => xxx.xxx.northscale.net
MEMCACHE_USERNAME => appxxxxxx%40heroku.com
What am I missing here?
finally figured this out.
Heroku's paths must not be matching up with the expire create/expire calls. so if you specify the path in the cache creation, and call that path specifically in the expire, it will work. also i had to use "expire_fragment" instead of "expire_action". here's my code:
in your controller:
caches_action :load, :up, :juice, :fresh, :cache_path => :custom_cache_path.to_proc
def custom_cache_path
path = "#{params[:controller]}/#{params[:action]}"
path += "/#{params[:id]}" if params[:id]
path += "/#{params[:sha]}" if params[:sha]
path
end
in the expiring method:
expire_fragment "serve/up/#{#site.id}"
expire_fragment "serve/fresh/#{#site.secret}"

rails aws-s3 delete file throws AWS::S3::PermanentRedirect error - EU bucket problem?

I'm building a rails3 app on heroku, and I'm using aws-s3 gem to manipulate files stored in an Amazon S3 eu bucket.
When I try to perform a AWS::S3::S3Object.delete filename, 'mybucketname' command, I get the following error:
AWS::S3::PermanentRedirect (The bucket you are attempting to access
must be addressed using the specified endpoint. Please send all future
requests to this endpoint.):
I have added the following to my application.rb file:
AWS::S3::Base.establish_connection!(
:access_key_id => "myAccessKey",
:secret_access_key => "mySecretAccessKey"
)
and the following code to my controller:
def destroy
song = tape.songs.find(params[:id])
AWS::S3::S3Object.delete song.filename, 'mybucket'
song.destroy
respond_to do |format|
format.js { render :nothing => true }
end end
I found a proposed solution somewhere to add AWS_CALLING_FORMAT: SUBDOMAIN to my amazon_s3.yml file, as supposedly, aws-s3 should handle differently eu buckets than us.
However, this did not work, same error is received.
Could you please provide any assistance?
Thank you very much for your help.
the problem is you need to type SUBDOMAIN as uppercase string in config, try this out
You can specify custom endpoint at connection initialization point:
AWS::S3::Base.establish_connection!(
:access_key_id => 'myAccessKey',
:secret_access_key => 'mySecretAccessKey',
:server => 's3-website-us-west-1.amazonaws.com'
)
you can find actual endpoint through the AWS console:
full list of valid options - here https://github.com/marcel/aws-s3/blob/master/lib/aws/s3/connection.rb#L252
VALID_OPTIONS = [:access_key_id, :secret_access_key, :server, :port, :use_ssl, :persistent, :proxy].freeze
My solution is to set the constant to the actual service link at initialization time.
in config/initializers/aws_s3.rb
AWS::S3::DEFAULT_HOST = "s3-ap-northeast-1.amazonaws.com"
AWS::S3::Base.establish_connection!(
:access_key_id => 'access_key_id',
:secret_access_key => 'secret_access_key'
)

Rails 3.0 / net-ldap - works in irb, but not in app

I've looked around and can't seem to find the answer to this... I'm trying to use net-ldap with rails.
in irb, I can run a quick bind and it works:
irb(main):003:0> ldap_con = Net::LDAP.new({:host => 'myhost.ad',
irb(main):004:2* :base => 'DC=myhost,DC=ad',
irb(main):005:2* :port => 389,:auth=>{:method=>:simple,:username => 'bsharpe#myhost.ad',
irb(main):006:3* :password => 'letmein' } } )
=> #<Net::LDAP:0x292089f0 #host="myhost.ad", #open_connection=nil, #encryption=nil, #auth={:password=>"letmein", :method=>:simple, :username=>"bsharpe#myhost.ad"}, #verbose=false, #port=389, #base="DC=myhost,DC=ad">
irb(main):007:0> ldap_con.bind
=> true
but if i run the app i get
no such file to load -- net/ldap
which is from my require net/ldap
I checked $LOAD_PATH and it does contain /usr/local/lib/ruby/gems/1.8/gems/net-ldap-0.1.1/lib
What am I missing here?
I had the same problem. Adding: require 'rubygems' before require 'net/ldap
For example:
#!/usr/bin/ruby -w
require 'rubygems'
require 'net/ldap'
ruby version 1.8.7 and net/ldap(0.3.1)