logstash-output-logservice 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +7 -0
  3. data/CONTRIBUTORS +11 -0
  4. data/DEVELOPER.md +2 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +13 -0
  7. data/NOTICE.TXT +5 -0
  8. data/README.md +89 -0
  9. data/lib/logstash/outputs/logservice.rb +143 -0
  10. data/lib/logstash/vendor/jar-dependencies/runtime-jars/aliyun-log-0.6.0-javadoc.jar +0 -0
  11. data/lib/logstash/vendor/jar-dependencies/runtime-jars/aliyun-log-0.6.0.jar +0 -0
  12. data/lib/logstash/vendor/jar-dependencies/runtime-jars/commons-beanutils-1.8.3.jar +0 -0
  13. data/lib/logstash/vendor/jar-dependencies/runtime-jars/commons-codec-1.4.jar +0 -0
  14. data/lib/logstash/vendor/jar-dependencies/runtime-jars/commons-collections-3.2.1.jar +0 -0
  15. data/lib/logstash/vendor/jar-dependencies/runtime-jars/commons-digester-1.8.jar +0 -0
  16. data/lib/logstash/vendor/jar-dependencies/runtime-jars/commons-lang-2.6.jar +0 -0
  17. data/lib/logstash/vendor/jar-dependencies/runtime-jars/commons-logging-1.1.1.jar +0 -0
  18. data/lib/logstash/vendor/jar-dependencies/runtime-jars/commons-validator-1.4.0.jar +0 -0
  19. data/lib/logstash/vendor/jar-dependencies/runtime-jars/ezmorph-1.0.6.jar +0 -0
  20. data/lib/logstash/vendor/jar-dependencies/runtime-jars/gson-2.2.4.jar +0 -0
  21. data/lib/logstash/vendor/jar-dependencies/runtime-jars/hamcrest-core-1.1.jar +0 -0
  22. data/lib/logstash/vendor/jar-dependencies/runtime-jars/httpclient-4.1.3.jar +0 -0
  23. data/lib/logstash/vendor/jar-dependencies/runtime-jars/httpcore-4.1.4.jar +0 -0
  24. data/lib/logstash/vendor/jar-dependencies/runtime-jars/json-lib-2.4-jdk15.jar +0 -0
  25. data/lib/logstash/vendor/jar-dependencies/runtime-jars/lz4-1.3.0.jar +0 -0
  26. data/lib/logstash/vendor/jar-dependencies/runtime-jars/protobuf-java-2.4.1.jar +0 -0
  27. data/logstash-output-logservice.gemspec +25 -0
  28. data/spec/outputs/logservice_spec.rb +22 -0
  29. metadata +137 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0136766990ee9e06bd4548d8385ac7120cfe1275
