nexaas-auditor 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ module Nexaas
2
+ module Auditor
3
+ class StatsSubscriber < Subscriber
4
+
5
+ def tracker
6
+ Nexaas::Auditor.tracker
7
+ end
8
+
9
+ private
10
+
11
+ def event_method_name(name)
12
+ "track_event_#{name.downcase.gsub('.', '_')}"
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ require 'active_support/core_ext/class/subclasses'
2
+
3
+ module Nexaas
4
+ module Auditor
5
+ class Subscriber
6
+
7
+ def self.subscribe_all
8
+ subscribers = []
9
+ subclasses.each do |klass|
10
+ subscribers << klass.subscribe()
11
+ end
12
+ subscribers
13
+ end
14
+
15
+ def self.subscribe(options={})
16
+ subscriber = options.fetch(:subscriber) { ::ActiveSupport::Notifications }
17
+ subscriber.subscribe(pattern, new)
18
+ end
19
+
20
+ def self.pattern
21
+ raise "Not Implemented, override in subclass and provide a regex or string."
22
+ end
23
+
24
+ # Dispatcher that converts incoming events to method calls.
25
+ def call(name, start, finish, event_id, payload)
26
+ method_name = event_method_name(name)
27
+ if respond_to?(method_name)
28
+ send(method_name, name, start, finish, event_id, payload)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def event_method_name(name)
35
+ raise "Not Implemented, override in subclass."
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ module Nexaas
2
+ module Auditor
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,57 @@
1
+ require 'active_support/notifications'
2
+
3
+ require 'nexaas/auditor/version'
4
+ require 'nexaas/auditor/configuration'
5
+ require 'nexaas/auditor/subscriber'
6
+ require 'nexaas/auditor/logs_subscriber'
7
+ require 'nexaas/auditor/stats_subscriber'
8
+ require 'nexaas/auditor/adapters/nunes'
9
+ require 'nexaas/auditor/rails_subscriber'
10
+ require 'nexaas/auditor/audit_logger'
11
+ require 'nexaas/auditor/statistics_trackers/base'
12
+ require 'nexaas/auditor/statistics_trackers/log'
13
+ require 'nexaas/auditor/statistics_trackers/stathat'
14
+ require 'nexaas/auditor/statistics_tracker'
15
+
16
+ module Nexaas
17
+ module Auditor
18
+
19
+ extend SingleForwardable
20
+ # forwards Nexaas::Auditor.instrument to ActiveSupport::Notifications.instrument
21
+ single_delegate :instrument => ActiveSupport::Notifications
22
+
23
+ class << self
24
+
25
+ def configure
26
+ # if configuration.enabled has not been set yet (is still 'nil'), set to true.
27
+ configuration.enabled = true if configuration.enabled.nil?
28
+ yield(configuration)
29
+ end
30
+
31
+ def configuration
32
+ @configuration ||= Configuration.new
33
+ end
34
+
35
+ def logger
36
+ Thread.current[:_nexaas_auditor_logger] ||= AuditLogger.new
37
+ end
38
+
39
+ def tracker
40
+ Thread.current[:_nexaas_auditor_tracker] ||= StatisticsTracker.setup(
41
+ configuration.statistics_service,
42
+ configuration.statistics_namespace
43
+ )
44
+ end
45
+
46
+ def subscribe_all
47
+ subscribers = []
48
+ subscribers << LogsSubscriber.subscribe_all if configuration.log_app_events
49
+ subscribers << StatsSubscriber.subscribe_all if configuration.track_app_events
50
+ subscribers << RailsSubscriber.subscribe_all if configuration.track_rails_events
51
+ subscribers
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nexaas/auditor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nexaas-auditor"
8
+ spec.version = Nexaas::Auditor::VERSION
9
+ spec.authors = ["Rodrigo Tassinari de Oliveira"]
10
+ spec.email = ["rodrigo@pittlandia.net"]
11
+
12
+ spec.summary = %q{Common code for audit logs and statistcs tracking for Nexaas Rails apps, via ActiveSupport::Instrumentation.}
13
+ spec.description = %q{Common code for audit logs and statistcs tracking for Nexaas Rails apps, via ActiveSupport::Instrumentation.}
14
+ spec.homepage = "https://github.com/myfreecomm/nexaas-auditor"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 11.1"
32
+ spec.add_development_dependency "rspec", "~> 3.4"
33
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
34
+ spec.add_development_dependency "test_notifier", "~> 2.0"
35
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nexaas-auditor
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Tassinari de Oliveira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test_notifier
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ description: Common code for audit logs and statistcs tracking for Nexaas Rails apps,
84
+ via ActiveSupport::Instrumentation.
85
+ email:
86
+ - rodrigo@pittlandia.net
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".codeclimate.yml"
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".rubocop.yml"
95
+ - ".travis.yml"
96
+ - CODE_OF_CONDUCT.md
97
+ - Gemfile
98
+ - Guardfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - TODO.md
103
+ - bin/console
104
+ - bin/setup
105
+ - lib/nexaas/auditor.rb
106
+ - lib/nexaas/auditor/adapters/nunes.rb
107
+ - lib/nexaas/auditor/audit_logger.rb
108
+ - lib/nexaas/auditor/configuration.rb
109
+ - lib/nexaas/auditor/logs_subscriber.rb
110
+ - lib/nexaas/auditor/rails_subscriber.rb
111
+ - lib/nexaas/auditor/statistics_tracker.rb
112
+ - lib/nexaas/auditor/statistics_trackers/base.rb
113
+ - lib/nexaas/auditor/statistics_trackers/log.rb
114
+ - lib/nexaas/auditor/statistics_trackers/stathat.rb
115
+ - lib/nexaas/auditor/stats_subscriber.rb
116
+ - lib/nexaas/auditor/subscriber.rb
117
+ - lib/nexaas/auditor/version.rb
118
+ - nexaas-auditor.gemspec
119
+ homepage: https://github.com/myfreecomm/nexaas-auditor
120
+ licenses:
121
+ - MIT
122
+ metadata:
123
+ allowed_push_host: https://rubygems.org
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.5.1
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Common code for audit logs and statistcs tracking for Nexaas Rails apps,
144
+ via ActiveSupport::Instrumentation.
145
+ test_files: []