Class: Fluent::SentryHttpInput
- Inherits:
-
HttpInput
- Object
- HttpInput
- Fluent::SentryHttpInput
- Defined in:
- lib/fluent/plugin/in_sentry_http.rb
Instance Attribute Summary collapse
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ SentryHttpInput
constructor
A new instance of SentryHttpInput.
- #on_request(path_info, params) ⇒ Object
Constructor Details
#initialize ⇒ SentryHttpInput
Returns a new instance of SentryHttpInput.
11 12 13 14 |
# File 'lib/fluent/plugin/in_sentry_http.rb', line 11 def initialize super @mapping = {} end |
Instance Attribute Details
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
9 10 11 |
# File 'lib/fluent/plugin/in_sentry_http.rb', line 9 def mapping @mapping end |
Instance Method Details
#configure(conf) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fluent/plugin/in_sentry_http.rb', line 16 def configure(conf) super conf.elements.select {|element| element.name == 'project' }.each do |element| @mapping[element.arg] = { 'tag' => element['tag'], 'key' => element['key'], 'secret' => element['secret'], } end end |
#on_request(path_info, params) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fluent/plugin/in_sentry_http.rb', line 29 def on_request(path_info, params) begin project = @mapping[path_info.split('/')[2]] # /api/999/store/ raise 'not found' unless project rescue return ['404 Not Found', {'Content-type' => 'text/plain'}, ''] end begin key, secret = get_auth_info(params) raise 'unauthorized' unless project['key'] == key and project['secret'] == secret rescue return ['401 Unauthorized', {'Content-type' => 'text/plain'}, ''] end begin time, record = parse_params(params) raise 'Record not found' if record.nil? record['tag'] = project['tag'] record['time'] = time if @add_http_headers params.each_pair { |k, v| if k.start_with?('HTTP_') record[k] = v end } end if @add_remote_addr record['REMOTE_ADDR'] = params['REMOTE_ADDR'] end rescue return ['400 Bad Request', {'Content-type' => 'text/plain'}, "400 Bad Request\n#{$!}\n"] end begin router.emit(project['tag'], time, record) rescue return ['500 Internal Server Error', {'Content-type' => 'text/plain'}, "500 Internal Server Error\n#{$!}\n"] end return ['200 OK', {'Content-type' => 'text/plain'}, ''] end |