logstash-output-dynatrace 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
+ SHA256:
3
+ metadata.gz: 9fa581d24c7d6dea1eed2199562913047b8712dc6f1c0c1259c7621880605552
4
+ data.tar.gz: 6ade6b59b77d436cbc9a537ce3fd87ca39345c243bd61bf927514c12d50f3246
5
+ SHA512:
6
+ metadata.gz: 3b03743e665c6af4ae1bf6be5031884aa71cc5dc1d27744d7229ce8bf5ccedd6e56097816bf73548492196a2bf484af9bbd5be41bcaca982c915a634a60af161
7
+ data.tar.gz: f7621c4ca998dca1166f73927ac58dc585c71036dd70af2d59ae8640c7aa4661eaf9ba64a4632127449d3d4e494c35321f25f5fdab110d6bbcbb9ac0395fcc33
data/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Dynatrace LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ source 'https://rubygems.org'
18
+
19
+ gemspec
20
+
21
+ logstash_path = ENV['LOGSTASH_PATH'] || '../../logstash'
22
+ use_logstash_source = ENV['LOGSTASH_SOURCE'] && ENV['LOGSTASH_SOURCE'].to_s == '1'
23
+
24
+ if Dir.exist?(logstash_path) && use_logstash_source
25
+ gem 'logstash-core', path: "#{logstash_path}/logstash-core"
26
+ gem 'logstash-core-plugin-api', path: "#{logstash_path}/logstash-core-plugin-api"
27
+ end
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Logstash Plugin
2
+
3
+ [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-output-example.svg)](https://travis-ci.com/logstash-plugins/logstash-output-example)
4
+
5
+ > This project is developed and maintained by Dynatrace R&D.
6
+
7
+ A [Logstash](https://github.com/elastic/logstash) output plugin for sending logs to the Dynatrace [Generic log ingest API v2](https://www.dynatrace.com/support/help/how-to-use-dynatrace/log-monitoring/log-monitoring-v2/post-log-ingest/).
8
+
9
+ ## Documentation
10
+
11
+ Logstash provides plugin documentation in a [central location](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-dynatrace.html).
12
+
13
+ ## Developing
14
+
15
+ ### 1. Plugin Developement and Testing
16
+
17
+ #### Code
18
+
19
+ - To get started, you'll need JRuby with the Bundler gem installed.
20
+
21
+ - Clone the plugin from github
22
+
23
+ - Install dependencies
24
+
25
+ ```sh
26
+ bundle install
27
+ ```
28
+
29
+ #### Test
30
+
31
+ - Update your dependencies
32
+
33
+ ```sh
34
+ bundle install
35
+ ```
36
+
37
+ - Run tests
38
+
39
+ ```sh
40
+ bundle exec rspec
41
+ ```
42
+
43
+ ### 2. Running your unpublished Plugin in Logstash
44
+
45
+ #### 2.1 Run in a local Logstash clone
46
+
47
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
48
+
49
+ ```ruby
50
+ gem "logstash-output-dynatrace", :path => "/your/local/logstash-output-dynatrace"
51
+ ```
52
+
53
+ - Install plugin
54
+
55
+ ```sh
56
+ # Logstash 2.3 and higher
57
+ bin/logstash-plugin install --no-verify
58
+
59
+ # Prior to Logstash 2.3
60
+ bin/plugin install --no-verify
61
+ ```
62
+
63
+ - Run Logstash with your plugin
64
+
65
+ ```sh
66
+ bin/logstash -e \
67
+ 'input { generator { count => 100 } } output { dynatrace { api_key => "your_api_key_here" ingest_endpoint_url => "https://{your-environment-id}.live.dynatrace.com/api/v2/logs/ingest" } }'
68
+ ```
69
+
70
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
71
+
72
+ #### 2.2 Run in an installed Logstash
73
+
74
+ 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:
75
+
76
+ - Build your plugin gem
77
+
78
+ ```sh
79
+ gem build logstash-output-dynatrace.gemspec
80
+
81
+ ```
82
+
83
+ - Install the plugin from the Logstash home
84
+
85
+ ```sh
86
+ # Logstash 2.3 and higher
87
+ bin/logstash-plugin install --no-verify
88
+
89
+ # Prior to Logstash 2.3
90
+ bin/plugin install --no-verify
91
+ ```
92
+
93
+ - Start Logstash and proceed to test the plugin
94
+
95
+ ## Contributing
96
+
97
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
98
+
99
+ 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.
100
+
101
+ It is more important to the community that you are able to contribute.
102
+
103
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Dynatrace LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'logstash/namespace'
18
+ require 'logstash/outputs/base'
19
+ require 'logstash/json'
20
+
21
+ module LogStash
22
+ module Outputs
23
+ # An output which sends logs to the Dynatrace log ingest v2 endpoint formatted as JSON
24
+ class Dynatrace < LogStash::Outputs::Base
25
+ @plugin_version = ::File.read(::File.expand_path('../../../VERSION', __dir__)).strip
26
+
27
+ config_name 'dynatrace'
28
+
29
+ concurrency :single
30
+
31
+ # The full URL of the Dynatrace log ingestion endpoint:
32
+ # - on SaaS: https://{your-environment-id}.live.dynatrace.com/api/v2/logs/ingest
33
+ # - on Managed: https://{your-domain}/e/{your-environment-id}/api/v2/logs/ingest
34
+ config :ingest_endpoint_url, validate: :uri, required: true
35
+
36
+ # The API token to use to authenticate requests to the log ingestion endpoint. Must have `logs.ingest` (Ingest Logs) scope.
37
+ config :api_key, validate: :string, required: true
38
+
39
+ # Disable SSL validation by setting :verify_mode OpenSSL::SSL::VERIFY_NONE
40
+ config :ssl_verify_none, validate: :boolean, default: false
41
+
42
+ default :codec, 'json'
43
+
44
+ attr_accessor :uri
45
+
46
+ def register
47
+ require 'net/https'
48
+ require 'uri'
49
+ @uri = URI.parse(@ingest_endpoint_url.uri.to_s)
50
+ @client = Net::HTTP.new(@uri.host, @uri.port)
51
+
52
+ if uri.scheme == 'https'
53
+ @client.use_ssl = true
54
+ @client.verify_mode = OpenSSL::SSL::VERIFY_NONE if @ssl_verify_none
55
+ end
56
+ @logger.info('Client', client: @client.inspect)
57
+ end
58
+
59
+ # This is split into a separate method mostly to help testing
60
+ def log_failure(message, opts)
61
+ @logger.error(message, opts)
62
+ end
63
+
64
+ def headers
65
+ {
66
+ 'User-Agent' => "logstash-output-dynatrace v#{@plugin_version}",
67
+ 'Content-Type' => 'application/json; charset=utf-8',
68
+ 'Authorization' => "Api-Token #{@api_key}"
69
+ }
70
+ end
71
+
72
+ # Takes an array of events
73
+ def multi_receive(events)
74
+ return if events.length.zero?
75
+
76
+ request = Net::HTTP::Post.new(uri, headers)
77
+ request.body = "#{LogStash::Json.dump(events.map(&:to_hash)).chomp}\n"
78
+ response = @client.request(request)
79
+ return if response.is_a? Net::HTTPSuccess
80
+
81
+ log_failure('Bad Response', request: request.inspect, response: response.inspect)
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Dynatrace LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ version = File.read(File.expand_path('VERSION', __dir__)).strip
18
+
19
+ Gem::Specification.new do |s|
20
+ s.name = 'logstash-output-dynatrace'
21
+ s.version = version
22
+ s.summary = 'A logstash output plugin for sending logs to the Dynatrace Generic log ingest API v2'
23
+ s.description = <<-EOF
24
+ This gem is a Logstash plugin required to be installed on top of the Logstash
25
+ core pipeline using `$LS_HOME/bin/logstash-plugin install logstash-output-dynatrace`.
26
+ This gem is not a stand-alone program.
27
+ EOF
28
+ s.authors = ['Dynatrace Open Source Engineering']
29
+ s.email = ['opensource@dynatrace.com']
30
+ s.homepage = 'https://github.com/dynatrace-oss/logstash-output-dynatrace'
31
+ s.licenses = ['Apache-2.0']
32
+ s.require_paths = ['lib']
33
+
34
+ # Files
35
+ s.files = Dir['lib/**/*', 'spec/**/*', 'vendor/**/*', '*.gemspec', '*.md', 'CONTRIBUTORS', 'Gemfile', 'LICENSE',
36
+ 'NOTICE.TXT', 'VERSION']
37
+ # Tests
38
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
39
+
40
+ # Special flag to let logstash know this is actually a logstash plugin
41
+ s.metadata = { 'logstash_plugin' => 'true', 'logstash_group' => 'output' }
42
+
43
+ # Gem dependencies
44
+ s.add_runtime_dependency 'logstash-codec-json'
45
+ s.add_runtime_dependency 'logstash-core-plugin-api', '>= 2.0.0', '< 3'
46
+
47
+ s.add_development_dependency 'insist'
48
+ s.add_development_dependency 'logstash-devutils'
49
+ s.add_development_dependency 'logstash-input-generator'
50
+ s.add_development_dependency 'sinatra'
51
+ s.add_development_dependency 'webrick'
52
+
53
+ s.add_development_dependency 'rubocop', '1.9.1'
54
+ s.add_development_dependency 'rubocop-rake', '0.5.1'
55
+ end
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Dynatrace LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative '../spec_helper'
18
+ require 'logstash/codecs/plain'
19
+ require 'logstash/event'
20
+ require 'sinatra'
21
+ require 'insist'
22
+
23
+ PORT = rand(65_535 - 1024) + 1025
24
+
25
+ # NOTE: that Sinatra startup and shutdown messages are directly logged to stderr so
26
+ # it is not really possible to disable them without reopening stderr which is not advisable.
27
+ #
28
+ # == Sinatra (v1.4.6) has taken the stage on 51572 for development with backup from WEBrick
29
+ # == Sinatra has ended his set (crowd applauds)
30
+ #
31
+ class TestApp < Sinatra::Base
32
+ # disable WEBrick logging
33
+ def self.server_settings
34
+ { AccessLog: [], Logger: WEBrick::BasicLog.new(nil, WEBrick::BasicLog::FATAL) }
35
+ end
36
+
37
+ class << self
38
+ attr_accessor :last_request
39
+
40
+ def clear
41
+ self.last_request = nil
42
+ end
43
+ end
44
+
45
+ post '/good' do
46
+ self.class.last_request = request
47
+ [204, '']
48
+ end
49
+
50
+ post '/bad' do
51
+ self.class.last_request = request
52
+ [400, 'Bad']
53
+ end
54
+ end
55
+
56
+ RSpec.configure do |config|
57
+ # http://stackoverflow.com/questions/6557079/start-and-call-ruby-http-server-in-the-same-script
58
+ def sinatra_run_wait(app, opts)
59
+ queue = Queue.new
60
+
61
+ t = java.lang.Thread.new(
62
+ proc do
63
+ begin
64
+ app.run!(opts) do |_server|
65
+ queue.push('started')
66
+ end
67
+ rescue StandardError => e
68
+ puts "Error in webserver thread #{e}"
69
+ # ignore
70
+ end
71
+ end
72
+ )
73
+ t.daemon = true
74
+ t.start
75
+ queue.pop # blocks until the run! callback runs
76
+ end
77
+
78
+ config.before(:suite) do
79
+ sinatra_run_wait(TestApp, port: PORT, server: 'webrick')
80
+ puts "Test webserver on port #{PORT}"
81
+ end
82
+ end
83
+
84
+ describe LogStash::Outputs::Dynatrace do
85
+ let(:port) { PORT }
86
+ let(:event) do
87
+ LogStash::Event.new({ 'message' => 'hi' })
88
+ end
89
+ let(:url) { "http://localhost:#{port}/good" }
90
+ let(:key) { 'api.key' }
91
+ let(:subject) { LogStash::Outputs::Dynatrace.new({ 'api_key' => key, 'ingest_endpoint_url' => url }) }
92
+
93
+ before do
94
+ subject.register
95
+ allow(subject).to receive(:log_failure).with(any_args)
96
+ end
97
+
98
+ context 'sending no events' do
99
+ it 'does not crash on empty events' do
100
+ subject.multi_receive([])
101
+ end
102
+ end
103
+
104
+ context 'with passing requests' do
105
+ before do
106
+ TestApp.clear
107
+ subject.multi_receive([event])
108
+ end
109
+
110
+ let(:last_request) { TestApp.last_request }
111
+ let(:body) { last_request.body.read }
112
+ let(:content_type) { last_request.env['CONTENT_TYPE'] }
113
+ let(:authorization) { last_request.env['HTTP_AUTHORIZATION'] }
114
+
115
+ let(:expected_body) { "#{LogStash::Json.dump([event])}\n" }
116
+ let(:expected_content_type) { 'application/json; charset=utf-8' }
117
+ let(:expected_authorization) { "Api-Token #{key}" }
118
+
119
+ it 'should not log a failure' do
120
+ expect(subject).not_to have_received(:log_failure).with(any_args)
121
+ end
122
+
123
+ it 'should receive the request' do
124
+ expect(last_request).to be_truthy
125
+ end
126
+
127
+ it 'should receive the event as a hash' do
128
+ expect(body).to eql(expected_body)
129
+ end
130
+
131
+ it 'should have the correct content type' do
132
+ expect(content_type).to eql(expected_content_type)
133
+ end
134
+
135
+ it 'should have the correct authorization' do
136
+ expect(authorization).to eql(expected_authorization)
137
+ end
138
+ end
139
+
140
+ context 'with failing requests' do
141
+ let(:url) { "http://localhost:#{port}/bad" }
142
+
143
+ before do
144
+ subject.multi_receive([event])
145
+ end
146
+
147
+ it 'should log a failure' do
148
+ expect(subject).to have_received(:log_failure).with(any_args)
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logstash/devutils/rspec/spec_helper'
4
+ require 'logstash/outputs/dynatrace'
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-output-dynatrace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dynatrace Open Source Engineering
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-codec-json
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: logstash-core-plugin-api
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '3'
47
+ - !ruby/object:Gem::Dependency
48
+ name: insist
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
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
+ - !ruby/object:Gem::Dependency
76
+ name: logstash-input-generator
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: sinatra
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: webrick
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '='
122
+ - !ruby/object:Gem::Version
123
+ version: 1.9.1
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '='
129
+ - !ruby/object:Gem::Version
130
+ version: 1.9.1
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubocop-rake
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '='
136
+ - !ruby/object:Gem::Version
137
+ version: 0.5.1
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '='
143
+ - !ruby/object:Gem::Version
144
+ version: 0.5.1
145
+ description: |2
146
+ This gem is a Logstash plugin required to be installed on top of the Logstash
147
+ core pipeline using `$LS_HOME/bin/logstash-plugin install logstash-output-dynatrace`.
148
+ This gem is not a stand-alone program.
149
+ email:
150
+ - opensource@dynatrace.com
151
+ executables: []
152
+ extensions: []
153
+ extra_rdoc_files: []
154
+ files:
155
+ - Gemfile
156
+ - LICENSE
157
+ - README.md
158
+ - VERSION
159
+ - lib/logstash/outputs/dynatrace.rb
160
+ - logstash-output-dynatrace.gemspec
161
+ - spec/outputs/dynatrace_spec.rb
162
+ - spec/spec_helper.rb
163
+ homepage: https://github.com/dynatrace-oss/logstash-output-dynatrace
164
+ licenses:
165
+ - Apache-2.0
166
+ metadata:
167
+ logstash_plugin: 'true'
168
+ logstash_group: output
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubygems_version: 3.1.6
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: A logstash output plugin for sending logs to the Dynatrace Generic log ingest
188
+ API v2
189
+ test_files:
190
+ - spec/outputs/dynatrace_spec.rb
191
+ - spec/spec_helper.rb