logstash-input-azure_event_hubs 1.0.0

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: 902edadba15d69ce6f3dddccb45d032da18822480c3877eb6c2aa0774838c02e
4
+ data.tar.gz: 9c80e3da69f7f8872edd278bedb3102f212ab3a4cbb6d643674e6543eda09ce0
5
+ SHA512:
6
+ metadata.gz: f49d124219f4618b051afe5d6ff705a6bad7b611474c20640d033014937a0ac95b7b97ef744f3e57d6e4d924006c0575b8d9b428efb9e5128b3ceb0c5838e70b
7
+ data.tar.gz: d0a8bd34fbbb9fb7f4c45216fdeeb22ce6978d72ed1b3bfdeb77ad1fe07f5188846ac1e50b60ac33296d908bb39ce18ceb86bec8b7b6c4e645764d71ada0e85f
@@ -0,0 +1,4 @@
1
+ ## 1.0.0
2
+ - Initial release of `logstash-input-azure_event_hubs` supersedes `logstash-input-azureeventhub`
3
+ - Re-implementation that uses Event Processor Host API and new configuration options.
4
+
@@ -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
+ # jakelandis
6
+ * brahmnes
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/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ logstash_path = "../../logstash"
6
+
7
+ if Dir.exist?(logstash_path) && ENV["LOGSTASH_SOURCE"] == "1"
8
+ gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
9
+ gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
10
+ end
11
+
12
+ if RUBY_VERSION == "1.9.3"
13
+ gem 'rake', '12.2.1'
14
+ 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.
@@ -0,0 +1,88 @@
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 Development 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
+ ./gradlew vendor
30
+ bundle install
31
+ ```
32
+
33
+ #### Test
34
+
35
+ - Update your dependencies
36
+
37
+ ```sh
38
+ bundle install
39
+ ```
40
+
41
+ - Run tests
42
+
43
+ ```sh
44
+ gem install rspec
45
+ bundle exec rspec --pattern spec/**/*_spec.rb
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ bin/logstash-plugin install --no-verify
59
+ ```
60
+ - Run Logstash with your plugin
61
+ ```sh
62
+ bin/logstash -e 'filter {awesome {}}'
63
+ ```
64
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
65
+
66
+ #### 2.2 Run in an installed Logstash
67
+
68
+ 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:
69
+
70
+ - Build your plugin gem
71
+ ```sh
72
+ gem build logstash-filter-awesome.gemspec
73
+ ```
74
+ - Install the plugin from the Logstash home
75
+ ```sh
76
+ bin/logstash-plugin install /your/local/plugin/logstash-filter-awesome.gem
77
+ ```
78
+ - Start Logstash and proceed to test the plugin
79
+
80
+ ## Contributing
81
+
82
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
83
+
84
+ 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.
85
+
86
+ It is more important to the community that you are able to contribute.
87
+
88
+ 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
+ 1.0.0
@@ -0,0 +1,10 @@
1
+ # AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.
2
+
3
+ require 'jar_dependencies'
4
+ require_jar('com.google.code.gson', 'gson', '2.8.3')
5
+ require_jar('org.apache.qpid', 'proton-j', '0.27.1')
6
+ require_jar('org.apache.logging.log4j', 'log4j-slf4j-impl', '2.9.1')
7
+ require_jar('com.microsoft.azure', 'azure-eventhubs', '1.0.1')
8
+ require_jar('com.microsoft.azure', 'azure-eventhubs-eph', '1.0.0')
9
+ require_jar('com.microsoft.azure', 'azure-storage', '7.0.0')
10
+ require_jar('org.apache.logging.log4j', 'log4j-api', '2.9.1')
@@ -0,0 +1,479 @@
1
+ # encoding: utf-8
2
+ require "logstash-input-azure_event_hubs"
3
+ require "logstash/inputs/base"
4
+ require "logstash/namespace"
5
+ require "stud/interval"
6
+ require "logstash/inputs/processor_factory"
7
+ require "logstash/inputs/error_notification_handler"
8
+ require "logstash/inputs/named_thread_factory"
9
+ require "logstash/inputs/look_back_position_provider"
10
+
11
+
12
+ java_import com.microsoft.azure.eventprocessorhost.EventProcessorHost
13
+ java_import com.microsoft.azure.eventprocessorhost.EventProcessorOptions
14
+ java_import com.microsoft.azure.eventprocessorhost.InMemoryCheckpointManager
15
+ java_import com.microsoft.azure.eventprocessorhost.InMemoryLeaseManager
16
+ java_import com.microsoft.azure.eventprocessorhost.HostContext
17
+ java_import com.microsoft.azure.eventhubs.ConnectionStringBuilder
18
+ java_import java.util.concurrent.Executors
19
+ java_import java.util.concurrent.TimeUnit
20
+
21
+
22
+ class LogStash::Inputs::AzureEventHubs < LogStash::Inputs::Base
23
+ config_name "azure_event_hubs"
24
+
25
+ # This plugin supports two styles of configuration
26
+ # basic - You supply a list of Event Hub connection strings complete with the 'EntityPath' that defines the Event Hub name. All other configuration is shared.
27
+ # advanced - You supply a list of Event Hub names, and under each name provide that Event Hub's configuration. Most all of the configuration options are identical as the basic model, except they are configured per Event Hub.
28
+ # Defaults to basic
29
+ # Example:
30
+ # azure_event_hubs {
31
+ # config_mode => "basic"
32
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1" , "Endpoint=sb://example2...;EntityPath=event_hub_name2" ]
33
+ # }
34
+ config :config_mode, :validate => ['basic', 'advanced'], :default => 'basic'
35
+
36
+ # advanced MODE ONLY - The event hubs to read from. This is a array of hashes, where the each entry of the array is a hash of the event_hub_name => {configuration}.
37
+ # Note - most basic configuration options are supported under the Event Hub names, and examples proved where applicable
38
+ # Note - while in advanced mode, if any basic options are defined at the top level they will be used if not already defined under the Event Hub name. e.g. you may define shared configuration at the top level
39
+ # Note - the required event_hub_connection is named 'event_hub_connection' (singular) which differs from the basic configuration option 'event_hub_connections' (plural)
40
+ # Note - the 'event_hub_connection' may contain the 'EntityPath', but only if it matches the Event Hub name.
41
+ # Note - the same Event Hub name is allowed under different configurations (and is why the config is array of Hashes)
42
+ # Example:
43
+ # azure_event_hubs {
44
+ # config_mode => "advanced"
45
+ # event_hubs => [
46
+ # { "event_hub_name1" => {
47
+ # event_hub_connection => "Endpoint=sb://example1..."
48
+ # }},
49
+ # { "event_hub_name2" => {
50
+ # event_hub_connection => "Endpoint=sb://example2..."
51
+ # storage_connection => "DefaultEndpointsProtocol=https;AccountName=example...."
52
+ # storage_container => "my_container"
53
+ # }}
54
+ # ]
55
+ # consumer_group => "logstash" # shared across all Event Hubs
56
+ # }
57
+ config :event_hubs, :validate => :array, :required => true # only required for advanced mode
58
+
59
+ # basic MODE ONLY - The Event Hubs to read from. This is a list of Event Hub connection strings that includes the 'EntityPath'.
60
+ # All other configuration options will be shared between Event Hubs.
61
+ # Example:
62
+ # azure_event_hubs {
63
+ # config_mode => "basic"
64
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1" , "Endpoint=sb://example2...;EntityPath=event_hub_name2" ]
65
+ # }
66
+ config :event_hub_connections, :validate => :array, :required => true # only required for basic mode
67
+
68
+ # Used to persists the offsets between restarts and ensure that multiple instances of Logstash process different partitions
69
+ # This is *stongly* encouraged to be set for production environments.
70
+ # When this value is set, restarts will pick up from where it left off. Without this value set the initial_position is *always* used.
71
+ # basic Example:
72
+ # azure_event_hubs {
73
+ # config_mode => "basic"
74
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1"]
75
+ # storage_connection => "DefaultEndpointsProtocol=https;AccountName=example...."
76
+ # }
77
+ # advanced example:
78
+ # azure_event_hubs {
79
+ # config_mode => "advanced"
80
+ # event_hubs => [
81
+ # { "event_hub_name1" => {
82
+ # event_hub_connection => "Endpoint=sb://example1..."
83
+ # storage_connection => "DefaultEndpointsProtocol=https;AccountName=example...."
84
+ # }}
85
+ # ]
86
+ # }
87
+ config :storage_connection, :validate => :password, :required => false
88
+
89
+ # The storage container to persist the offsets.
90
+ # Note - don't allow multiple Event Hubs to write to the same container with the same consumer group, else the offsets will be persisted incorrectly.
91
+ # Note - this will default to the event hub name if not defined
92
+ # basic Example:
93
+ # azure_event_hubs {
94
+ # config_mode => "basic"
95
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1"]
96
+ # storage_connection => "DefaultEndpointsProtocol=https;AccountName=example...."
97
+ # storage_container => "my_container"
98
+ # }
99
+ # advanced example:
100
+ # azure_event_hubs {
101
+ # config_mode => "advanced"
102
+ # event_hubs => [
103
+ # { "event_hub_name1" => {
104
+ # event_hub_connection => "Endpoint=sb://example1..."
105
+ # storage_connection => "DefaultEndpointsProtocol=https;AccountName=example...."
106
+ # storage_container => "my_container"
107
+ # }}
108
+ # ]
109
+ # }
110
+ config :storage_container, :validate => :string, :required => false
111
+
112
+ # Total threads used process events. Requires at minimum 2 threads. This option can not be set per Event Hub.
113
+ # azure_event_hubs {
114
+ # threads => 4
115
+ # }
116
+ config :threads, :validate => :number, :default => 4
117
+
118
+ # Consumer group used to read the Event Hub(s). It is recommended to change from the $Default to a consumer group specifically for Logstash, and ensure that all instances of Logstash use that consumer group.
119
+ # basic Example:
120
+ # azure_event_hubs {
121
+ # config_mode => "basic"
122
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1"]
123
+ # consumer_group => "logstash"
124
+ # }
125
+ # advanced example:
126
+ # azure_event_hubs {
127
+ # config_mode => "advanced"
128
+ # event_hubs => [
129
+ # { "event_hub_name1" => {
130
+ # event_hub_connection => "Endpoint=sb://example1..."
131
+ # consumer_group => "logstash"
132
+ # }}
133
+ # ]
134
+ # }
135
+ config :consumer_group, :validate => :string, :default => '$Default'
136
+
137
+ # The max size of events are processed together. A checkpoint is created after each batch. Increasing this value may help with performance, but requires more memory.
138
+ # Defaults to 50
139
+ # basic Example:
140
+ # azure_event_hubs {
141
+ # config_mode => "basic"
142
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1"]
143
+ # max_batch_size => 125
144
+ # }
145
+ # advanced example:
146
+ # azure_event_hubs {
147
+ # config_mode => "advanced"
148
+ # event_hubs => [
149
+ # { "event_hub_name1" => {
150
+ # event_hub_connection => "Endpoint=sb://example1..."
151
+ # max_batch_size => 125
152
+ # }}
153
+ # ]
154
+ # }
155
+ config :max_batch_size, :validate => :number, :default => 125
156
+
157
+ # The max size of events that are retrieved prior to processing. Increasing this value may help with performance, but requires more memory.
158
+ # Defaults to 300
159
+ # basic Example:
160
+ # azure_event_hubs {
161
+ # config_mode => "basic"
162
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1"]
163
+ # prefetch_count => 300
164
+ # }
165
+ # advanced example:
166
+ # azure_event_hubs {
167
+ # config_mode => "advanced"
168
+ # event_hubs => [
169
+ # { "event_hub_name1" => {
170
+ # event_hub_connection => "Endpoint=sb://example1..."
171
+ # prefetch_count => 300
172
+ # }}
173
+ # ]
174
+ # }
175
+ # NOTE - This option is intentionally not part of the public documentation. This is a very low level configuration that shouldn't need to be changed by anyone other then an Event Hub expert.
176
+ config :prefetch_count, :validate => :number, :default => 300
177
+
178
+ # The max time allowed receive events without a timeout.
179
+ # Value is expressed in seconds, default 60
180
+ # basic Example:
181
+ # azure_event_hubs {
182
+ # config_mode => "basic"
183
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1"]
184
+ # receive_timeout => 60
185
+ # }
186
+ # advanced example:
187
+ # azure_event_hubs {
188
+ # config_mode => "advanced"
189
+ # event_hubs => [
190
+ # { "event_hub_name1" => {
191
+ # event_hub_connection => "Endpoint=sb://example1..."
192
+ # receive_timeout => 300
193
+ # }}
194
+ # ]
195
+ # }
196
+ # NOTE - This option is intentionally not part of the public documentation. This is a very low level configuration that shouldn't need to be changed by anyone other then an Event Hub expert.
197
+ config :receive_timeout, :validate => :number, :default => 60
198
+
199
+ # When first reading from an event hub, start from this position.
200
+ # beginning - reads ALL pre-existing events in the event hub
201
+ # end - reads NO pre-existing events in the event hub
202
+ # look_back - reads end minus N seconds worth of pre-existing events
203
+ # Note - If the storage_connection is set, this configuration is only applicable for the very first time Logstash reads from the event hub.
204
+ # basic Example:
205
+ # azure_event_hubs {
206
+ # config_mode => "basic"
207
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1"]
208
+ # initial_position => "beginning"
209
+ # }
210
+ # advanced example:
211
+ # azure_event_hubs {
212
+ # config_mode => "advanced"
213
+ # event_hubs => [
214
+ # { "event_hub_name1" => {
215
+ # event_hub_connection => "Endpoint=sb://example1..."
216
+ # initial_position => "beginning"
217
+ # }}
218
+ # ]
219
+ # }
220
+ config :initial_position, :validate => ['beginning', 'end', 'look_back'], :default => 'beginning'
221
+
222
+ # The number of seconds to look back for pre-existing events to determine the initial position.
223
+ # Note - If the storage_connection is set, this configuration is only applicable for the very first time Logstash reads from the event hub.
224
+ # Note - this options is only used when initial_position => "look_back"
225
+ # Value is expressed in seconds, default is 1 day
226
+ # basic Example:
227
+ # azure_event_hubs {
228
+ # config_mode => "basic"
229
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1"]
230
+ # initial_position => "look_back"
231
+ # initial_position_look_back => 86400
232
+ # }
233
+ # advanced example:
234
+ # azure_event_hubs {
235
+ # config_mode => "advanced"
236
+ # event_hubs => [
237
+ # { "event_hub_name1" => {
238
+ # event_hub_connection => "Endpoint=sb://example1..."
239
+ # initial_position => "look_back"
240
+ # initial_position_look_back => 86400
241
+ # }}
242
+ # ]
243
+ # }
244
+ config :initial_position_look_back, :validate => :number, :default => 86400
245
+
246
+ # The interval in seconds between writing checkpoint while processing a batch. Default 5 seconds. Checkpoints can slow down processing, but are needed to know where to start after a restart.
247
+ # Note - checkpoints happen after every batch, so this configuration is only applicable while processing a single batch.
248
+ # Value is expressed in seconds, set to zero to disable
249
+ # basic Example:
250
+ # azure_event_hubs {
251
+ # config_mode => "basic"
252
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1"]
253
+ # checkpoint_interval => 5
254
+ # }
255
+ # advanced example:
256
+ # azure_event_hubs {
257
+ # config_mode => "advanced"
258
+ # event_hubs => [
259
+ # { "event_hub_name1" => {
260
+ # event_hub_connection => "Endpoint=sb://example1..."
261
+ # checkpoint_interval => 5
262
+ # }}
263
+ # ]
264
+ # }
265
+ config :checkpoint_interval, :validate => :number, :default => 5
266
+
267
+ # Adds meta data to the event.
268
+ # [@metadata][azure_event_hubs][name] - the name of hte event host
269
+ # [@metadata][azure_event_hubs][consumer_group] - the consumer group that consumed this event
270
+ # [@metadata][azure_event_hubs][processor_host] - the unique identifier that identifies which host processed this event. Note - there can be multiple processor hosts on a single instance of Logstash.
271
+ # [@metadata][azure_event_hubs][partition] - the partition from which event came from
272
+ # [@metadata][azure_event_hubs][offset] - the event hub offset for this event
273
+ # [@metadata][azure_event_hubs][sequence] - the event hub sequence for this event
274
+ # [@metadata][azure_event_hubs][timestamp] - the enqueued time of the event
275
+ # [@metadata][azure_event_hubs][event_size] - the size of the event
276
+ # basic Example:
277
+ # azure_event_hubs {
278
+ # config_mode => "basic"
279
+ # event_hub_connections => ["Endpoint=sb://example1...;EntityPath=event_hub_name1"]
280
+ # decorate_events => true
281
+ # }
282
+ # advanced example:
283
+ # azure_event_hubs {
284
+ # config_mode => "advanced"
285
+ # event_hubs => [
286
+ # { "event_hub_name1" => {
287
+ # event_hub_connection => "Endpoint=sb://example1..."
288
+ # decorate_events => true
289
+ # }}
290
+ # ]
291
+ # }
292
+ config :decorate_events, :validate => :boolean, :default => false
293
+
294
+ attr_reader :count, :pre_count
295
+
296
+ def initialize(params)
297
+
298
+ # explode the all of the parameters to be scoped per event_hub
299
+ @event_hubs_exploded = []
300
+ # global_config will be merged into the each of the exploded configs, prefer any configuration already scoped over the globally scoped config
301
+ global_config = {}
302
+ params.each do |k, v|
303
+ if !k.eql?('id') && !k.eql?('event_hubs') && !k.eql?('threads') && !k.eql?('event_hub_connections') # don't copy these to the per-event-hub configs
304
+ global_config[k] = v
305
+ end
306
+ end
307
+
308
+ if params['config_mode'] && params['config_mode'].eql?('advanced')
309
+ params['event_hub_connections'] = ['dummy'] # trick the :required validation
310
+
311
+ params['event_hubs'].each do |event_hub|
312
+ raise "event_hubs must be a Hash" unless event_hub.is_a?(Hash)
313
+ event_hub.each do |event_hub_name, config|
314
+ config.each do |k, v|
315
+ if 'event_hub_connection'.eql?(k) || 'storage_connection'.eql?(k) # protect from leaking logs
316
+ config[k] = ::LogStash::Util::Password.new(v)
317
+ end
318
+ end
319
+ if config['event_hub_connection'] #add the 's' to pass validation
320
+ config['event_hub_connections'] = config['event_hub_connection']
321
+ config.delete('event_hub_connection')
322
+ end
323
+
324
+ config.merge!({'event_hubs' => [event_hub_name]})
325
+ config.merge!(global_config) {|k, v1, v2| v1}
326
+ @event_hubs_exploded << config
327
+ end
328
+ end
329
+ else # basic config
330
+ params['event_hubs'] = ['dummy'] # trick the :required validation
331
+ if params['event_hub_connections']
332
+ connections = *params['event_hub_connections'] # ensure array
333
+ connections.each.with_index do |_connection, i|
334
+ begin
335
+ connection = self.class.replace_placeholders(_connection) if self.class.respond_to? 'replace_placeholders' # 6.x
336
+ connection = self.class.replace_env_placeholders(_connection) if self.class.respond_to? 'replace_env_placeholders' # 5.x
337
+ event_hub_name = ConnectionStringBuilder.new(connection).getEventHubName
338
+ redacted_connection = connection.gsub(/(SharedAccessKey=)([0-9a-zA-Z=+]*)([;]*)(.*)/, '\\1<redacted>\\3\\4')
339
+ params['event_hub_connections'][i] = redacted_connection # protect from leaking logs
340
+ raise "invalid Event Hub name" unless event_hub_name
341
+ rescue
342
+ raise LogStash::ConfigurationError, "Error parsing event hub string name for connection: '#{redacted_connection}' please ensure that the connection string contains the EntityPath"
343
+ end
344
+ @event_hubs_exploded << {'event_hubs' => [event_hub_name]}.merge({'event_hub_connections' => [::LogStash::Util::Password.new(connection)]}).merge(global_config) {|k, v1, v2| v1}
345
+ end
346
+ end
347
+ end
348
+
349
+ super(params)
350
+
351
+ container_consumer_groups = []
352
+ # explicitly validate all the per event hub configs
353
+ @event_hubs_exploded.each do |event_hub|
354
+ if !self.class.validate(event_hub)
355
+ raise LogStash::ConfigurationError, I18n.t("logstash.runner.configuration.invalid_plugin_settings")
356
+ end
357
+ container_consumer_groups << {event_hub['storage_connection'].value.to_s + (event_hub['storage_container'] ? event_hub['storage_container'] : event_hub['event_hubs'][0]) => event_hub['consumer_group']} if event_hub['storage_connection']
358
+ end
359
+ raise "The configuration will result in overwriting offsets. Please ensure that the each Event Hub's consumer_group is using a unique storage container." if container_consumer_groups.size > container_consumer_groups.uniq.size
360
+ end
361
+
362
+ attr_reader :event_hubs_exploded
363
+
364
+ def register
365
+ # augment the exploded config with the defaults
366
+ @event_hubs_exploded.each do |event_hub|
367
+ @config.each do |key, value|
368
+ if !key.eql?('id') && !key.eql?('event_hubs')
369
+ event_hub[key] = value unless event_hub[key]
370
+ end
371
+ end
372
+ end
373
+ @logger.debug("Exploded Event Hub configuration.", :event_hubs_exploded => @event_hubs_exploded.to_s)
374
+ end
375
+
376
+ def run(queue)
377
+ event_hub_threads = []
378
+ named_thread_factory = LogStash::Inputs::Azure::NamedThreadFactory.new("azure_event_hubs-worker", @id)
379
+ scheduled_executor_service = Executors.newScheduledThreadPool(@threads, named_thread_factory)
380
+ @event_hubs_exploded.each do |event_hub|
381
+ event_hub_threads << Thread.new do
382
+ event_hub_name = event_hub['event_hubs'].first # there will always only be 1 from @event_hubs_exploded
383
+ @logger.info("Event Hub #{event_hub_name} is initializing... ")
384
+ begin
385
+ if event_hub['storage_connection']
386
+ event_processor_host = EventProcessorHost.new(
387
+ EventProcessorHost.createHostName('logstash'),
388
+ event_hub_name,
389
+ event_hub['consumer_group'],
390
+ event_hub['event_hub_connections'].first.value, #there will only be one in this array by the time it gets here
391
+ event_hub['storage_connection'].value,
392
+ event_hub.fetch('storage_container', event_hub_name),
393
+ scheduled_executor_service)
394
+ else
395
+ @logger.warn("You have NOT specified a `storage_connection_string` for #{event_hub_name}. This configuration is only supported for a single Logstash instance.")
396
+ checkpoint_manager = InMemoryCheckpointManager.new
397
+ lease_manager = InMemoryLeaseManager.new
398
+ event_processor_host = EventProcessorHost.new(
399
+ EventProcessorHost.createHostName('logstash'),
400
+ event_hub_name,
401
+ event_hub['consumer_group'],
402
+ event_hub['event_hub_connections'].first.value, #there will only be one in this array by the time it gets here
403
+ checkpoint_manager,
404
+ lease_manager,
405
+ scheduled_executor_service,
406
+ nil)
407
+ #using java_send to avoid naming conflicts with 'initialize' method
408
+ lease_manager.java_send :initialize, [HostContext], event_processor_host.getHostContext
409
+ checkpoint_manager.java_send :initialize, [HostContext], event_processor_host.getHostContext
410
+ end
411
+ options = EventProcessorOptions.new
412
+ options.setExceptionNotification(LogStash::Inputs::Azure::ErrorNotificationHandler.new)
413
+ case @initial_position
414
+ when 'beginning'
415
+ msg = "Configuring Event Hub #{event_hub_name} to read events all events."
416
+ @logger.debug("If this is the initial read... " + msg) if event_hub['storage_connection']
417
+ @logger.info(msg) unless event_hub['storage_connection']
418
+ options.setInitialPositionProvider(EventProcessorOptions::StartOfStreamInitialPositionProvider.new(options))
419
+ when 'end'
420
+ msg = "Configuring Event Hub #{event_hub_name} to read only new events."
421
+ @logger.debug("If this is the initial read... " + msg) if event_hub['storage_connection']
422
+ @logger.info(msg) unless event_hub['storage_connection']
423
+ options.setInitialPositionProvider(EventProcessorOptions::EndOfStreamInitialPositionProvider.new(options))
424
+ when 'look_back'
425
+ msg = "Configuring Event Hub #{event_hub_name} to read events starting at 'now - #{@initial_position_look_back}' seconds."
426
+ @logger.debug("If this is the initial read... " + msg) if event_hub['storage_connection']
427
+ @logger.info(msg) unless event_hub['storage_connection']
428
+ options.setInitialPositionProvider(LogStash::Inputs::Azure::LookBackPositionProvider.new(@initial_position_look_back))
429
+ end
430
+ event_processor_host.registerEventProcessorFactory(LogStash::Inputs::Azure::ProcessorFactory.new(queue, event_hub['codec'], event_hub['checkpoint_interval'], self.method(:decorate), event_hub['decorate_events']), options)
431
+ .whenComplete {|x, e|
432
+ @logger.info("Event Hub registration complete. ", :event_hub_name => event_processor_host.getHostContext.getEventHubPath.to_s )
433
+ @logger.error("Event Hub failure while registering.", :event_hub_name => event_processor_host.getHostContext.getEventHubPath.to_s, :exception => e, :backtrace => e.backtrace) if e
434
+ }
435
+ .then_accept {|x|
436
+ @logger.info("Event Hub is processing events... ", :event_hub_name => event_processor_host.getHostContext.getEventHubPath.to_s )
437
+ # this blocks the completable future chain from progressing, actual work is done via the executor service
438
+ while !stop?
439
+ Stud.stoppable_sleep(1) {stop?}
440
+ end
441
+ }
442
+ .thenCompose {|x|
443
+ @logger.info("Unregistering Event Hub this can take a while... ", :event_hub_name => event_processor_host.getHostContext.getEventHubPath.to_s )
444
+ event_processor_host.unregisterEventProcessor
445
+ }
446
+ .exceptionally {|e|
447
+ @logger.error("Event Hub encountered an error.", :event_hub_name => event_processor_host.getHostContext.getEventHubPath.to_s , :exception => e, :backtrace => e.backtrace) if e
448
+ nil
449
+ }
450
+ .get # this blocks till all of the futures are complete.
451
+ @logger.info("Event Hub #{event_processor_host.getHostContext.getEventHubPath.to_s} is closed.")
452
+ rescue => e
453
+ @logger.error("Event Hub failed during initialization.", :event_hub_name => event_hub_name, :exception => e, :backtrace => e.backtrace) if e
454
+ do_stop
455
+ end
456
+ end
457
+ end
458
+
459
+ # this blocks the input from existing. (all work is being done in threads)
460
+ while !stop?
461
+ Stud.stoppable_sleep(1) {stop?}
462
+ end
463
+
464
+ # This blocks the input till all the threads have run to completion.
465
+ event_hub_threads.each do |thread|
466
+ thread.join
467
+ end
468
+
469
+ # Ensure proper shutdown of executor service. # Note - this causes a harmless warning in the logs that scheduled tasks are being rejected.
470
+ scheduled_executor_service.shutdown
471
+ begin
472
+ scheduled_executor_service.awaitTermination(10, TimeUnit::MINUTES);
473
+ rescue => e
474
+ @logger.debug("interrupted while waiting to close executor service, this can generally be ignored", :exception => e, :backtrace => e.backtrace) if e
475
+ end
476
+ end
477
+ end
478
+
479
+