appmonitor 0.0.1 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb9475dc2e370f599c06c6289db239812e94656b
4
- data.tar.gz: 07f3188c7274c48d82761318390a474ba3dcb053
3
+ metadata.gz: 7d58774bb5e727ad8870239e6d0771dcdabefd87
4
+ data.tar.gz: 8d0c4ee29e555a22516b2fdba48f4cf1edf324ad
5
5
  SHA512:
6
- metadata.gz: 7695bc7a5262dda6aeca0da08ef17f7c62b45cfe3884f6e9835700be3c04128fd67ad1e9c31389ed838b2c432ded6b7a36d030d63dbc53ca237ce811568a97e5
7
- data.tar.gz: 9d1dc4ddcb409e0e7df3ded382884bf2b2025f7943fa43080db54c589bd00da483dd7e4bd80f825d8ab06ef64d32af6da39a190e105bddab30f8b67765d2dfae
6
+ metadata.gz: 8396fd14c5d8485f43b70f0b23d77813077c5297982916805bee441092184f3b866881dc5a0b5fc14116b1df051dbed943b0d9038660758c3b49bb9a7005b264
7
+ data.tar.gz: 08a37976a502f4118fc98d93afc251243a32041db88d673dc3055bb525a02bbdbdc88eddedb4b81b505493477c03af042d9066a4674b98932a1f054eea6f7571
@@ -0,0 +1,27 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'active_support/core_ext'
4
+ require 'action_dispatch'
5
+
6
+ module AppMonitor
7
+ class EventNotification
8
+
9
+ def self.build_exception_hash(exception, request, options = {})
10
+ params = request.params
11
+ {:klass => params[:controller], :method => params[:action], :message => exception.message.inspect,
12
+ :session => request.session.to_hash, :stack_trace => exception.backtrace.join("\n"),
13
+ :params => request.filtered_parameters,
14
+ :url => request.original_url, :ip_address => request.remote_ip, :time => Time.now.to_i,
15
+ :environment => Rails.env || ''}
16
+ end
17
+
18
+ def self.build_rake_event(exception, options)
19
+ rake_called_name = options[:rake_command_line].split(":",2)
20
+ rake_namespace = rake_called_name.first
21
+ {method: options[:rake_command_line], time: Time.now.to_i, message: exception.message.inspect, stack_trace: exception.backtrace.join("\n"),
22
+ klass: rake_namespace, environment: Rails.env || ''}
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -1,21 +1,23 @@
1
1
  require 'uri'
2
2
  require 'net/http'
3
- require "active_support/core_ext"
3
+ require 'active_support/core_ext'
4
4
  require 'action_dispatch'
5
+ require 'appmonitor/event_notification'
5
6
 
6
7
  module AppMonitor
7
8
  class EventNotifier
8
9
 
10
+ API_MESSAGE_URL = 'http://team10-14.ucebne.fiit.stuba.sk/api/message'
11
+
9
12
  def initialize(app)
10
13
  @app = app
11
14
  configure
12
15
  @config[:ignore_exceptions] ||= self.class.default_ignore_exceptions
13
16
  end
14
17
 
15
- def configure(opts = {} )
18
+ def configure(opts = {})
16
19
  @config = {
17
20
  api_key: '',
18
- uri: '',
19
21
  project_id: '',
20
22
  monitoring: {development: '', staging: '', production: ''}
21
23
  }
@@ -32,15 +34,16 @@ module AppMonitor
32
34
  config.each { |k, v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym }
33
35
  end
34
36
 
35
-
36
37
  def self.default_ignore_exceptions
37
38
  [].tap do |exceptions|
38
39
  exceptions << 'ActionController::RoutingError'
39
40
  exceptions << 'ActionController::InvalidAuthenticityToken'
40
41
  exceptions << 'CGI::Session::CookieStore::TamperedWithCookie'
41
42
  exceptions << 'ActionController::UnknownAction'
43
+ exceptions << 'ActionController::UnknownFormat'
42
44
  exceptions << 'ActionController::UnknownHttpMethod'
43
45
  exceptions << 'Mongoid::Errors::DocumentNotFound'
46
+ exceptions << 'AbstractController::ActionNotFound'
44
47
  end
45
48
  end
46
49
 
@@ -48,25 +51,9 @@ module AppMonitor
48
51
  Array.wrap(ignore_array).map(&:to_s).include?(exception.class.name)
49
52
  end
50
53
 
