logstash-output-thinkingdata 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c02a307fd4272626a3066db6f4d924767fa058dbb889477583d19db2b195b9e3
4
+ data.tar.gz: e019db8cd60d9fd6625d6a16391f2bcd899c88082442d6004579b3213fc8e7e4
5
+ SHA512:
6
+ metadata.gz: f990de3bab4004e223ad6f9691ec22f217f51ed711d617036fd14527ddc73a4fa353da3aae9713a95533006cb0793aba44aa9b999d57acc9369da7e590c2dc70
7
+ data.tar.gz: 92787899f34fc00787ec28130b91013a8197e5ba22534a6958a0fec36c602ef5dd5a816c9f6744818cf8f9ddb941c89c2cd9b087f8efa0ed713dd39f6552d077
@@ -0,0 +1,2 @@
1
+ **v0.1.1** (2020-04-27)
2
+ - thinkingdata output plugin created with the logstash plugin generator
@@ -0,0 +1,10 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * xuzz - xuzz@thinkingdata.cn
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ Logstash, and you aren't on the list above and want to be, please let us know
9
+ and we'll make sure you're here. Contributions from folks like you are what make
10
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-output-thinkingdata
2
+ Example output plugin. This should help bootstrap your effort to write your own output plugin!
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'net-http-persistent'
5
+
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
@@ -0,0 +1,73 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
6
+
7
+ ## Documentation
8
+
9
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
10
+
11
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+
33
+ ### 2. Running your unpublished Plugin in Logstash
34
+
35
+ #### 2.1 Run in a local Logstash clone
36
+
37
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
38
+ ```ruby
39
+ gem "logstash-output-thinkingdata", :path => "/your/local/logstash-output-thinkingdata"
40
+ ```
41
+ - Install plugin
42
+ ```sh
43
+ bin/logstash-plugin install --no-verify
44
+ ```
45
+ - Run Logstash with your plugin
46
+ ```sh
47
+ bin/logstash -e 'output {thinkingdata {url => "url",appid => "appid"}}'
48
+ ```
49
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
50
+
51
+ #### 2.2 Run in an installed Logstash
52
+
53
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
54
+
55
+ - Build your plugin gem
56
+ ```sh
57
+ gem build logstash-output-thinkingdata.gemspec
58
+ ```
59
+ - Install the plugin from the Logstash home
60
+ ```sh
61
+ bin/logstash-plugin install /your/local/plugin/logstash-output-thinkingdata.gem
62
+ ```
63
+ - Start Logstash and proceed to test the plugin
64
+
65
+ ## Contributing
66
+
67
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
68
+
69
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
70
+
71
+ It is more important to the community that you are able to contribute.
72
+
73
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,121 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "logstash/namespace"
4
+ require "logstash/plugin_mixins/http_client"
5
+ require "stud/buffer"
6
+ require "zlib"
7
+ require "json"
8
+
9
+
10
+ # An thinkingdata output that does nothing.
11
+ class LogStash::Outputs::Thinkingdata < LogStash::Outputs::Base
12
+
13
+ include Stud::Buffer
14
+ include LogStash::PluginMixins::HttpClient
15
+
16
+ attr_accessor :buffer_state
17
+
18
+ config_name "thinkingdata"
19
+ concurrency :single
20
+
21
+ # URL to use
22
+ config :url, :validate => :string, :required => :true
23
+
24
+ # 数据的项目appid
25
+ config :appid, :validate => :string, :required => :true
26
+
27
+ # 触发 flush 间隔时间
28
+ config :flush_interval_sec, :validate => :number, :default => 2
29
+
30
+ # 批次flush 最大 content 数量
31
+ config :flush_batch_size, :validate => :number, :default => 100
32
+
33
+ # 是否压缩数据 0:不压缩,1:gzip压缩
34
+ config :compress, :validate => :number, :default => 1
35
+
36
+ PLUGIN_VERSION = "0.1.1"
37
+
38
+ public
39
+ def register
40
+ @logger.info("Registering thinkingdata Output",
41
+ :url => @url,
42
+ :appid => @appid,
43
+ :flush_interval_sec => @flush_interval_sec,
44
+ :flush_batch_size => @flush_batch_size,
45
+ :compress =>@compress
46
+ )
47
+
48
+ http_client_config = client_config
49
+ http_client_config[:user_agent] = "thinkingdata_logstash_output_plugin_" + PLUGIN_VERSION
50
+ @client = Manticore::Client.new(http_client_config)
51
+ appid_check
52
+ buffer_config = {
53
+ :max_items => @flush_batch_size.to_i,
54
+ :max_interval => @flush_interval_sec.to_i,
55
+ :logger => @logger
56
+ }
57
+ buffer_initialize(buffer_config)
58
+ end # def register
59
+
60
+ #验证appid
61
+ public
62
+ def appid_check
63
+ @server_uri = URI(@url)
64
+ @server_uri.path = "/check_appid"
65
+ @server_uri.query= "appid="+@appid
66
+ response = client.get(@server_uri.to_s).call
67
+ result = JSON.parse(response.body)
68
+ if result['code'] == -2
69
+ @logger.error("APPID 错误,请检查APPID。")
70
+ raise
71
+ end
72
+ end
73
+
74
+ public
75
+ def multi_receive(events)
76
+ return if events.empty?
77
+
78
+ events.each do |e|
79
+ begin
80
+ content = JSON.parse(e.get("message"))
81
+ buffer_receive(content)
82
+ rescue
83
+ @logger.error("Could not process content", :content => e.to_s)
84
+ end
85
+ end
86
+ # return "Event received"
87
+ end # def event
88
+
89
+ public
90
+ def close
91
+ buffer_flush(:final => true)
92
+ client.close
93
+ end
94
+
95
+ public
96
+ def flush(events, final = false)
97
+ if @compress == 0
98
+ data = events.to_json
99
+ compress_type = 'none'
100
+ else
101
+ gz = StringIO.new("w")
102
+ gz.set_encoding("BINARY")
103
+ z = Zlib::GzipWriter.new(gz)
104
+ z.write(events.to_json)
105
+ z.close
106
+ data = gz.string
107
+ compress_type = 'gzip'
108
+ end
109
+ headers ={'appid' => @appid,'version'=>PLUGIN_VERSION,'user-agent' =>'logstash_'+ PLUGIN_VERSION,
110
+ 'compress' => compress_type}
111
+ response = client.post(@url, :body => data,:headers =>headers).call
112
+ result = JSON.parse(response.body)
113
+ if response.code != 200
114
+ @logger.warn("Send failed, code: #{response.code}, body: #{response.body}")
115
+ raise
116
+ end
117
+ if result['code'] != 0
118
+ @logger.error(" Send failed data:" , :failData => events.to_json,:responseBody => response.body)
119
+ end
120
+ end
121
+ end # class LogStash::Outputs::Thinkingdata
@@ -0,0 +1,30 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-thinkingdata'
3
+ s.version = '0.1.1'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Output plugin for Thinkingdata Analytics'
6
+ s.description = 'This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program.'
7
+ s.homepage = 'https://www.thinkingdata.cn/manual/api.html'
8
+ s.authors = ['xuzz']
9
+ s.email = 'xuzz@thinkingdata.cn'
10
+ s.require_paths = ['lib']
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
22
+ s.add_runtime_dependency "logstash-codec-plain"
23
+ s.add_runtime_dependency 'logstash-mixin-http_client', ">= 6.0.0", "< 8.0.0"
24
+ s.add_runtime_dependency 'stud', "~> 0.0.23"
25
+
26
+ s.add_development_dependency "logstash-devutils"
27
+ s.add_development_dependency 'sinatra'
28
+ s.add_development_dependency 'webrick'
29
+
30
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/outputs/thinkingdata"
4
+ require "logstash/codecs/plain"
5
+ require "logstash/event"
6
+
7
+ describe LogStash::Outputs::Thinkingdata do
8
+ let(:sample_event) { LogStash::Event.new }
9
+ let(:output) { LogStash::Outputs::Thinkingdata.new }
10
+
11
+ before do
12
+ output.register
13
+ end
14
+
15
+ describe "receive message" do
16
+ subject { output.receive(sample_event) }
17
+
18
+ it "returns a string" do
19
+ expect(subject).to eq("Event received")
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-thinkingdata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - xuzz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.60'
20
+ - - "<="
21
+ - !ruby/object:Gem::Version
22
+ version: '2.99'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.60'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-codec-plain
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-mixin-http_client
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 6.0.0
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: 8.0.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 6.0.0
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: 8.0.0
67
+ - !ruby/object:Gem::Dependency
68
+ name: stud
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: 0.0.23
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: 0.0.23
81
+ - !ruby/object:Gem::Dependency
82
+ name: logstash-devutils
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: sinatra
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: webrick
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ description: This gem is a logstash plugin required to be installed on top of the
124
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
125
+ gem is not a stand-alone program.
126
+ email: xuzz@thinkingdata.cn
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - CHANGELOG.md
132
+ - CONTRIBUTORS
133
+ - DEVELOPER.md
134
+ - Gemfile
135
+ - LICENSE
136
+ - README.md
137
+ - lib/logstash/outputs/thinkingdata.rb
138
+ - logstash-output-thinkingdata.gemspec
139
+ - spec/outputs/thinkingdata_spec.rb
140
+ homepage: https://www.thinkingdata.cn/manual/api.html
141
+ licenses:
142
+ - Apache-2.0
143
+ metadata:
144
+ logstash_plugin: 'true'
145
+ logstash_group: output
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubygems_version: 3.0.3
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Output plugin for Thinkingdata Analytics
165
+ test_files:
166
+ - spec/outputs/thinkingdata_spec.rb