fluent-plugin-decode_location 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a7696e324681561250bf52e77f0d5bc73ba457d1
4
+ data.tar.gz: 0197fc55126f7c46f396b291774460f36d1398f9
5
+ SHA512:
6
+ metadata.gz: 46318e05963391dcac2bfcbc7cd2002af6e9013ddf190856f3db9eaca8e088f1de6d8530f54279c555c29a328dd349e2335438930cd9dbca2d1d1c3b9ea5233b
7
+ data.tar.gz: 3db1613ab27392e4ab795d741b2b456524c69d98895d470446be9e5c28d14cb32443e6066a9d882370d3c4389b97447de50fc3175113aed3a27dd7a930d71283
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.0.1 (2015/04/02)
2
+ Initial release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-decode_location.gemspec
4
+ gemspec
5
+
6
+ gem 'base62'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 sredni
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ ## Fluent::Plugin::DecodeLoaction, a plugin for [Fluentd](http://fluentd.org)
2
+
3
+ Fluentd plugin to decode location.
4
+
5
+ Basic usage
6
+ ```
7
+ <match foo.**>
8
+ type decode_location
9
+ key parameters.loc
10
+ </match>
11
+
12
+ input
13
+ "test" {
14
+ "parameters":{
15
+ "loc":"2713417160022875720572523180974772929416894547711076940525453875:|WmF3YWR6a2k="
16
+ }
17
+ }
18
+
19
+ output
20
+ "location_decoded.test" {
21
+ "parameters":{
22
+ "loc":"2713417160022875720572523180974772929416894547711076940525453875:|WmF3YWR6a2k="
23
+ },
24
+ "lat": "50.6099014282",
25
+ "lng": "18.4776992798",
26
+ "continent": "EU",
27
+ "countryCode": "PL",
28
+ "province": "79",
29
+ "city": "Zawadzki"
30
+ }
31
+ ```
32
+
33
+ If you want create key with parsed data.
34
+ ```
35
+ <match foo.**>
36
+ type decode_location
37
+ key location.loc
38
+ sub_key location
39
+ </match>
40
+
41
+ input
42
+ "test" {
43
+ "parameters":{
44
+ "loc":"2713417160022875720572523180974772929416894547711076940525453875:|WmF3YWR6a2k="
45
+ }
46
+ }
47
+
48
+ output
49
+ "location_decoded.test" {
50
+ "parameters":{
51
+ "loc":"2713417160022875720572523180974772929416894547711076940525453875:|WmF3YWR6a2k="
52
+ },
53
+ "location": {
54
+ "lat": "50.6099014282",
55
+ "lng": "18.4776992798",
56
+ "continent": "EU",
57
+ "countryCode": "PL",
58
+ "province": "79",
59
+ "city": "Zawadzki"
60
+ }
61
+ }
62
+ ```
63
+
64
+ ## Option Parameters
65
+
66
+ ### key :String
67
+ key is used to point a key thad is cookie.
68
+
69
+ ### tag_prefix :String
70
+ Added tag prefix.
71
+ Default value is "parsed."
72
+
73
+ ### sub_key :String
74
+ You want to put parsed data into separate key.
75
+ Default value is false.
76
+
77
+ ## Change log
78
+ See [CHANGELOG.md](https://github.com/sredni/fluent-plugin-decode_location/blob/master/CHANGELOG.md) for details.
79
+
80
+ ## Contributing
81
+
82
+ 1. Fork it ( https://github.com/sredni/fluent-plugin-decode_location/fork )
83
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
84
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
85
+ 4. Push to the branch (`git push origin my-new-feature`)
86
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.verbose = true
9
+ end
@@ -0,0 +1,28 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'fluent/plugin/decode_location/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "fluent-plugin-decode_location"
6
+ spec.version = Fluent::DecodeLocation::VERSION
7
+ spec.authors = ["L. Srednicki"]
8
+ spec.email = ["lukasz@sredni.pl"]
9
+ spec.summary = %q{Fluentd plugin to decode location}
10
+ spec.description = %q{Fluentd plugin to decode location}
11
+ spec.homepage = ""
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "fluentd"
20
+ spec.add_development_dependency "bundler"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "pry"
23
+ spec.add_development_dependency "pry-byebug"
24
+ spec.add_development_dependency "pry-nav"
25
+ spec.add_development_dependency "test-unit"
26
+ spec.add_development_dependency "rr"
27
+ spec.add_development_dependency "timecop"
28
+ end
@@ -0,0 +1,5 @@
1
+ module Fluent
2
+ module DecodeLocation
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,90 @@
1
+ module Fluent
2
+ class DecodeLocationOutput < Output
3
+ Fluent::Plugin.register_output('decode_location', self)
4
+ config_param :key, :string, :default => 'parameters.loc'
5
+ config_param :tag_prefix, :string, :default => 'location_decoded.'
6
+ config_param :sub_key, :string, :default => nil
7
+
8
+ SEPARATOR = 'a';
9
+ SEPARATOR_DOT = 'b';
10
+ SEPARATOR_DASH = 'c';
11
+
12
+ def initialize
13
+ super
14
+ require 'base62'
15
+ require 'base64'
16
+ end
17
+
18
+ # Define `log` method for v0.10.42 or earlier
19
+ unless method_defined?(:log)
20
+ define_method("log") { $log }
21
+ end
22
+
23
+ def configure(conf)
24
+ super
25
+ end
26
+
27
+ def start
28
+ super
29
+ end
30
+
31
+ def shutdown
32
+ super
33
+ end
34
+
35
+ def emit(tag, es, chain)
36
+ es.each {|time, record|
37
+ t = tag.dup
38
+ new_record = decode_location(record)
39
+
40
+ t = @tag_prefix + t unless @tag_prefix.nil?
41
+
42
+ Engine.emit(t, time, new_record)
43
+ }
44
+ chain.next
45
+ rescue => e
46
+ log.warn("out_decode_location: error_class:#{e.class} error_message:#{e.message} tag:#{tag} es:#{es} bactrace:#{e.backtrace.first}")
47
+ end
48
+
49
+ def decode_location(record)
50
+ source = record
51
+
52
+ key.split('.').each do |v|
53
+ if source[v.to_sym]
54
+ source = source[v.to_sym]
55
+ else
56
+ record['break'] = true
57
+ source = nil
58
+ break
59
+ end
60
+ end
61
+
62
+ if source
63
+ hash = {}
64
+ city = ''
65
+
66
+ if source.include? ":|"
67
+ exploded = source.split(":|")
68
+ source = exploded[0]
69
+ city = exploded[1]
70
+ end
71
+
72
+ array = source.to_i.base62_encode.gsub(SEPARATOR_DASH, '-').gsub(SEPARATOR_DOT, '.').split(SEPARATOR)
73
+
74
+ hash['lat'] = array[0] ? array[0] : ''
75
+ hash['lng'] = array[1] ? array[1] : ''
76
+ hash['continent'] = array[2] ? array[2] : ''
77
+ hash['countryCode'] = array[3] ? array[3] : ''
78
+ hash['province'] = array[4] ? array[4] : ''
79
+ hash['city'] = city ? Base64.decode64(city) : ''
80
+
81
+ target = sub_key ? (record[sub_key] ||= {}) : record
82
+
83
+ target.merge!(hash)
84
+ end
85
+ return record
86
+ rescue => e
87
+ log.warn("out_decode_location: error_class:#{e.class} error_message:#{e.message} tag:#{tag} record:#{record} bactrace:#{e.backtrace.first}")
88
+ end
89
+ end
90
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ # pass
20
+ end
21
+ }
22
+ $log = nulllogger
23
+ end
24
+
25
+ require 'fluent/plugin/out_decode_location'
26
+
27
+ class Test::Unit::TestCase
28
+ end
@@ -0,0 +1,109 @@
1
+ require 'helper'
2
+ require 'rr'
3
+ require 'timecop'
4
+ require 'pry-byebug'
5
+ require 'fluent/plugin/out_decode_location'
6
+
7
+ class DecodeLoactionOutputTest < Test::Unit::TestCase
8
+
9
+ RECORD = {
10
+ "remote":"93.97.192.253",
11
+ "host":"-",
12
+ "user":"-",
13
+ "datetime":"02/Apr/2015:10:05:49 +0200",
14
+ "method":"GET",
15
+ "path":"/widget/core.js?key=D111-96FC-CF47-5B47-1WKpvg&type=2&domain=zmianynaziemi.pl&loc=2713417160022875720572523180974772929416894547711076940525453875:|WmF3YWR6a2k=&url=http%3A%2F%2Fzmianynaziemi.pl%2Fwiadomosc%2Fdoradca-putina-wysmial-publicznie-wiare-ze-brzoza-spowodowala-katastrofe-w-smolensku&is_mobile=false&lang=&cnt=2&ts=1427961948895&referer=http%3A%2F%2Fwww.google.co.uk%2Furl%3Fsa%3Dt%26rct%3Dj%26q%3D%26esrc%3Ds%26source%3Dweb%26cd%3D20%26ved%3D0CHMQFjAJOAo%26url%3Dhttp%253A%252F%252Fzmianynaziemi.pl%252Fwiadomosc%252Fdoradca-putina-wysmial-publicznie-wiare-ze-brzoza-spowodowala-katastrofe-w-smolensku%26ei%3DWvccVf3LAdPSaOKFgYAK%26usg%3DAFQjCNGh8yfYXkXFOEYt4UucoG6uO1H1VQ%26bvm%3Dbv.89744112%2Cd.d2s&status=0&live_preview_hash=&",
16
+ "code":"200",
17
+ "size":"2195",
18
+ "referer":"http://zmianynaziemi.pl/wiadomosc/doradca-putina-wysmial-publicznie-wiare-ze-brzoza-spowodowala-katastrofe-w-smolensku",
19
+ "agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0",
20
+ "parameters":{
21
+ "key":"D111-96FC-CF47-5B47-1WKpvg",
22
+ "type":"2",
23
+ "domain":
24
+ "zmianynaziemi.pl",
25
+ "loc":"2713417160022875720572523180974772929416894547711076940525453875:|WmF3YWR6a2k=",
26
+ "url":"http://zmianynaziemi.pl/wiadomosc/doradca-putina-wysmial-publicznie-wiare-ze-brzoza-spowodowala-katastrofe-w-smolensku",
27
+ "is_mobile":"false",
28
+ "lang":"",
29
+ "cnt":"2",
30
+ "ts":"1427961948895",
31
+ "referer":"http://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=20&ved=0CHMQFjAJOAo&url=http%3A%2F%2Fzmianynaziemi.pl%2Fwiadomosc%2Fdoradca-putina-wysmial-publicznie-wiare-ze-brzoza-spowodowala-katastrofe-w-smolensku&ei=WvccVf3LAdPSaOKFgYAK&usg=AFQjCNGh8yfYXkXFOEYt4UucoG6uO1H1VQ&bvm=bv.89744112,d.d2s",
32
+ "status":"0",
33
+ "live_preview_hash":""
34
+ },
35
+ "cookie":{
36
+ "__nc_ms":"c9f833a16d69432eb5f6f538883b026a"
37
+ }
38
+ }
39
+
40
+ def setup
41
+ Fluent::Test.setup
42
+ Timecop.freeze(@time)
43
+ end
44
+
45
+ teardown do
46
+ Timecop.return
47
+ end
48
+
49
+ def create_driver(conf, tag)
50
+ Fluent::Test::OutputTestDriver.new(
51
+ Fluent::DecodeLocationOutput, tag
52
+ ).configure(conf)
53
+ end
54
+
55
+ def emit(conf, record, tag='test')
56
+ d = create_driver(conf, tag)
57
+ d.run {d.emit(record)}
58
+ emits = d.emits
59
+ end
60
+
61
+ def test_configure
62
+ d = create_driver(%[
63
+ key test
64
+ ], "test")
65
+
66
+ assert_equal 'test', d.instance.key
67
+ assert_equal 'location_decoded.', d.instance.tag_prefix
68
+ end
69
+
70
+ def test_decode
71
+ conf = %[
72
+
73
+ ]
74
+
75
+ record = RECORD.dup
76
+
77
+ emits = emit(conf, record)
78
+
79
+ emits.each_with_index do |(tag, time, record), i|
80
+ assert_equal 'location_decoded.test', tag
81
+ assert_equal '50.6099014282', record['lat']
82
+ assert_equal '18.4776992798', record['lng']
83
+ assert_equal 'EU', record['continent']
84
+ assert_equal 'PL', record['countryCode']
85
+ assert_equal '79', record['province']
86
+ assert_equal 'Zawadzki', record['city']
87
+ end
88
+ end
89
+
90
+ def test_sub_key
91
+ conf = %[
92
+ sub_key location
93
+ ]
94
+
95
+ record = RECORD.dup
96
+
97
+ emits = emit(conf, record)
98
+
99
+ emits.each_with_index do |(tag, time, record), i|
100
+ assert_equal 'location_decoded.test', tag
101
+ assert_equal '50.6099014282', record['location']['lat']
102
+ assert_equal '18.4776992798', record['location']['lng']
103
+ assert_equal 'EU', record['location']['continent']
104
+ assert_equal 'PL', record['location']['countryCode']
105
+ assert_equal '79', record['location']['province']
106
+ assert_equal 'Zawadzki', record['location']['city']
107
+ end
108
+ end
109
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-decode_location
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - L. Srednicki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-nav
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: test-unit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: timecop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Fluentd plugin to decode location
140
+ email:
141
+ - lukasz@sredni.pl
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - CHANGELOG.md
148
+ - Gemfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - fluent-plugin-decode_location.gemspec
153
+ - lib/fluent/plugin/decode_location/version.rb
154
+ - lib/fluent/plugin/out_decode_location.rb
155
+ - test/helper.rb
156
+ - test/plugin/test_out_decode_location.rb
157
+ homepage: ''
158
+ licenses:
159
+ - MIT
160
+ metadata: {}
161
+ post_install_message:
162
+ rdoc_options: []
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ required_rubygems_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubyforge_project:
177
+ rubygems_version: 2.4.6
178
+ signing_key:
179
+ specification_version: 4
180
+ summary: Fluentd plugin to decode location
181
+ test_files:
182
+ - test/helper.rb
183
+ - test/plugin/test_out_decode_location.rb