fluent-plugin-azureeventhubs_splunk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b26b2a5309570c664ba85890015ece297d430b878c57d863245c80b0b2105734
4
+ data.tar.gz: ce9cfe9ce9515cc2f10b87c478ba70be27ac70fe76b9079ae84aacf1fe02b7d8
5
+ SHA512:
6
+ metadata.gz: 3a1bf4937c3e9e1ceccb13993d8f1696893f89e94a37438d6bba23271897e37ab73060d3f1034187699eb1759b429075ab9468ae5d7d45009ea53c0a6d4804a3
7
+ data.tar.gz: f86de1be539821695fbd5187ddd0e29ec4280f22a86ea9698a7c1abb226c42d6949c30aee1f86c9abab20a51cb88c0f6bba8fa35ee76520f5f2825d06485c22a
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-azureeventhubs_splunk.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,48 @@
1
+ # Fluent::Plugin::AzureeventhubsSplunk
2
+
3
+ Azure Event Hubs buffered output plugin for Fluentd in Splunk format.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fluent-plugin-azureeventhubs_splunk'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fluent-plugin-azureeventhubs_splunk
20
+
21
+ ## Configuration
22
+
23
+ ```
24
+ <match pattern>
25
+ type azureeventhubs_splunk
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
+ </match>
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( https://github.com/[my-github-username]/fluent-plugin-azureeventhubs_splunk/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,22 @@
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_splunk"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["James Peet"]
9
+ spec.email = ["james.peet@amido.com"]
10
+ spec.summary = "Forwards Fluentd output to Azure EventHubs in Splunk format"
11
+ spec.description = "Forwards Fluentd output to Azure EventHubs in Splunk format. Forked from https://github.com/htgc/fluent-plugin-azureeventhubs"
12
+ spec.homepage = "https://github.com/peet-j/fluent-plugin-azureeventhubs_splunk"
13
+ spec.license = "MIT"
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.7"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_dependency "fluentd", [">= 0.14.15", "< 2"]
22
+ end
@@ -0,0 +1,78 @@
1
+
2
+ class AzureEventHubsSplunkHttpSender
3
+ def initialize(plugin, 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
+ @plugin = plugin
11
+ @connection_string = connection_string
12
+ @hub_name = hub_name
13
+ @expiry_interval = expiry
14
+ @proxy_addr = proxy_addr
15
+ @proxy_port = proxy_port
16
+ @open_timeout = open_timeout
17
+ @read_timeout = read_timeout
18
+
19
+ if @connection_string.count(';') != 2
20
+ raise "Connection String format is not correct"
21
+ end
22
+
23
+ @connection_string.split(';').each do |part|
24
+ if ( part.index('Endpoint') == 0 )
25
+ @endpoint = 'https' + part[11..-1]
26
+ elsif ( part.index('SharedAccessKeyName') == 0 )
27
+ @sas_key_name = part[20..-1]
28
+ elsif ( part.index('SharedAccessKey') == 0 )
29
+ @sas_key_value = part[16..-1]
30
+ end
31
+ end
32
+ @uri = URI.parse("#{@endpoint}#{@hub_name}/messages")
33
+ @plugin.log.info "Initialized AzureEventHubsSplunkHttpSender. uri: #{@uri}"
34
+ end
35
+
36
+ def generate_sas_token(uri)
37
+ target_uri = CGI.escape(uri.downcase).downcase
38
+ expiry = Time.now.to_i + @expiry_interval
39
+ to_sign = "#{target_uri}\n#{expiry}";
40
+ signature = CGI.escape(Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha256'), @sas_key_value, to_sign)).strip())
41
+ token = "SharedAccessSignature sr=#{target_uri}&sig=#{signature}&se=#{expiry}&skn=#{@sas_key_name}"
42
+ return token
43
+ end
44
+
45
+ private :generate_sas_token
46
+
47
+ def send(payload)
48
+ send_w_properties(payload, nil)
49
+ end
50
+
51
+ def send_w_properties(payload, properties)
52
+ token = generate_sas_token(@uri.to_s)
53
+ headers = {
54
+ 'Content-Type' => 'application/json;type=entry;charset=utf-8',
55
+ 'Authorization' => token
56
+ }
57
+ if not properties.nil?
58
+ headers = headers.merge(properties)
59
+ end
60
+ if (@proxy_addr.to_s.empty?)
61
+ https = Net::HTTP.new(@uri.host, @uri.port)
62
+ https.open_timeout = @open_timeout
63
+ https.read_timeout = @read_timeout
64
+ else
65
+ https = Net::HTTP.new(@uri.host, @uri.port,@proxy_addr,@proxy_port)
66
+ https.open_timeout = @open_timeout
67
+ https.read_timeout = @read_timeout
68
+ end
69
+ https.use_ssl = true
70
+ req = Net::HTTP::Post.new(@uri.request_uri, headers)
71
+ req.body = payload.to_json
72
+ @plugin.log.info "Sending payload to EventHub: #{req.body}"
73
+ res = https.request(req)
74
+ @plugin.log.info "Response code from EventHub: #{res.code}"
75
+ @plugin.log.info "Response body from EventHub: #{res.body}"
76
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Errno::ETIMEDOUT, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
77
+ end
78
+ end
@@ -0,0 +1,79 @@
1
+ module Fluent::Plugin
2
+
3
+ class AzureEventHubsOutputSplunk < Output
4
+ Fluent::Plugin.register_output('azureeventhubs_splunk', 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 :max_events_per_send, :integer, :default => 100
23
+
24
+ config_section :buffer do
25
+ config_set_default :@type, DEFAULT_BUFFER_TYPE
26
+ config_set_default :chunk_keys, ['tag']
27
+ end
28
+
29
+ def configure(conf)
30
+ compat_parameters_convert(conf, :buffer, :inject)
31
+ super
32
+ case @type
33
+ when 'amqps'
34
+ raise NotImplementedError
35
+ else
36
+ require_relative 'azureeventhubsplunk/http'
37
+ @sender = AzureEventHubsSplunkHttpSender.new(self, @connection_string, @hub_name, @expiry_interval, @proxy_addr, @proxy_port, @open_timeout, @read_timeout)
38
+ end
39
+ raise Fluent::ConfigError, "'tag' in chunk_keys is required." if not @chunk_key_tag
40
+ end
41
+
42
+ def format(tag, time, record)
43
+ record = inject_values_to_record(tag, time, record)
44
+ [tag, time, record].to_msgpack
45
+ end
46
+
47
+ def formatted_to_msgpack_binary?
48
+ true
49
+ end
50
+
51
+ def write(chunk)
52
+ log.info "Have EventHub chunk to write..."
53
+ chunk.msgpack_each { |tag, time, record|
54
+ records ||= []
55
+ p record.to_s
56
+ if @include_tag
57
+ record['tag'] = tag
58
+ end
59
+ if @include_time
60
+ record[@tag_time_name] = time
61
+ end
62
+ records << record
63
+ }
64
+ log.info "Processed batch of #{records.size()}. Forwarding to EventHub..."
65
+ process_in_batches(records)
66
+ end
67
+
68
+ # This will need tuning dependent on eventhub/splunk payload limits
69
+ # Also ought to have some error handling
70
+ def process_in_batches(records)
71
+ records.each_slice(@max_events_per_send).each { |batch|
72
+ payload = { "records" => batch }
73
+ log.info "Sending batch of #{batch.size()} records to EventHub..."
74
+ @sender.send_w_properties(payload, @message_properties)
75
+ }
76
+ end
77
+
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-azureeventhubs_splunk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - James Peet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-24 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: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
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: Forwards Fluentd output to Azure EventHubs in Splunk format. Forked from
62
+ https://github.com/htgc/fluent-plugin-azureeventhubs
63
+ email:
64
+ - james.peet@amido.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - fluent-plugin-azureeventhubs-splunk.gemspec
74
+ - lib/fluent/plugin/azureeventhubsplunk/http.rb
75
+ - lib/fluent/plugin/out_azureeventhubs_splunk.rb
76
+ homepage: https://github.com/peet-j/fluent-plugin-azureeventhubs_splunk
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.7.4
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Forwards Fluentd output to Azure EventHubs in Splunk format
100
+ test_files: []