51
-
52
- def build_exception_hash(exception, request)
53
- params = request.params
54
- {:klass => params[:controller], :method => params[:action], :message => exception.message.inspect,
55
- :session => request.session.to_hash, :stack_trace => exception.backtrace.join("\n"),
56
- :params => request.filtered_parameters,
57
- :url => request.original_url, :ip_address => request.remote_ip, :timestamp => Time.now.to_i,
58
- :environment => Rails.env}
59
- end
60
-
61
- def build_rake_event(exception,options)
62
- {timestamp: Time.now.to_i, message: exception.message.inspect, stack_trace: exception.backtrace.join("\n"),
63
- klass: options[:rake_command_line], environment: Rails.env || ''}
64
- end
65
-
66
54
  def call(env)
67
55
  @app.call(env)
68
56
  rescue Exception => exception
69
- puts @config
70
57
  if @config[:monitoring]["#{Rails.env.to_s.downcase}"]
71
58
  @request = ActionDispatch::Request.new(env)
72
59
  send_exception(exception)
@@ -76,7 +63,7 @@ module AppMonitor
76
63
 
77
64
  def send_exception(exception)
78
65
  unless ignored_exception(@config[:ignore_exceptions], exception)
79
- event = build_exception_hash(exception, @request)
66
+ event = EventNotification.build_exception_hash(exception, @request)
80
67
  @event = event.to_json
81
68
  notify_on_event("Error")
82
69
  end
@@ -85,15 +72,19 @@ module AppMonitor
85
72
  def send_rake_event(exception, options = {})
86
73
  configure
87
74
  unless ignored_exception(@config[:ignore_exceptions], exception)
88
- event = build_rake_event(exception, options)
75
+ event = EventNotification.build_rake_event(exception, options)
89
76
  @event = event.to_json
90
77
  notify_on_event("RakeError")
91
78
  end
92
79
  end
93
80
 
94
- def notify_on_event(type)
95
- uri = URI.parse(@config[:uri])
81
+ def send_custom_event(type, options={})
82
+ @event = options.to_json
83
+ notify_on_event(type)
84
+ end
96
85
 
86
+ def notify_on_event(type)
87
+ uri = URI.parse(API_MESSAGE_URL)
97
88
  https = Net::HTTP.new(uri.host, uri.port)
98
89
  https.use_ssl = false
99
90
  request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' => "application/json",
@@ -102,19 +93,19 @@ module AppMonitor
102
93
  'appm_type' => type}
103
94
  )
104
95
 
105
- request.body = "#@event"
96
+ request.body = @event
106
97
  response = https.request(request)
107
98
 
108
- Rails.logger.info ("Appmonitor: Event has been sent")
99
+ Rails.logger.debug ("Appmonitor: Event has been sent")
109
100
  puts 'Appmonitor: Event has been sent'
110
101
 
111
102
  unless response.kind_of? Net::HTTPSuccess
112
- Rails.logger.info('Appmonitor WARNING: Something went wrong, please check your config')
113
- Rails.logger.info("AppMonitor WARNING: Response #{response.inspect}")
103
+ Rails.logger.warn('Appmonitor WARNING: Something went wrong, please check your config')
104
+ Rails.logger.warn("AppMonitor WARNING: Response ''#{response.code}: #{response.message}''")
114
105
  puts 'Appmonitor WARNING: Something went wrong, please check your config'
115
106
  puts "AppMonitor WARNING: Response #{response.inspect}"
116
107
  end
117
108
  end
118
- end
119
109
 
110
+ end
120
111
  end
data/lib/appmonitor.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  require 'appmonitor/event_notifier'
2
- require 'appmonitor/rake'
2
+ require 'appmonitor/event_notification'
3
3
  require 'appmonitor/rake_patch'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appmonitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Gappers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2010-10-31 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2010-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: AppMonitor agent for ruby language
14
28
  email: gappers-tip-fiit@googlegroups.com
15
29
  executables: []
@@ -17,8 +31,8 @@ extensions: []
17
31
  extra_rdoc_files: []
18
32
  files:
19
33
  - lib/appmonitor.rb
34
+ - lib/appmonitor/event_notification.rb
20
35
  - lib/appmonitor/event_notifier.rb
21
- - lib/appmonitor/rake.rb
22
36
  - lib/appmonitor/rake_patch.rb
23
37
  homepage: http://rubygems.org/gems/appmonitor
24
38
  licenses:
@@ -45,3 +59,4 @@ signing_key:
45
59
  specification_version: 4
46
60
  summary: AppMonitor agent for ruby language
47
61
  test_files: []
62
+ has_rdoc:
@@ -1,10 +0,0 @@
1
- require 'appmonitor'
2
-
3
- module AppMonitor
4
- class Rake
5
- def self.configure
6
-
7
- end
8
-
9
- end
10
- end