async-fluent-plugin-azureeventhubs 0.0.1

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: 895d5c57e671be39e4ccd9be2def670d02f87b1171af01b41d926f4bfbb8f021
4
+ data.tar.gz: dea3b6593fd2716aa7d22d430a97ba4433c7e584b36e4b2820b44966b0232ce4
5
+ SHA512:
6
+ metadata.gz: 88c23e1607e61424d62ffe3645ab7ece75d996f129942432b1b3da7e056cfab6964a1547d374dfb454360df8f986789e07511e4819c314c67c058d9769eb9571
7
+ data.tar.gz: 999590adf69222f41e63cb4f06d592a92853ed4f27ecfbe25817d2e6f4f1527c5fa44838b3efccb0b69f9bf7201e9e74a636be99a3e40c7280f2b393810974e1
@@ -0,0 +1,4 @@
1
+ /.idea/vcs.xml
2
+ /.idea/async-fluent-plugin-azureeventhubs.iml
3
+ /.idea/modules.xml
4
+ /.idea/workspace.xml
@@ -0,0 +1,28 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.1
5
+ - 2.2
6
+ - 2.3.1
7
+ - 2.4.1
8
+ - 2.5.0
9
+ - ruby-head
10
+
11
+ before_install:
12
+ - gem update --system
13
+
14
+ script:
15
+ - bundle exec rake test
16
+
17
+ sudo: false
18
+
19
+ matrix:
20
+ allow_failures:
21
+ - rvm: ruby-head
22
+ deploy:
23
+ provider: rubygems
24
+ api_key: "bc5cc687adff822e861d4df96c0986e4"
25
+ gemspec: aync-fluent-plugin-azureeventhubs.gemspec
26
+ on:
27
+ tags: true
28
+ all_branches: true
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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 sio2k
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # async-fluent-plugin-azureeventhubs-
2
+ [![Build Status](https://travis-ci.com/sio2k/async-fluent-plugin-azureeventhubs-.svg?branch=master)](https://travis-ci.com/sio2k/async-fluent-plugin-azureeventhubs-)
3
+ Inspired by https://github.com/htgc/fluent-plugin-azureeventhubs
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+
7
+
8
+ task :default => [:build]
@@ -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 = "async-fluent-plugin-azureeventhubs"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Sandeep Kotha"]
9
+ spec.email = ["sandeep.kotha@live.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/htgc/fluent-plugin-azureeventhubs"
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", "~> 12.3"
22
+ spec.add_dependency "fluentd", [">= 0.14.15", "< 2"]
23
+ end
@@ -0,0 +1,67 @@
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 'unirest'
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
+ Unirest.post @uri.request_uri,
60
+ headers:{ 'Content-Type' => 'application/atom+xml;type=entry;charset=utf-8',
61
+ 'Authorization' => token
62
+ },
63
+ parameters:payload {|response|
64
+ response.code
65
+ }
66
+ end
67
+ end
@@ -0,0 +1,63 @@
1
+ module Fluent::Plugin
2
+
3
+ class AzureEventHubsOutputBuffered < Output
4
+ Fluent::Plugin.register_output('azure_eventhub_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
+
23
+ config_section :buffer do
24
+ config_set_default :@type, DEFAULT_BUFFER_TYPE
25
+ config_set_default :chunk_keys, ['tag']
26
+ end
27
+
28
+ def configure(conf)
29
+ compat_parameters_convert(conf, :buffer, :inject)
30
+ super
31
+ case @type
32
+ when 'amqps'
33
+ raise NotImplementedError
34
+ else
35
+ require_relative 'azureeventhubs/http'
36
+ @sender = AzureEventHubsHttpSender.new(@connection_string, @hub_name, @expiry_interval,@proxy_addr,@proxy_port,@open_timeout,@read_timeout)
37
+ end
38
+ raise Fluent::ConfigError, "'tag' in chunk_keys is required." if not @chunk_key_tag
39
+ end
40
+
41
+ def format(tag, time, record)
42
+ record = inject_values_to_record(tag, time, record)
43
+ [tag, time, record].to_msgpack
44
+ end
45
+
46
+ def formatted_to_msgpack_binary?
47
+ true
48
+ end
49
+
50
+ def write(chunk)
51
+ chunk.msgpack_each { |tag, time, record|
52
+ p record.to_s
53
+ if @include_tag
54
+ record['tag'] = tag
55
+ end
56
+ if @include_time
57
+ record[@tag_time_name] = time
58
+ end
59
+ @sender.send_w_properties(record, @message_properties)
60
+ }
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ require 'fluent/test'
15
+ unless ENV.has_key?('VERBOSE')
16
+ nulllogger = Object.new
17
+ nulllogger.instance_eval {|obj|
18
+ def method_missing(method, *args)
19
+ end
20
+ }
21
+ $log = nulllogger
22
+ end
23
+
24
+
25
+ class Test::Unit::TestCase
26
+ end
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+ require 'fluent/output'
3
+
4
+ class AzureEventHubTest < Test::Unit::TestCase
5
+ def setup
6
+ Fluent::Test.setup
7
+ end
8
+
9
+ BASE_CONFIG = %[
10
+ type azure_eventhub_buffered
11
+ ]
12
+
13
+ CONFIG = BASE_CONFIG + %[
14
+ connection_string sb://sample
15
+ ]
16
+
17
+ def create_driver(conf = CONFIG, tag='test')
18
+ "sample"
19
+ end
20
+
21
+
22
+
23
+ def test_format
24
+ d = create_driver
25
+ assert_equal 'sample', d
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: async-fluent-plugin-azureeventhubs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sandeep Kotha
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fluentd
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.14.15
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '2'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 0.14.15
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '2'
61
+ description: Fluentd output plugin for Azure Event Hubs
62
+ email:
63
+ - sandeep.kotha@live.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - ".travis.yml"
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - aync-fluent-plugin-azureeventhubs.gemspec
75
+ - lib/fluent/plugin/azureeventhubs/http.rb
76
+ - lib/fluent/plugin/out_azureeventhubs_buffered.rb
77
+ - test/helper.rb
78
+ - test/plugin/test_out_azure_event_hub.rb
79
+ homepage: https://github.com/htgc/fluent-plugin-azureeventhubs
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.7.7
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Fluentd output plugin for Azure Event Hubs
103
+ test_files:
104
+ - test/helper.rb
105
+ - test/plugin/test_out_azure_event_hub.rb