4
+ data.tar.gz: e3422c2e1705932e30ba6422f1e7a3feda02bce5
5
+ SHA512:
6
+ metadata.gz: fcf85a80751c260469d0da8239226e4ed143f272be5ff3ac22d5e86473dc65cfaa296fe91c99aac4f56989dd3b84dbef1d2df962a61fe2953f4002bff85cbada
7
+ data.tar.gz: c28980495fdfb804f9e2da7c31447001db8f9b61d4b29017a10b83ac85dd2e7abcb3097a6c816c345c1b49ff893ed97f6ce6049380880b95930a54f236591362
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## 2.0.1
2
+ - Add encoding: utf-8 to spec files. This can help prevent issues during testing.
3
+ ## 2.0.0
4
+ - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully,
5
+ instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895
6
+ - Dependency on logstash-core update to 2.0
7
+
data/CONTRIBUTORS ADDED
@@ -0,0 +1,11 @@
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
+ * Aaron Mildenstein (untergeek)
6
+ * Pier-Hugues Pellerin (ph)
7
+
8
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
9
+ Logstash, and you aren't on the list above and want to be, please let us know
10
+ and we'll make sure you're here. Contributions from folks like you are what make
11
+ open source awesome.
data/DEVELOPER.md ADDED
@@ -0,0 +1,2 @@
1
+ # logstash-output-example
2
+ Example output plugin. This should help bootstrap your effort to write your own output plugin!
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ gem "logstash", :github => "elastic/logstash", :branch => "2.2"
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012–2015 Elasticsearch <http://www.elastic.co>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/NOTICE.TXT ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # Logstash Plugin
2
+
3
+ [![Build
4
+ Status](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-example-unit/badge/icon)](http://build-eu-00.elastic.co/view/LS%20Plugins/view/LS%20Outputs/job/logstash-plugin-output-example-unit/)
5
+
6
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
7
+
8
+ 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.
9
+
10
+ ## Documentation
11
+
12
+ 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/).
13
+
14
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
15
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
16
+
17
+ ## Need Help?
18
+
19
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
20
+
21
+ ## Developing
22
+
23
+ ### 1. Plugin Developement and Testing
24
+
25
+ #### Code
26
+ - To get started, you'll need JRuby with the Bundler gem installed.
27
+
28
+ - 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).
29
+
30
+ - Install dependencies
31
+ ```sh
32
+ bundle install
33
+ ```
34
+
35
+ #### Test
36
+
37
+ - Update your dependencies
38
+
39
+ ```sh
40
+ bundle install
41
+ ```
42
+
43
+ - Run tests
44
+
45
+ ```sh
46
+ bundle exec rspec
47
+ ```
48
+
49
+ ### 2. Running your unpublished Plugin in Logstash
50
+
51
+ #### 2.1 Run in a local Logstash clone
52
+
53
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
54
+ ```ruby
55
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
56
+ ```
57
+ - Install plugin
58
+ ```sh
59
+ bin/plugin install --no-verify
60
+ ```
61
+ - Run Logstash with your plugin
62
+ ```sh
63
+ bin/logstash -e 'filter {awesome {}}'
64
+ ```
65
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
66
+
67
+ #### 2.2 Run in an installed Logstash
68
+
69
+ 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:
70
+
71
+ - Build your plugin gem
72
+ ```sh
73
+ gem build logstash-filter-awesome.gemspec
74
+ ```
75
+ - Install the plugin from the Logstash home
76
+ ```sh
77
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
78
+ ```
79
+ - Start Logstash and proceed to test the plugin
80
+
81
+ ## Contributing
82
+
83
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
84
+
85
+ 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.
86
+
87
+ It is more important to the community that you are able to contribute.
88
+
89
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,143 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "logstash/namespace"
4
+ require "logstash/environment"
5
+ require "stud/buffer"
6
+ require 'socket'
7
+ require "java"
8
+
9
+ import "java.util.ArrayList"
10
+
11
+ root_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
12
+
13
+ LogStash::Environment.load_runtime_jars! File.join(root_dir, "vendor")
14
+
15
+ class LogStash::Outputs::LogService < LogStash::Outputs::Base
16
+ include Stud::Buffer
17
+
18
+ config_name "logservice"
19
+
20
+ # log service config, https://help.aliyun.com/document_detail/sls/api/endpoints.html
21
+ config :endpoint, :validate => :string, :required => true
22
+ config :project, :validate=> :string, :required=> true
23
+ config :logstore, :validate=> :string, :required=> true
24
+ config :topic, :validate=> :string, :requried=> false, :default=> ""
25
+ # if source is null, will set ip default
26
+ config :source, :validete=> :string, :required=> true
27
+
28
+ # access_key_id/access_key_secret created by account of aliyun.com
29
+ config :access_key_id, :validate=> :string, :required=> true
30
+ config :access_key_secret, :validate=> :string, :required=> true
31
+
32
+ # default 1000 logs in a logGroup for batch send
33
+ config :max_buffer_items, :validate=> :number, :required=> false, :default=> 1000
34
+ # default 2*1024*1024 Bytes in a logGroup for batch send
35
+ config :max_buffer_bytes, :validate=> :number, :required=> false, :default=> 2097152
36
+ # for batch send, logGroup will emit in default 3 seconds
37
+ config :max_buffer_seconds, :validate=> :number, :required=> false, :default=> 3
38
+
39
+ # logGroup will retry send to log service when error happened, and will be discard when retry times exceed limit (default 3)
40
+ config :max_send_retry, :validate=> :number, :required=> true, :default=> 3
41
+ # sleep default 100 milliseconds before retry next send
42
+ config :send_retry_interval, :validate=> :number, :required=> false, :default=> 100
43
+
44
+ Log = com.aliyun.openservices.log
45
+ LogException = com.aliyun.openservices.log.exception.LogException
46
+ LogCommon = com.aliyun.openservices.log.common
47
+
48
+ public
49
+ def register
50
+ buffer_initialize(
51
+ :max_items => @max_buffer_items,
52
+ :max_interval => @max_buffer_seconds,
53
+ :logger => @logger
54
+ )
55
+ @logclient = Log.Client::new(@endpoint, @access_key_id, @access_key_secret)
56
+ if @source == ''
57
+ @source = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
58
+ end
59
+ @send_retry_interval_seconds = @send_retry_interval / 1000.0
60
+ @logger.info("init logstash-output-logservice plugin", :endpoint => @endpoint, :project => @project, :logstore => @logstore, :topic => @topic, :source => @source, :max_buffer_bytes => @max_buffer_bytes)
61
+ end # def register
62
+
63
+ public
64
+ def receive(event)
65
+ return unless output?(event)
66
+ begin
67
+ buffer_receive(event)
68
+ rescue => e
69
+ @logger.warn("error encoding event for logstash-output-logservice", :exception => e, :event => event)
70
+ end
71
+ end # def event
72
+
73
+ def send_to_log_service(loggroup)
74
+ @retry = 0
75
+ begin
76
+ @retry += 1
77
+ @logclient.PutLogs(@project, @logstore, @topic, loggroup, @source)
78
+ @logger.info("send logs to logservice success", :logcount => loggroup.size().to_s)
79
+ rescue LogException => e
80
+ @error_code = e.GetErrorCode()
81
+ @error_message = e.GetErrorMessage()
82
+ if @retry < @max_send_retry
83
+ @logger.info("send logs to logservice fail, will retry soon", :exception => e, :error_code => @error_code, :error_message => @error_message, :retry => @retry)
84
+ sleep(@send_retry_interval_seconds)
85
+ retry
86
+ else
87
+ @logger.error("send logs to logservice fail, disarcd logs", :exception => e, :error_code => @error_code, :error_message => @error_message, :retry => @retry)
88
+ end
89
+ rescue => e
90
+ if @retry < @max_send_retry
91
+ @logger.info("send logs to logservice fail, will retry soon", :exception => e, :retry => @retry)
92
+ sleep(@send_retry_interval_seconds)
93
+ retry
94
+ else
95
+ @logger.error("send logs to logservice fail, disarcd logs", :exception => e, :retry => @retry)
96
+ end
97
+ end
98
+ end
99
+
100
+ # called from Stud::Buffer#buffer_flush when there are events to flush
101
+ def flush(events, close=false)
102
+ if events.size < 1
103
+ return
104
+ end
105
+
106
+ @loggroup = ArrayList.new
107
+ @byte_size = 0
108
+ events.each { |x|
109
+ begin
110
+ @event_map = x.to_hash
111
+ if @event_map.size < 1
112
+ next
113
+ end
114
+ @logitem = LogCommon.LogItem.new
115
+ #@timestamp like 2016-02-18T03:23:11.053Z
116
+ @logitem.SetTime(Time.parse(@event_map['@timestamp'].to_s).to_i)
117
+ @event_map.each do | key, value |
118
+ @key_str = key.to_s
119
+ @value_str = value.to_s
120
+ @byte_size += @key_str.length + @value_str.length
121
+ @logitem.PushBack(@key_str, @value_str)
122
+ end
123
+ @loggroup.add(@logitem)
124
+ if @byte_size > @max_buffer_bytes
125
+ send_to_log_service(@loggroup)
126
+ @loggroup = ArrayList.new
127
+ @byte_size = 0
128
+ end
129
+ rescue => e
130
+ @logger.warn("decode log data to LogGroup fail", :exception => e)
131
+ end
132
+ }
133
+ if @byte_size > 0
134
+ send_to_log_service(@loggroup)
135
+ end
136
+ end
137
+
138
+ public
139
+ def close
140
+ buffer_flush(:final => true)
141
+ end # def close
142
+
143
+ end # class LogStash::Outputs::LogService
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-logservice'
3
+ s.version = "0.1.0"
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "put data into logservice."
6
+ s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
7
+ s.authors = ["tangkai"]
8
+ s.email = "kai.tangkai@alibaba-inc.com"
9
+ s.homepage = "https://help.aliyun.com/product/8314976_sls.html"
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", ">= 2.0.0", "< 3.0.0"
22
+ s.add_runtime_dependency "logstash-codec-plain"
23
+ s.add_runtime_dependency "stud"
24
+ s.add_development_dependency "logstash-devutils"
25
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/outputs/example"
4
+ require "logstash/codecs/plain"
5
+ require "logstash/event"
6
+
7
+ describe LogStash::Outputs::LogService do
8
+ let(:sample_event) { LogStash::Event.new }
9
+ let(:output) { LogStash::Outputs::Example.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,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-logservice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tangkai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
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: stud
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: logstash-devutils
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: This gem is a logstash plugin required to be installed on top of the
76
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
77
+ a stand-alone program
78
+ email: kai.tangkai@alibaba-inc.com
79
+ executables: []
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - CHANGELOG.md
84
+ - CONTRIBUTORS
85
+ - DEVELOPER.md
86
+ - Gemfile
87
+ - LICENSE
88
+ - NOTICE.TXT
89
+ - README.md
90
+ - lib/logstash/outputs/logservice.rb
91
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/aliyun-log-0.6.0-javadoc.jar
92
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/aliyun-log-0.6.0.jar
93
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/commons-beanutils-1.8.3.jar
94
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/commons-codec-1.4.jar
95
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/commons-collections-3.2.1.jar
96
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/commons-digester-1.8.jar
97
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/commons-lang-2.6.jar
98
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/commons-logging-1.1.1.jar
99
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/commons-validator-1.4.0.jar
100
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/ezmorph-1.0.6.jar
101
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/gson-2.2.4.jar
102
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/hamcrest-core-1.1.jar
103
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/httpclient-4.1.3.jar
104
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/httpcore-4.1.4.jar
105
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/json-lib-2.4-jdk15.jar
106
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/lz4-1.3.0.jar
107
+ - lib/logstash/vendor/jar-dependencies/runtime-jars/protobuf-java-2.4.1.jar
108
+ - logstash-output-logservice.gemspec
109
+ - spec/outputs/logservice_spec.rb
110
+ homepage: https://help.aliyun.com/product/8314976_sls.html
111
+ licenses:
112
+ - Apache License (2.0)
113
+ metadata:
114
+ logstash_plugin: 'true'
115
+ logstash_group: output
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.5.1
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: put data into logservice.
136
+ test_files:
137
+ - spec/outputs/logservice_spec.rb