appmonitor-ruby 0.0.111 → 0.0.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e3b6ab8916b5498f51dca0e593d7659c19f38be
4
- data.tar.gz: f3d239d0df24f20392f985655f53e7554903fa66
3
+ metadata.gz: 3514c5ec29cb5502bc4ea2c92f03d9fb814acca6
4
+ data.tar.gz: a8db53e0be3eae864dd6c3965eb239b66e800d01
5
5
  SHA512:
6
- metadata.gz: 3f0bb90264fd2c10b420d5744638a239bbd6d502b4d8c4ad091ea0f4e7f1b9188df4788bebd1a15e5a598fbf4a13d47e07619ca139084c280a653a00d86d54b6
7
- data.tar.gz: 0b75b1109d3ce9644d7a5198f3231819e4321e4ef87805ff8c11428cb4b76329a3d72b8cf5b0c2d6a24ea113fa681a37fb2f0d9b820e4818175b4d9aceef363b
6
+ metadata.gz: c55fbf7c8243248146269d91137ac05863a81422d1bd7eea2e829310cf2631175b7d858f1625dd33d27b171f883a91cc44ed349803aaff11c8356e44ddbd9749
7
+ data.tar.gz: 99ef7d9a963fdaf01c201f6be2b6aeb8467e90f46a5a4bbdb7851ea1ae95a92893671ff184d2192a286a492c7e2ee6e5d70813120a5081564c37f5a14d04f89f
@@ -0,0 +1,22 @@
1
+ module AppMonitorRuby
2
+ def self.included(base)
3
+ base.around_filter :exception_catcher
4
+ end
5
+
6
+
7
+
8
+ def exception_catcher(&block)
9
+
10
+ begin
11
+
12
+ yield
13
+
14
+ rescue Exception => exception
15
+ event_notifier = EventNotifier.new
16
+ event_notifier.notify(exception,request,params)
17
+ raise exception
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,90 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require "active_support/core_ext"
4
+
5
+ class EventNotification
6
+ def self.build_hash(exception,request,params)
7
+ hash={}
8
+ hash[:event]={:klass => params[:controller], :method =>params[:action] , :message => exception.message,
9
+ :type => "Error"}
10
+
11
+ hash[:message] = {:session => request.session.to_hash, :stack_trace => exception.backtrace,
12
+ :url => request.original_url, :ip_address => request.remote_ip, :time =>Time.now ,
13
+ :environment => Rails.env , :attrs => params}
14
+
15
+ hash
16
+ end
17
+ end
18
+
19
+ class EventNotifier
20
+
21
+
22
+
23
+ # Configure through hash
24
+ def configure(opts = {})
25
+ @config = {
26
+ :api_key=> "",
27
+ :uri =>""
28
+ }
29
+
30
+ @valid_config_keys = @config.keys
31
+
32
+ opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
33
+ end
34
+
35
+ def self.default_ignore_exceptions
36
+ [].tap do |exceptions|
37
+
38
+ exceptions << 'ActionController::RoutingError'
39
+ exceptions << 'ActionController::InvalidAuthenticityToken'
40
+ exceptions << 'CGI::Session::CookieStore::TamperedWithCookie'
41
+ exceptions << 'ActionController::UnknownAction'
42
+ exceptions << 'ActionController::UnknownHttpMethod'
43
+ exceptions << 'Mongoid::Errors::DocumentNotFound'
44
+ end
45
+ end
46
+
47
+ def read_config
48
+ path_to_yaml_file = "#{Rails.root}/config/appmonitor.yml"
49
+ begin
50
+ config = YAML::load(IO.read(path_to_yaml_file))
51
+ Rails.logger.info(config)
52
+ rescue Errno::ENOENT
53
+ return
54
+ rescue Psych::SyntaxError
55
+ return
56
+ end
57
+ configure(config)
58
+ end
59
+
60
+ def ignored_exception(ignore_array, exception)
61
+ Array.wrap(ignore_array).map(&:to_s).include?(exception.class.name)
62
+ end
63
+
64
+ def initialize()
65
+ read_config
66
+ @config[:ignore_exceptions] ||= self.class.default_ignore_exceptions
67
+ end
68
+
69
+ def notify(exception, request,params)
70
+ unless ignored_exception(@config[:ignore_exceptions],exception )
71
+
72
+ event = EventNotification.build_hash(exception,request,params)
73
+ @event = event.to_json
74
+ uri = URI.parse(@config[:uri])
75
+ token = @config[:api_key]
76
+
77
+ https = Net::HTTP.new(uri.host, uri.port)
78
+ https.use_ssl = false
79
+ request = Net::HTTP::Post.new(uri.path,initheader = {"Content-Type" =>"application/json", "Authorization" => "Token token=#{token}"})
80
+
81
+ request.body = "#@event"
82
+
83
+ response = https.request(request)
84
+ end
85
+ end
86
+
87
+
88
+
89
+
90
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appmonitor-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.111
4
+ version: 0.0.112
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Gappers
@@ -16,7 +16,9 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - lib/application_controller.rb
19
20
  - lib/appmonitor-ruby.rb
21
+ - lib/event_notifier.rb
20
22
  homepage: http://rubygems.org/gems/appmonitor-ruby
21
23
  licenses:
22
24
  - MIT