class EventNotifier

Public Class Methods

default_ignore_exceptions() click to toggle source
# File lib/event_notifier.rb, line 35
def self.default_ignore_exceptions
    [].tap do |exceptions|
      
      exceptions << 'ActionController::RoutingError'
                exceptions << 'ActionController::InvalidAuthenticityToken'
                exceptions << 'CGI::Session::CookieStore::TamperedWithCookie'
                exceptions << 'ActionController::UnknownAction'
                exceptions << 'ActionController::UnknownHttpMethod'
        exceptions << 'Mongoid::Errors::DocumentNotFound'
    end
 end
new() click to toggle source
# File lib/event_notifier.rb, line 64
def initialize()
   read_config
   @config[:ignore_exceptions] ||= self.class.default_ignore_exceptions
 end

Public Instance Methods

configure(opts = {}) click to toggle source

Configure through hash

# File lib/event_notifier.rb, line 24
def configure(opts = {})
      @config = {
            :api_key=> "",
            :uri =>""
          }

@valid_config_keys = @config.keys

  opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
end
ignored_exception(ignore_array, exception) click to toggle source
# File lib/event_notifier.rb, line 60
def ignored_exception(ignore_array, exception)
   Array.wrap(ignore_array).map(&:to_s).include?(exception.class.name)
 end
notify(exception, request,params) click to toggle source
# File lib/event_notifier.rb, line 69
def notify(exception, request,params)
        unless ignored_exception(@config[:ignore_exceptions],exception )

                event = EventNotification.build_hash(exception,request,params)
                @event = event.to_json
                uri = URI.parse(@config[:uri])
                token = @config[:api_key]

                https = Net::HTTP.new(uri.host, uri.port)
                https.use_ssl = false
                request = Net::HTTP::Post.new(uri.path,initheader = {"Content-Type" =>"application/json", "Authorization" => "Token token=#{token}"})

                request.body = "#@event"

                response = https.request(request)
        end
end
read_config() click to toggle source
# File lib/event_notifier.rb, line 47
 def read_config
        path_to_yaml_file = "#{Rails.root}/config/appmonitor.yml"
        begin
      config = YAML::load(IO.read(path_to_yaml_file))
      Rails.logger.info(config)
    rescue Errno::ENOENT
return
    rescue Psych::SyntaxError
  return
    end
    configure(config)
 end