Sha256: 03a84c104ebacb012ce4b9c600b0d37173f4ebb2e263b8244a49b7111c114458

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

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

class Fluent::HttpMixpanelInput < Fluent::Plugin::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)
    domain = params['HTTP_ORIGIN'].sub('://', '_').gsub('.', '_')
    props = json['properties']
    path = "/#{tag_prefix}.#{domain}.#{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

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-mixpanel-enchanced-0.0.13 lib/fluent/plugin/in_http_mixpanel.rb