logstash-filter-mixpanel 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +4 -1
- data/README.md +5 -3
- data/lib/logstash/filters/mixpanel.rb +25 -10
- data/logstash-filter-mixpanel.gemspec +5 -2
- data/mixpanel_test.rb +43 -0
- data/spec/filters/mixpanel_spec.rb +100 -7
- metadata +46 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDA1YzRhYzRiMTJhYzRlZDliOTQ1NjI3NmJhM2I0NjQ5ZjJmN2Y2Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Nzg2ZDMxYzYzNzdlY2Q3NzY2YTgzZDJkZjEwZjg4NWFlM2YyMDg1OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGQ3M2VjMjRmMzk3NWVjYTJmOTNlMjJkOTlhYjcwM2RjNGE4YzVjZTJjODFm
|
10
|
+
ZWFkMzFhMjUwNzU1N2ZhNjY4NjQ4YzY5YjdjNjc1NmQwZTBiZWNkNmFiZmE3
|
11
|
+
ZTJjOTY4NjBhYzhmMjUxMmQ5N2RiYTg2NGM2ZGE1YzBmNDY5NGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTY3MjBmMjdiYWIzYjM2M2MyZGVhYjJhMzU1ZDZlNmI4MGU4MDY2YjQxNDdk
|
14
|
+
NWY1OTg4Nzg1ZjM4OTE2NWFkMTcwN2I5ZDk3YmUzN2MyN2U0YzE4MTU4N2Zh
|
15
|
+
YTgyOGRjNjlkNWRhMDZlMWZhYTYyZmI0ZTRkYjBiOWU1NmQ1YTA=
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ It is fully free and fully open source. The license is Apache 2.0, meaning you a
|
|
6
6
|
|
7
7
|
# Status
|
8
8
|
- [![Gem Version](https://badge.fury.io/rb/logstash-filter-mixpanel.svg)](http://badge.fury.io/rb/logstash-filter-mixpanel)
|
9
|
-
- [![Build Status](https://travis-ci.org/torstenfeld/logstash-filter-mixpanel.svg?branch=master)](https://travis-ci.org/torstenfeld/logstash-filter-mixpanel)
|
9
|
+
- [![Build Status](https://travis-ci.org/torstenfeld/logstash-filter-mixpanel.svg?branch=master)](https://travis-ci.org/torstenfeld/logstash-filter-mixpanel)
|
10
10
|
- [![Coverage Status](https://coveralls.io/repos/torstenfeld/logstash-filter-mixpanel/badge.svg?branch=master)](https://coveralls.io/r/torstenfeld/logstash-filter-mixpanel?branch=master)
|
11
11
|
- [![Code Climate](https://codeclimate.com/github/torstenfeld/logstash-filter-mixpanel/badges/gpa.svg)](https://codeclimate.com/github/torstenfeld/logstash-filter-mixpanel)
|
12
12
|
- [![Dependency Status](https://gemnasium.com/torstenfeld/logstash-filter-mixpanel.svg)](https://gemnasium.com/torstenfeld/logstash-filter-mixpanel)
|
@@ -15,8 +15,7 @@ It is fully free and fully open source. The license is Apache 2.0, meaning you a
|
|
15
15
|
|
16
16
|
- Edit Logstash `Gemfile` and add needed requirements:
|
17
17
|
```ruby
|
18
|
-
gem "
|
19
|
-
gem "logstash-filter-mixpanel", ">= 0.2.0", :git => "https://github.com/torstenfeld/logstash-filter-mixpanel.git"
|
18
|
+
gem "logstash-filter-mixpanel", ">= 0.1.0", :git => "https://github.com/torstenfeld/logstash-filter-mixpanel.git"
|
20
19
|
```
|
21
20
|
|
22
21
|
|
@@ -24,3 +23,6 @@ gem "logstash-filter-mixpanel", ">= 0.2.0", :git => "https://github.com/torstenf
|
|
24
23
|
```sh
|
25
24
|
bundle install
|
26
25
|
```
|
26
|
+
|
27
|
+
# Using
|
28
|
+
[![Mixpanel Logo](https://cdn.mxpnl.com/site_media/images/partner/badge_blue.png)](https://mixpanel.com/f/partner)
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "logstash/filters/base"
|
3
3
|
require "logstash/namespace"
|
4
|
+
require 'mixpanel_client'
|
4
5
|
|
5
6
|
# This example filter will replace the contents of the default
|
6
7
|
# message field with whatever you specify in the configuration.
|
7
8
|
#
|
8
9
|
# It is only intended to be used as an example.
|
9
|
-
class LogStash::Filters::
|
10
|
+
class LogStash::Filters::Mixpanel < LogStash::Filters::Base
|
10
11
|
|
11
12
|
# Setting the config_name here is required. This is how you
|
12
13
|
# configure this filter from your Logstash config.
|
@@ -17,27 +18,41 @@ class LogStash::Filters::Example < LogStash::Filters::Base
|
|
17
18
|
# }
|
18
19
|
# }
|
19
20
|
#
|
20
|
-
config_name "
|
21
|
+
config_name "mixpanel"
|
21
22
|
|
22
23
|
# Replace the message with this value.
|
23
|
-
config :
|
24
|
-
|
24
|
+
config :api_key, :validate => :string, :required => true
|
25
|
+
config :api_secret, :validate => :string, :required => true
|
26
|
+
config :where, :validate => :string, :required => true
|
27
|
+
config :source, :validate => :string, :default => 'message'
|
28
|
+
config :target, :validate => :string, :default => 'mixpanel'
|
29
|
+
|
25
30
|
|
26
31
|
public
|
27
32
|
def register
|
28
|
-
|
33
|
+
@mp = Mixpanel::Client.new(
|
34
|
+
api_key: @api_key,
|
35
|
+
api_secret: @api_secret
|
36
|
+
)
|
29
37
|
end # def register
|
30
38
|
|
31
39
|
public
|
32
40
|
def filter(event)
|
33
41
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
42
|
+
result = fetch_data
|
43
|
+
# TODO: remove puts result
|
44
|
+
puts result
|
45
|
+
event[@target] = result
|
39
46
|
|
40
47
|
# filter_matched should go in the last line of our successful code
|
41
48
|
filter_matched(event)
|
42
49
|
end # def filter
|
50
|
+
|
51
|
+
private
|
52
|
+
def fetch_data
|
53
|
+
options = {}
|
54
|
+
# options['where'] = @where if @where
|
55
|
+
result = @mp.request('engage', options)
|
56
|
+
result
|
57
|
+
end
|
43
58
|
end # class LogStash::Filters::Example
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-filter-mixpanel'
|
3
|
-
s.version
|
3
|
+
s.version = '0.1.1'
|
4
4
|
s.version = "#{s.version}.pre.#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS'] and ENV['TRAVIS_BRANCH'] != 'master'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "This filter checks mixpanel for additional people data and adds it to the event data"
|
@@ -20,6 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
# Gem dependencies
|
22
22
|
s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
|
23
|
+
s.add_runtime_dependency "mixpanel_client", '~> 4.1'
|
23
24
|
s.add_development_dependency 'logstash-devutils'
|
24
|
-
s.add_development_dependency 'coveralls', '~> 0.8
|
25
|
+
s.add_development_dependency 'coveralls', '~> 0.8'
|
26
|
+
s.add_development_dependency 'ffaker', '~> 2.0'
|
27
|
+
s.add_development_dependency 'mixpanel-ruby', '< 2.0'
|
25
28
|
end
|
data/mixpanel_test.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# require File.absolute_path(File.join(File.dirname(__FILE__), 'lib/logstash/filters/mixpanel'))
|
2
|
+
# require 'lib/logstash/filters/mixpanel'
|
3
|
+
|
4
|
+
|
5
|
+
class MixpanelTest
|
6
|
+
def initialize
|
7
|
+
require 'rubygems'
|
8
|
+
require 'mixpanel_client'
|
9
|
+
@mp = Mixpanel::Client.new(
|
10
|
+
api_key: ENV['MP_PROJECT_KEY'],
|
11
|
+
api_secret: ENV['MP_PROJECT_SECRET']
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
result = fetch_data
|
17
|
+
result
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def fetch_data
|
22
|
+
result = @mp.request('engage', {})
|
23
|
+
result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# mpt = MixpanelTest.new
|
28
|
+
# mpt.config
|
29
|
+
# res = mpt.run
|
30
|
+
# puts res.inspect
|
31
|
+
|
32
|
+
test_hash = {
|
33
|
+
'filter' {
|
34
|
+
'languagedetect' => {
|
35
|
+
'api_key' => ENV['MP_PROJECT_KEY'],
|
36
|
+
'api_secret' => ENV['MP_PROJECT_SECRET'],
|
37
|
+
'where' => '123'
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
test_string = test_hash.to_s
|
43
|
+
puts test_string
|
@@ -1,20 +1,113 @@
|
|
1
1
|
require File.absolute_path(File.join(File.dirname(__FILE__), '../../spec/spec_helper'))
|
2
2
|
require File.absolute_path(File.join(File.dirname(__FILE__), '../../lib/logstash/filters/mixpanel'))
|
3
|
+
require 'mixpanel_client'
|
4
|
+
require 'mixpanel-ruby'
|
5
|
+
require 'ffaker'
|
6
|
+
require 'base64'
|
3
7
|
|
4
|
-
|
5
|
-
|
8
|
+
|
9
|
+
describe LogStash::Filters::Mixpanel do
|
10
|
+
before(:all) do
|
11
|
+
@mp = Mixpanel::Tracker.new(ENV['MP_PROJECT_TOKEN'])
|
12
|
+
|
13
|
+
@user_id = FFaker::Guid.guid
|
14
|
+
@user_ip = FFaker::Internet.ip_v4_address
|
15
|
+
@user_data = {
|
16
|
+
:$first_name => FFaker::NameDE.first_name,
|
17
|
+
:$last_name => FFaker::NameDE.last_name,
|
18
|
+
:$email => FFaker::Internet.safe_email
|
19
|
+
}
|
20
|
+
@mp.people.set(@user_id, @user_data, ip=@user_ip)
|
21
|
+
@mp.track(@user_id, 'user created')
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'raise error' do
|
25
|
+
context 'on wrong api key config' do
|
26
|
+
subject {
|
27
|
+
config = {
|
28
|
+
'api_key' => 123
|
29
|
+
}
|
30
|
+
filter = LogStash::Filters::Mixpanel.new config
|
31
|
+
}
|
32
|
+
|
33
|
+
it 'should raise error on invalid api key config' do
|
34
|
+
insist { subject.register }.raises(LogStash::ConfigurationError)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'on wrong api secret config' do
|
39
|
+
subject {
|
40
|
+
config = {
|
41
|
+
'api_secret' => 123
|
42
|
+
}
|
43
|
+
filter = LogStash::Filters::Mixpanel.new config
|
44
|
+
}
|
45
|
+
|
46
|
+
it 'should raise error on invalid api secret config' do
|
47
|
+
insist { subject.register }.raises(LogStash::ConfigurationError)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'on invalid api key' do
|
52
|
+
subject {
|
53
|
+
config = {
|
54
|
+
'api_key' => '123',
|
55
|
+
'api_secret' => '123',
|
56
|
+
'where' => '123'
|
57
|
+
}
|
58
|
+
filter = LogStash::Filters::Mixpanel.new config
|
59
|
+
filter.register
|
60
|
+
filter.filter LogStash::Event.new
|
61
|
+
}
|
62
|
+
|
63
|
+
it 'should raise error on invalid api key' do
|
64
|
+
insist { subject.filter.flush }.raises(Mixpanel::HTTPError)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'on invalid api secret' do
|
69
|
+
subject {
|
70
|
+
config = {
|
71
|
+
'api_key' => ENV['MP_PROJECT_KEY'],
|
72
|
+
'api_secret' => '123',
|
73
|
+
'where' => '123'
|
74
|
+
}
|
75
|
+
filter = LogStash::Filters::Mixpanel.new config
|
76
|
+
filter.register
|
77
|
+
filter.filter LogStash::Event.new
|
78
|
+
# filter.filter LogStash::Event.new({'message' => 'test'})
|
79
|
+
}
|
80
|
+
|
81
|
+
it 'should raise error on invalid api secret' do
|
82
|
+
insist { subject.filter.flush }.raises(Mixpanel::HTTPError)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'fetch created user' do
|
6
88
|
let(:config) do <<-CONFIG
|
7
89
|
filter {
|
8
|
-
|
9
|
-
|
90
|
+
mixpanel {
|
91
|
+
api_key => '#{ENV['MP_PROJECT_KEY']}'
|
92
|
+
api_secret => '#{ENV['MP_PROJECT_SECRET']}'
|
93
|
+
where => '123'
|
10
94
|
}
|
11
95
|
}
|
12
96
|
CONFIG
|
13
97
|
end
|
14
98
|
|
15
|
-
sample("message" => "
|
16
|
-
|
17
|
-
|
99
|
+
# sample("message" => "123") do
|
100
|
+
# expect(subject).to include('mixpanel')
|
101
|
+
# end
|
102
|
+
|
103
|
+
context 'by distinct id' do
|
104
|
+
sample("message" => "123") do
|
105
|
+
expect(subject).to include('mixpanel')
|
106
|
+
end
|
18
107
|
end
|
19
108
|
end
|
109
|
+
|
110
|
+
after(:all) do
|
111
|
+
@mp.people.delete_user(@user_id)
|
112
|
+
end
|
20
113
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-mixpanel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Torsten Feld
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - <
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 2.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mixpanel_client
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '4.1'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '4.1'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: logstash-devutils
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,14 +64,42 @@ dependencies:
|
|
50
64
|
requirements:
|
51
65
|
- - ~>
|
52
66
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0.8
|
67
|
+
version: '0.8'
|
54
68
|
type: :development
|
55
69
|
prerelease: false
|
56
70
|
version_requirements: !ruby/object:Gem::Requirement
|
57
71
|
requirements:
|
58
72
|
- - ~>
|
59
73
|
- !ruby/object:Gem::Version
|
60
|
-
version: 0.8
|
74
|
+
version: '0.8'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: ffaker
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ~>
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ~>
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: mixpanel-ruby
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - <
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '2.0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - <
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '2.0'
|
61
103
|
description: This gem is a logstash plugin required to be installed on top of the
|
62
104
|
Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
|
63
105
|
a stand-alone program
|
@@ -77,6 +119,7 @@ files:
|
|
77
119
|
- Rakefile
|
78
120
|
- lib/logstash/filters/mixpanel.rb
|
79
121
|
- logstash-filter-mixpanel.gemspec
|
122
|
+
- mixpanel_test.rb
|
80
123
|
- spec/filters/mixpanel_spec.rb
|
81
124
|
- spec/spec_helper.rb
|
82
125
|
homepage: https://github.com/torstenfeld/logstash-filter-mixpanel
|