logstash-output-thetapoint 0.1.0

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: ee92e8be35167e5f6733532e4d9c2d38e5d6f721
4
+ data.tar.gz: 705459cd21e91278e020a1796beb81bfe56c21c6
5
+ SHA512:
6
+ metadata.gz: 50ae2fb42a5bafae6226992e29545aa125577aa3261274571343f570774aceb7aed2b14196f83b279b2cb001a0fadabc1283803e5a3b1e479c8af402e3190699
7
+ data.tar.gz: 615dcdcb35564b0ccac04b1c8fa001f079fb542eda7ac921c4292416fc7c297db5a34becbfaf8b0caf3961053bd0ad696898b036f9e7ef8505cac37f0cd7eaef
data/CHANGELOG.md ADDED
File without changes
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 => "1.5"
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ logstash-output-thetapoint (0.1.0)
5
+ logstash-codec-plain
6
+ logstash-core (>= 1.4.0, < 2.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ cabin (0.7.1)
12
+ clamp (0.6.5)
13
+ coderay (1.1.0)
14
+ diff-lcs (1.2.5)
15
+ ffi (1.9.8-java)
16
+ filesize (0.0.4)
17
+ gem_publisher (1.5.0)
18
+ i18n (0.6.9)
19
+ insist (1.0.0)
20
+ jrjackson (0.2.8)
21
+ logstash-codec-plain (0.1.6)
22
+ logstash-core (>= 1.4.0, < 2.0.0)
23
+ logstash-core (1.5.0-java)
24
+ cabin (~> 0.7.0)
25
+ clamp (~> 0.6.5)
26
+ filesize (= 0.0.4)
27
+ i18n (= 0.6.9)
28
+ jrjackson (~> 0.2.8)
29
+ minitar (~> 0.5.4)
30
+ pry (~> 0.10.1)
31
+ stud (~> 0.0.19)
32
+ treetop (< 1.5.0)
33
+ logstash-devutils (0.0.14-java)
34
+ gem_publisher
35
+ insist (= 1.0.0)
36
+ minitar
37
+ rake
38
+ rspec (~> 3.1.0)
39
+ method_source (0.8.2)
40
+ minitar (0.5.4)
41
+ polyglot (0.3.5)
42
+ pry (0.10.1-java)
43
+ coderay (~> 1.1.0)
44
+ method_source (~> 0.8.1)
45
+ slop (~> 3.4)
46
+ spoon (~> 0.0)
47
+ rake (10.4.2)
48
+ rspec (3.1.0)
49
+ rspec-core (~> 3.1.0)
50
+ rspec-expectations (~> 3.1.0)
51
+ rspec-mocks (~> 3.1.0)
52
+ rspec-core (3.1.7)
53
+ rspec-support (~> 3.1.0)
54
+ rspec-expectations (3.1.2)
55
+ diff-lcs (>= 1.2.0, < 2.0)
56
+ rspec-support (~> 3.1.0)
57
+ rspec-mocks (3.1.3)
58
+ rspec-support (~> 3.1.0)
59
+ rspec-support (3.1.2)
60
+ slop (3.6.0)
61
+ spoon (0.0.4)
62
+ ffi
63
+ stud (0.0.19)
64
+ treetop (1.4.15)
65
+ polyglot
66
+ polyglot (>= 0.3.1)
67
+
68
+ PLATFORMS
69
+ java
70
+
71
+ DEPENDENCIES
72
+ logstash-devutils
73
+ logstash-output-thetapoint!
74
+
75
+ BUNDLED WITH
76
+ 1.10.3
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/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elasticsearch/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.elasticsearch.org/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/elasticsearch/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 and Testing
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
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {awesome {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ 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:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ 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.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rake"
@@ -0,0 +1,154 @@
1
+ # encoding: utf-8
2
+ require "logstash/outputs/base"
3
+ require "logstash/namespace"
4
+ require "uri"
5
+ require "net/http"
6
+ require "net/https"
7
+ require "stud/buffer"
8
+ require "zlib"
9
+ require 'time'
10
+
11
+ #
12
+ # This is most useful so you can use logstash to parse and structure
13
+ # your logs and ship structured, json events to ThetaPoint.
14
+ #
15
+ # To use this, you'll need to use a ThetaPoint input with type 'http'
16
+ # and 'json logging' enabled.
17
+ class LogStash::Outputs::ThetaPoint < LogStash::Outputs::Base
18
+
19
+ include Stud::Buffer
20
+
21
+ config_name "thetapoint"
22
+ milestone 3
23
+
24
+ # The hostname to send logs to.
25
+ config :host, :validate => :string, :default => "api.theta-point.com"
26
+ config :port, :validate => :number, :default => 443
27
+ config :path, :validate => :string, :default => "bulk"
28
+
29
+ # The thetapoint http input key to send to.
30
+ # https://thetapoint03.theta-point.com/inputs/abcdef12-3456-7890-abcd-ef0123456789
31
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
32
+ # \----------> key <-------------/
33
+ #
34
+ # You can use %{foo} field lookups here if you need to pull the api key from
35
+ # the event. This is mainly aimed at multitenant hosting providers who want
36
+ # to offer shipping a customer's logs to that customer's loggly account.
37
+ config :key, :validate => :string, :required => true
38
+
39
+ # Should the log action be sent over https instead of plain http
40
+ config :proto, :validate => :string, :default => "https"
41
+
42
+ # Proxy Host
43
+ config :proxy_host, :validate => :string, :default => nil
44
+
45
+ # Proxy Port
46
+ config :proxy_port, :validate => :number, :default => nil
47
+
48
+ # Proxy Username
49
+ config :proxy_user, :validate => :string, :default => nil
50
+
51
+ # Proxy Password
52
+ config :proxy_password, :validate => :password, :default => nil
53
+
54
+ # If true, we send an HTTP POST request every "batch_events" events or
55
+ # "batch_timeout" seconds (whichever comes first).
56
+ config :batch, :validate => :boolean, :default => false
57
+ config :batch_events, :validate => :number, :default => 100
58
+ config :batch_timeout, :validate => :number, :default => 5
59
+
60
+ config :compress, :validate => :boolean, :default => false
61
+
62
+ public
63
+ def register
64
+ if @batch
65
+ buffer_initialize(
66
+ :max_items => @batch_events,
67
+ :max_interval => @batch_timeout,
68
+ :logger => @logger
69
+ )
70
+ end
71
+
72
+ end
73
+
74
+ public
75
+ def receive(event)
76
+ return unless output?(event)
77
+
78
+ if event == LogStash::SHUTDOWN
79
+ finished
80
+ return
81
+ end
82
+
83
+ if @batch
84
+ # Stud::Buffer
85
+ buffer_receive(event, event.sprintf(@key))
86
+ return
87
+ end
88
+
89
+ sendEvent(event.to_json, event.sprintf(@key))
90
+
91
+ end # def receive
92
+
93
+ def sendEvent(data, key)
94
+ # Comress data
95
+ if @compress
96
+ @logger.info("Deflate start", :now => Time.now.rfc2822, :length => data.length)
97
+ send_data = Zlib::Deflate.deflate(data, Zlib::BEST_COMPRESSION)
98
+ @logger.info("Deflate end", :now => Time.now.rfc2822, :length => send_data.length, :ratio => send_data.length/data.length)
99
+ @path = "zbulk"
100
+ else
101
+ send_data = data
102
+ end
103
+ # Send the data
104
+ @logger.info("ThetaPoint Connect: ",
105
+ :host => @host,
106
+ :port => @port,
107
+ :proxy_host => @proxy_host,
108
+ :proxy_port => @proxy_port,
109
+ :proxy_user => @proxy_user,
110
+ :proxy_password => @proxy_password.value)
111
+ @http = Net::HTTP.new(@host, @port, @proxy_host, @proxy_port, @proxy_user, @proxy_password.value)
112
+ @logger.info("http", :http => @http)
113
+ if @proto == 'https'
114
+ @http.use_ssl = true
115
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
116
+ end
117
+
118
+ begin
119
+ @logger.info("Submit start", :now => Time.now.rfc2822)
120
+ uri = "/#{@path}/#{@key}"
121
+ response = @http.request_post(uri, send_data)
122
+ @logger.info("Submit end", :now => Time.now.rfc2822)
123
+ @logger.info("response", :response => response)
124
+ if response.is_a?(Net::HTTPSuccess)
125
+ @logger.info("Event send to ThetaPoint OK!")
126
+ else
127
+ @logger.warn("HTTP error", :error => response.error!)
128
+ end
129
+ rescue Exception => e
130
+ @logger.error("ThetaPoint Unhandled exception", :pd_error => e.backtrace)
131
+ end
132
+
133
+ end # def sendEvent
134
+
135
+ # called from Stud::Buffer#buffer_flush when there are events to flush
136
+ def flush(events, key, teardown=false)
137
+ sendEvent(events.to_json, key)
138
+ end # def flush
139
+
140
+ # called from Stud::Buffer#buffer_flush when an error occurs
141
+ def on_flush_error(e)
142
+ @logger.warn("Failed to send backlog of events to ThetaPoint",
143
+ :exception => e,
144
+ :backtrace => e.backtrace
145
+ )
146
+ end # def on_flush_error
147
+
148
+ def teardown
149
+ if @batch
150
+ buffer_flush(:final => true)
151
+ end
152
+ end # def teardown
153
+
154
+ end # class LogStash::Outputs::ThetaPoint
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-output-thetapoint'
3
+ s.version = "0.1.0"
4
+ s.licenses = ["Apache License (2.0)"]
5
+ s.summary = "This thetapoint output does nothing."
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 = ["ThetaPoint"]
8
+ s.email = "info@theta-point.com"
9
+ s.homepage = "http://www.theta-point.com"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = `git ls-files`.split($\)
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", ">= 1.4.0", "< 2.0.0"
22
+ s.add_runtime_dependency "logstash-codec-plain"
23
+ s.add_development_dependency "logstash-devutils"
24
+ end
@@ -0,0 +1,32 @@
1
+ require "logstash/devutils/rspec/spec_helper"
2
+ require "logstash/outputs/thetapoint"
3
+ require "logstash/codecs/plain"
4
+ require "logstash/event"
5
+
6
+ describe LogStash::Outputs::ThetaPoint do
7
+ let(:config) { { 'key' => 'lksjdflskdjflskdjflskdj' } }
8
+ let(:event) do
9
+ LogStash::Outputs::ThetaPoint.new(
10
+ 'message' => 'example message',
11
+ 'type' => 'event',
12
+ '@timestamp' => Logstash::Timestamp.now)
13
+ end
14
+
15
+ context 'when initializing' do
16
+ subject { LogStash::Outputs::ThetaPoint.new(config) }
17
+
18
+ it 'should register' do
19
+ expect { subject.register }.to_not raise_error
20
+ end
21
+
22
+ it 'should have default config values' do
23
+ insist { subject.host } == 'api.theta-point.com'
24
+ insist { subject.port } == 443
25
+ insist { subject.proto } == 'https'
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+ # vim: ts=2:sw=2:
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-thetapoint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ThetaPoint
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.0
28
+ - - <
29
+ - !ruby/object:Gem::Version
30
+ version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-codec-plain
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
46
+ type: :runtime
47
+ - !ruby/object:Gem::Dependency
48
+ name: logstash-devutils
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ prerelease: false
60
+ type: :development
61
+ 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
62
+ email: info@theta-point.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - CHANGELOG.md
68
+ - CONTRIBUTORS
69
+ - DEVELOPER.md
70
+ - Gemfile
71
+ - Gemfile.lock
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - lib/logstash/outputs/thetapoint.rb
76
+ - logstash-output-thetapoint.gemspec
77
+ - spec/outputs/thetapoint_spec.rb
78
+ homepage: http://www.theta-point.com
79
+ licenses:
80
+ - Apache License (2.0)
81
+ metadata:
82
+ logstash_plugin: 'true'
83
+ logstash_group: output
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.5
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: This thetapoint output does nothing.
104
+ test_files:
105
+ - spec/outputs/thetapoint_spec.rb