fluent-plugin-azureeventhubs-batched 0.0.1

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: 74def7d027bf6127cd29286e4758a92c0ed8be4c40863c838b899eabcb27ceac
4
+ data.tar.gz: e700d8820a647de916e71c4c90748c79c0db23b0951c74a75a5e6ff2f938a97d
5
+ SHA512:
6
+ metadata.gz: 00f123f4e1065205a7ba14a833717cbeb3c6ae3822638e18da5e74dc12d045fabf1a322fc91b9c53a2454a1556e6738c1b2828706ef898857ea213b93b39e95a
7
+ data.tar.gz: 2f8005cf7aa5223e8b138dd42a4dcb074af6b80727c719666d72d2268d86cd3773125c1b04f5ce0af616740e533ed9652b892c9561688c3b088cf98a463e1b21
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-azureeventhubs.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Hidemasa Togashi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Fluent::Plugin::Azureeventhubs
2
+
3
+ Azure Event Hubs buffered output plugin for Fluentd.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fluent-plugin-azureeventhubs'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fluent-plugin-azureeventhubs
20
+
21
+ ## Configuration
22
+
23
+ ```
24
+ <match pattern>
25
+ type azureeventhubs_buffered
26
+
27
+ connection_string <Paste SAS connection string from Azure Management Potal>
28
+ hub_name <Name of Event Hubs>
29
+ include_tag (true|false) # true: Include tag into record [Optional: default => false]
30
+ include_time (true|false) # true: Include time into record [Optional: default => false]
31
+ tag_time_name record_time # record tag for time when include_time sets true. [Optional: default => 'time']
32
+ type (https|amqps) # Connection type. [Optional: default => https]. Note that amqps is not implementated.
33
+ expiry_interval <Integer number> # Signature expiration time interval in seconds. [Optional: default => 3600 (60min)]
34
+ proxy_addr <Host or IP> # Address of the proxy [Optional]
35
+ proxy_port <Integer> # Proxy port. [Optional: default => 3128]
36
+ read_timeout <Integer> # HTTP Read timeout in seconds[Optional: default => 60]
37
+ open_timeout <Integer> # HTTP Open timeout in seconds[Optional: default => 60]
38
+ message_properties <Json Object> # A json object of key/value pairs to add Properties to the events being sent to EventHubs [Optional: default => nil]
39
+ batch (true|false) # true: Send a collection of records to Event Hubs instead of one message per record. [Optional: default => false]
40
+ max_batch_size <Integer> # The max number of records to send in a single message to Event Hubs. [Optional: default => 20]
41
+ print_records (true|false) # true: Print each record as it is processed. [Optional: default => true]
42
+ </match>
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/[my-github-username]/fluent-plugin-azureeventhubs/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-azureeventhubs-batched"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Hidemasa Togashi", "Toddy Mladenov", "Justin Seely", "Chih Hsiang Hsu"]
9
+ spec.email = ["togachiro@gmail.com", "toddysm@gmail.com", "s8901489@gmail.com"]
10
+ spec.summary = "Fluentd output plugin for Azure Event Hubs"
11
+ spec.description = "Fluentd output plugin for Azure Event Hubs"
12
+ spec.homepage = "https://github.com/ChihSeanHsu/fluent-plugin-azureeventhubs-batched"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_dependency "fluentd", [">= 0.14.15", "< 2"]
23
+ end
@@ -0,0 +1,74 @@
1
+
2
+ class AzureEventHubsHttpSender
3
+ def initialize(connection_string, hub_name, expiry=3600,proxy_addr='',proxy_port=3128,open_timeout=60,read_timeout=60)
4
+ require 'openssl'
5
+ require 'base64'
6
+ require 'net/http'
7
+ require 'json'
8
+ require 'cgi'
9
+ require 'time'
10
+ @connection_string = connection_string
11
+ @hub_name = hub_name
12
+ @expiry_interval = expiry
13
+ @proxy_addr = proxy_addr
14
+ @proxy_port = proxy_port
15
+ @open_timeout = open_timeout
16
+ @read_timeout = read_timeout
17
+
18
+ if @connection_string.count(';') != 2
19
+ raise "Connection String format is not correct"
20
+ end
21
+
22
+ @connection_string.split(';').each do |part|
23
+ if ( part.index('Endpoint') == 0 )
24
+ @endpoint = 'https' + part[11..-1]
25
+ elsif ( part.index('SharedAccessKeyName') == 0 )
26
+ @sas_key_name = part[20..-1]
27
+ elsif ( part.index('SharedAccessKey') == 0 )
28
+ @sas_key_value = part[16..-1]
29
+ end
30
+ end
31
+ @uri = URI.parse("#{@endpoint}#{@hub_name}/messages")
32
+ end
33
+
34
+ def generate_sas_token(uri)
35
+ target_uri = CGI.escape(uri.downcase).downcase
36
+ expiry = Time.now.to_i + @expiry_interval
37
+ to_sign = "#{target_uri}\n#{expiry}";
38
+ signature = CGI.escape(Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), @sas_key_value, to_sign)).strip())
39
+
40
+ token = "SharedAccessSignature sr=#{target_uri}&sig=#{signature}&se=#{expiry}&skn=#{@sas_key_name}"
41
+ return token
42
+ end
43
+
44
+ private :generate_sas_token
45
+
46
+ def send(payload)
47
+ send_w_properties(payload, nil)
48
+ end
49
+
50
+ def send_w_properties(payload, properties)
51
+ token = generate_sas_token(@uri.to_s)
52
+ headers = {
53
+ 'Content-Type' => 'application/atom+xml;type=entry;charset=utf-8',
54
+ 'Authorization' => token
55
+ }
56
+ if not properties.nil?
57
+ headers = headers.merge(properties)
58
+ end
59
+ if (@proxy_addr.to_s.empty?)
60
+ https = Net::HTTP.new(@uri.host, @uri.port)
61
+ https.open_timeout = @open_timeout
62
+ https.read_timeout = @read_timeout
63
+ else
64
+ https = Net::HTTP.new(@uri.host, @uri.port,@proxy_addr,@proxy_port)
65
+ https.open_timeout = @open_timeout
66
+ https.read_timeout = @read_timeout
67
+ end
68
+ https.use_ssl = true
69
+ req = Net::HTTP::Post.new(@uri.request_uri, headers)
70
+ req.body = payload.to_json
71
+ res = https.request(req)
72
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Errno::ETIMEDOUT, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
73
+ end
74
+ end
@@ -0,0 +1,93 @@
1
+ module Fluent::Plugin
2
+
3
+ class AzureEventHubsOutputBuffered < Output
4
+ Fluent::Plugin.register_output('azureeventhubs_buffered', self)
5
+
6
+ helpers :compat_parameters, :inject
7
+
8
+ DEFAULT_BUFFER_TYPE = "memory"
9
+
10
+ config_param :connection_string, :string
11
+ config_param :hub_name, :string
12
+ config_param :include_tag, :bool, :default => false
13
+ config_param :include_time, :bool, :default => false
14
+ config_param :tag_time_name, :string, :default => 'time'
15
+ config_param :expiry_interval, :integer, :default => 3600 # 60min
16
+ config_param :type, :string, :default => 'https' # https / amqps (Not Implemented)
17
+ config_param :proxy_addr, :string, :default => ''
18
+ config_param :proxy_port, :integer,:default => 3128
19
+ config_param :open_timeout, :integer,:default => 60
20
+ config_param :read_timeout, :integer,:default => 60
21
+ config_param :message_properties, :hash, :default => nil
22
+ config_param :batch, :bool, :default => false
23
+ config_param :max_batch_size, :integer,:default => 20
24
+ config_param :print_records, :bool, :default => true
25
+
26
+ config_section :buffer do
27
+ config_set_default :@type, DEFAULT_BUFFER_TYPE
28
+ config_set_default :chunk_keys, ['tag']
29
+ end
30
+
31
+ def configure(conf)
32
+ compat_parameters_convert(conf, :buffer, :inject)
33
+ super
34
+ case @type
35
+ when 'amqps'
36
+ raise NotImplementedError
37
+ else
38
+ require_relative 'azureeventhubs/http'
39
+ @sender = AzureEventHubsHttpSender.new(@connection_string, @hub_name, @expiry_interval,@proxy_addr,@proxy_port,@open_timeout,@read_timeout)
40
+ end
41
+ raise Fluent::ConfigError, "'tag' in chunk_keys is required." if not @chunk_key_tag
42
+ end
43
+
44
+ def format(tag, time, record)
45
+ record = inject_values_to_record(tag, time, record)
46
+ [tag, time, record].to_msgpack
47
+ end
48
+
49
+ def formatted_to_msgpack_binary?
50
+ true
51
+ end
52
+
53
+ def write(chunk)
54
+ @batch ? write_batched(chunk) : write_singularly(chunk)
55
+ end
56
+
57
+ def write_singularly(chunk)
58
+ chunk.msgpack_each { |tag, time, record|
59
+ if @print_records
60
+ p record.to_s
61
+ end
62
+ enrich_record(tag, time, record)
63
+ @sender.send_w_properties(record, @message_properties)
64
+ }
65
+ end
66
+
67
+ def write_batched(chunk)
68
+ records = []
69
+ chunk.msgpack_each { |tag, time, record|
70
+ if @print_records
71
+ p record.to_s
72
+ end
73
+ enrich_record(tag, time, record)
74
+
75
+ records << record
76
+ }
77
+
78
+ records.each_slice(@max_batch_size).each { |group|
79
+ payload = { "records" => group }
80
+ @sender.send_w_properties(payload, @message_properties)
81
+ }
82
+ end
83
+
84
+ def enrich_record(tag, time, record)
85
+ if @include_tag
86
+ record['tag'] = tag
87
+ end
88
+ if @include_time
89
+ record[@tag_time_name] = time
90
+ end
91
+ end
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-azureeventhubs-batched
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hidemasa Togashi
8
+ - Toddy Mladenov
9
+ - Justin Seely
10
+ - Chih Hsiang Hsu
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2021-03-29 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: bundler
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.7'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.7'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '10.0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '10.0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: fluentd
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.14.15
51
+ - - "<"
52
+ - !ruby/object:Gem::Version
53
+ version: '2'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.14.15
61
+ - - "<"
62
+ - !ruby/object:Gem::Version
63
+ version: '2'
64
+ description: Fluentd output plugin for Azure Event Hubs
65
+ email:
66
+ - togachiro@gmail.com
67
+ - toddysm@gmail.com
68
+ - s8901489@gmail.com
69
+ executables: []
70
+ extensions: []
71
+ extra_rdoc_files: []
72
+ files:
73
+ - ".gitignore"
74
+ - Gemfile
75
+ - LICENSE.txt
76
+ - README.md
77
+ - Rakefile
78
+ - fluent-plugin-azureeventhubs-batched.gemspec
79
+ - lib/fluent/plugin/azureeventhubs/http.rb
80
+ - lib/fluent/plugin/out_azureeventhubs_buffered.rb
81
+ homepage: https://github.com/ChihSeanHsu/fluent-plugin-azureeventhubs-batched
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubygems_version: 3.0.3
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Fluentd output plugin for Azure Event Hubs
104
+ test_files: []