fluent-plugin-airbrake-python 0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ *.gem
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ Moriyoshi Koizumi <mozo@mozo.jp>
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gem 'airbrake'
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Moriyoshi Koizumi
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-airbrake-python"
6
+ gem.description = "Airbrake (Python) plugin for Fluentd"
7
+ gem.homepage = "https://github.com/moriyoshi/fluent-plugin-airbrake-python"
8
+ gem.summary = gem.description
9
+ gem.version = File.read("VERSION").strip
10
+ gem.authors = ["Moriyoshi Koizumi"]
11
+ gem.email = "mozo@mozo.jp"
12
+ gem.has_rdoc = false
13
+ gem.files = `git ls-files`.split($/)
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split($/)
15
+ gem.executables = `git ls-files -- bin/*`.split($/).map{ |f| File.basename(f) }
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_dependency "fluentd", ">= 0"
19
+ gem.add_dependency "airbrake", ">= 3.1"
20
+ end
@@ -0,0 +1,194 @@
1
+ # Copyright 2014 Moriyoshi Koizumi
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'net/http'
16
+ require 'airbrake'
17
+ require 'airbrake/version'
18
+ require 'airbrake/sender'
19
+ require 'airbrake/configuration'
20
+ require 'airbrake/notice'
21
+ require 'airbrake/backtrace'
22
+ require 'airbrake/utils/rack_filters'
23
+ require 'airbrake/utils/params_cleaner'
24
+
25
+ class Fluent::AirbrakePythonOutput < Fluent::Output
26
+ Fluent::Plugin.register_output('airbrake_python', self)
27
+
28
+ PY_LOGLEVEL_MAP = {
29
+ 'CRITICAL' => 50,
30
+ 'FATAL' => 50,
31
+ 'ERROR' => 40,
32
+ 'WARNING' => 30,
33
+ 'WARN' => 30,
34
+ 'INFO' => 20,
35
+ 'DEBUG' => 10,
36
+ 'NOTSET' => 0
37
+ }
38
+
39
+ config_param :host, :string, :default => nil
40
+ config_param :port, :integer, :default => nil
41
+ config_param :proxy_host, :string, :default => nil
42
+ config_param :proxy_port, :integer, :default => nil
43
+ config_param :proxy_user, :string, :default => nil
44
+ config_param :proxy_pass, :string, :default => nil
45
+ config_param :protocol, :string, :default => 'ssl'
46
+ config_param :param_filters, :string, :default => nil
47
+ config_param :development_environments, :string, :default => nil
48
+ config_param :development_lookup, :bool, :default => false
49
+ config_param :environment_name, :string, :default => 'production'
50
+ config_param :project_root, :string, :default => ''
51
+ config_param :notifier_name, :string, :default => nil
52
+ config_param :notifier_version, :string, :default => nil
53
+ config_param :notifier_url, :string, :default => nil
54
+ config_param :user_information, :string, :default => nil
55
+ config_param :framework, :string, :default => nil
56
+ config_param :secure, :bool, :default => true
57
+ config_param :use_system_ssl_cert_chain, :bool, :default => true
58
+ config_param :http_open_timeout, :integer, :default => nil
59
+ config_param :http_read_timeout, :integer, :default => nil
60
+ config_param :project_id, :string, :default => nil
61
+ config_param :api_key, :string
62
+ config_param :message_regexp, :string, :default => '.*'
63
+ config_param :message_template, :string, :default => '\\0'
64
+ config_param :loglevel, :string, :default => 'DEBUG'
65
+ config_param :cgi_data_dump_key, :string, :default => nil
66
+ config_param :parameters_dump_key, :string, :default => nil
67
+ config_param :session_dump_key, :string, :default => nil
68
+
69
+ class Notice < Airbrake::Notice
70
+ def initialize(args)
71
+ backtrace = args.delete(:backtrace)
72
+ super
73
+ @error_class = args[:error_class]
74
+ @backtrace = backtrace
75
+ end
76
+ end
77
+
78
+ def configure(conf)
79
+ super
80
+
81
+ aconf = Airbrake::Configuration.new
82
+ aconf.host = @host
83
+ aconf.port = @port ? @port: (@secure ? 443: 80)
84
+ aconf.proxy_host = @proxy_host
85
+ aconf.proxy_port = @proxy_port
86
+ aconf.proxy_user = @proxy_user
87
+ aconf.proxy_pass = @proxy_pass
88
+ aconf.param_filters = @param_filters.split(/\s+/) if @param_filters
89
+ aconf.development_environments = @development_environments.split(/\s+/) if @development_environments
90
+ aconf.development_lookup = @development_lookup
91
+ aconf.environment_name = @environment_name
92
+ aconf.project_root = @project_root
93
+ aconf.notifier_name = @notifier_name if @notifier_name
94
+ aconf.notifier_version = @notifier_version if @notifier_version
95
+ aconf.notifier_url = @notifier_url if @notifier_url
96
+ aconf.user_information = @user_information if @user_information
97
+ aconf.framework = @framework if @framework
98
+ aconf.secure = @secure
99
+ aconf.use_system_ssl_cert_chain = @use_system_ssl_cert_chain
100
+ aconf.http_open_timeout = @http_open_timeout if @http_open_timeout
101
+ aconf.http_read_timeout = @http_read_timeout if @http_read_timeout
102
+ aconf.project_id = @project_id
103
+ aconf.api_key = @api_key
104
+
105
+ @aconf = aconf
106
+ @sender = Airbrake::Sender.new(aconf)
107
+ @message_regexp = Regexp.new(@message_regexp, Regexp::MULTILINE)
108
+ @loglevel = Integer(@loglevel) rescue PY_LOGLEVEL_MAP[@loglevel]
109
+ end
110
+
111
+ def notification_needed(tag, time, record)
112
+ record['sys_levelno'] >= @loglevel
113
+ end
114
+
115
+ def build_component_name_py(record)
116
+ record['sys_name']
117
+ end
118
+
119
+ def build_action_name_py(record)
120
+ record['sys_funcname']
121
+ end
122
+
123
+ def build_message_py(record)
124
+ record['message'].sub(@message_regexp, @message_template)
125
+ end
126
+
127
+ def build_cgi_data_dump(record)
128
+ if @cgi_data_dump_key
129
+ record[@cgi_data_dump_key]
130
+ else
131
+ nil
132
+ end
133
+ end
134
+
135
+ def build_parameters_dump(record)
136
+ if @parameters_dump_key
137
+ record[@parameters_dump_key]
138
+ else
139
+ nil
140
+ end
141
+ end
142
+
143
+ def build_session_dump(record)
144
+ if @session_dump_key
145
+ record[@session_dump_key]
146
+ else
147
+ nil
148
+ end
149
+ end
150
+
151
+ def notice_from_py_record(aconf, tag, record)
152
+ exc_info_rec = record['sys_exc_info']
153
+ return nil unless exc_info_rec
154
+ error_class = nil
155
+ backtrace = nil
156
+ if exc_info_rec
157
+ error_class = exc_info_rec['type']
158
+ backtrace = Airbrake::Backtrace.new(
159
+ exc_info_rec['traceback'].map { |f|
160
+ Airbrake::Backtrace::Line.new(f[0], f[1], f[2])
161
+ }
162
+ )
163
+ end
164
+
165
+ Notice.new(
166
+ aconf.merge(
167
+ :error_class => error_class,
168
+ :backtrace => backtrace,
169
+ :error_message => build_message_py(record),
170
+ :component => build_component_name_py(record),
171
+ :action => build_action_name_py(record),
172
+ :hostname => record['sys_host'],
173
+ :project_id => aconf[:project_id] || tag,
174
+ :cgi_data => build_cgi_data_dump(record) || {},
175
+ :session_data => build_session_dump(record) || {},
176
+ :parameters => build_parameters_dump(record) || {},
177
+ )
178
+ )
179
+ end
180
+
181
+
182
+ def build_notice(tag, time, record)
183
+ if notification_needed(tag, time, record)
184
+ notice_from_py_record(@aconf, tag, record)
185
+ end
186
+ end
187
+
188
+ def emit(tag, es, chain)
189
+ es.each do |time, record|
190
+ notice = build_notice(tag, time, record)
191
+ @sender.send_to_airbrake(notice) if notice
192
+ end
193
+ end
194
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-airbrake-python
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Moriyoshi Koizumi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fluentd
16
+ requirement: &70211936351300 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70211936351300
25
+ - !ruby/object:Gem::Dependency
26
+ name: airbrake
27
+ requirement: &70211936349340 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70211936349340
36
+ description: Airbrake (Python) plugin for Fluentd
37
+ email: mozo@mozo.jp
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - .gitignore
43
+ - AUTHORS
44
+ - Gemfile
45
+ - LICENSE
46
+ - VERSION
47
+ - fluent-plugin-airbrake-python.gemspec
48
+ - lib/fluent/plugin/out_airbrake_python.rb
49
+ homepage: https://github.com/moriyoshi/fluent-plugin-airbrake-python
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.10
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Airbrake (Python) plugin for Fluentd
73
+ test_files: []