Sha256: 0f1fca31fbedd8493a0fcba9a5051d904c8aa0084bea84d42d39bfaeb6497556

Contents?: true

Size: 995 Bytes

Versions: 6

Compression:

Stored size: 995 Bytes

Contents

require 'fluent/plugin/in_http'
require 'base64'

class Fluent::HttpMixpanelInput < Fluent::HttpInput
  Fluent::Plugin.register_input('http_mixpanel', self)

  config_param :tag_prefix, :default => 'mixpanel'

  def on_request(path_info, params)
    data = Base64.decode64(params['data']).force_encoding('utf-8')
    json = JSON.parse(data)
    props = json['properties']
    path = "/#{tag_prefix}.#{json['event']}"
    params['json'] = props.to_json
    params['time'] = props['time'].to_s if props['time']

    ret = super(path, params)
    
    headers = {
      'Access-Control-Allow-Credentials' => true,
      'Access-Control-Allow-Headers' => 'X-Requested-With',
      'Access-Control-Allow-Methods' => 'GET, POST, OPTIONS',
      'Access-Control-Allow-Origin' => params['HTTP_ORIGIN'],
      'Access-Control-Max-Age' => 1728000,
      'Cache-Control' => 'no-cache, no-store',
      'Content-type' => 'text/plain'
    }

    [ret[0], headers, (ret[0] == '200 OK' ? '1' : '0')]
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fluent-plugin-mixpanel-0.1.0 lib/fluent/plugin/in_http_mixpanel.rb
fluent-plugin-mixpanel-0.0.9 lib/fluent/plugin/in_http_mixpanel.rb
fluent-plugin-mixpanel-0.0.8 lib/fluent/plugin/in_http_mixpanel.rb
fluent-plugin-mixpanel-0.0.7 lib/fluent/plugin/in_http_mixpanel.rb
fluent-plugin-mixpanel-0.0.6 lib/fluent/plugin/in_http_mixpanel.rb
fluent-plugin-mixpanel-0.0.5 lib/fluent/plugin/in_http_mixpanel.rb