fluent-plugin-griddb 1.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: dfa1f367763ceb308d6cac0dfc57951bbc81e7ad46a72b6e81feece042474a6c
4
+ data.tar.gz: 0f94a3e33a970b76beddcd1d387406556e24c11761611d5352e24aa5d98ea55a
5
+ SHA512:
6
+ metadata.gz: 605222fa8fb0f4b5a38f06f10867586674f7a53bb9866557482c1b0760e986a2487837e55a22ebc055734a200ea1c32255f32e7d052fd9fec55d4c33ef3dc7d9
7
+ data.tar.gz: 67bd8d6eeedb6a8dbbe2749cb19b001cd6838123a0cb0668c7a3230ee1548f3d0f62b3e88de4664c2594a7e4c6c21fa20be97e7e4dbbd478dc76f8b3893186f9
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__)
4
+
5
+ module Fluent
6
+ module GridDBAuthParams
7
+ def self.included(klass)
8
+ klass.instance_eval {
9
+ desc "Host to GridDB Server"
10
+ # Endpoint URL ex. http://localhost.local/api/
11
+ config_param :host, :string
12
+
13
+ desc "Cluster name"
14
+ # Cluster name to GridDB Server
15
+ config_param :cluster, :string
16
+
17
+ desc "Database name"
18
+ # Database name in GridDB Server
19
+ config_param :database, :string
20
+
21
+ desc "Container name"
22
+ # Container name in database
23
+ config_param :container, :string
24
+
25
+ desc "Username of GridDB account"
26
+ # GridDB username account
27
+ config_param :username, :string, :default => ''
28
+
29
+ desc "Password of GridDB account"
30
+ # GridDB password account
31
+ config_param :password, :string, :default => '', :secret => true
32
+
33
+ # Switch non-buffered/buffered plugin
34
+ config_param :buffered, :bool, :default => false
35
+ }
36
+ end
37
+ end
38
+
39
+ module GridDBAuth
40
+
41
+ # Set type for request body
42
+ def set_body(req, record)
43
+ req.body = Yajl.dump(record)
44
+ req['Content-Type'] = 'application/json'
45
+ end
46
+
47
+ # Create new request
48
+ def create_request(record)
49
+ url = format_url()
50
+ uri = URI.parse(URI.encode(url))
51
+ req = Net::HTTP::Put.new(uri.request_uri)
52
+ req.basic_auth(@username, @password)
53
+ set_body(req, record)
54
+ return req, uri
55
+ end
56
+
57
+ # Send request
58
+ def send_request(req, uri)
59
+ res = nil
60
+ begin
61
+ @last_request_time = Time.now.to_f
62
+ res = Net::HTTP.start(uri.host, uri.port) {|http| http.request(req) }
63
+
64
+ rescue => e
65
+ log.warn "Net::HTTP.#{req.method.capitalize} raises exception: #{e.class}, '#{e.message}'"
66
+ raise e if @raise_on_error
67
+ else
68
+ unless res and res.is_a?(Net::HTTPSuccess)
69
+ res_summary = if res
70
+ "#{res.code} #{res.message} #{res.body}"
71
+ else
72
+ "res=nil"
73
+ end
74
+ log.warn "failed to #{req.method} #{uri} (#{res_summary})"
75
+ end
76
+ end
77
+ end
78
+
79
+ # Get URL to API
80
+ def format_url()
81
+ if $real_container.nil? || $real_container.empty?
82
+ @host + "/griddb/v2/" + @cluster + "/dbs/" + @database + "/containers/" + @container + "/rows"
83
+ else
84
+ @host + "/griddb/v2/" + @cluster + "/dbs/" + @database + "/containers/" + $real_container + "/rows"
85
+ end
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: .unshift File.dirname(__FILE__)
4
+
5
+ module Fluent
6
+ module GridDBData
7
+ # Format for chunk data
8
+ def chunk_convert(chunk)
9
+ arrays_2 = Array.new
10
+ tmp = Array.new
11
+ chunk.msgpack_each do |time, record|
12
+ tmp = hash_to_array(record)
13
+ arrays_2.push(tmp)
14
+ end
15
+ arrays_2
16
+ end
17
+
18
+ #Format for each record
19
+ def convert(record)
20
+ arrays_2 = Array.new
21
+ tmp = hash_to_array(record)
22
+ arrays_2.push(tmp)
23
+ end
24
+
25
+ # Covert from hash object to array
26
+ def hash_to_array(record)
27
+ arr = Array.new
28
+ record.map do |key, val |
29
+ arr.push(val)
30
+ end
31
+ arr
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,119 @@
1
+ require "fluent/plugin/output"
2
+ require_relative 'griddb_auth'
3
+ require_relative 'griddb_data'
4
+ require "net/http"
5
+ require "uri"
6
+ require "yajl"
7
+ require "date"
8
+
9
+ module Fluent
10
+ module Plugin
11
+ class GriddbOutput < Fluent::Plugin::Output
12
+ Fluent::Plugin.register_output("griddb", self)
13
+ helpers :compat_parameters
14
+
15
+ include Fluent::GridDBAuthParams
16
+ include Fluent::GridDBAuth
17
+ include Fluent::GridDBData
18
+
19
+ DEFAULT_BUFFER_TYPE = "memory"
20
+ DEFAULT_FORMATTER = "json"
21
+
22
+ def initialize
23
+ super
24
+ end
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
+ config_section :format do
32
+ config_set_default :@type, DEFAULT_FORMATTER
33
+ end
34
+
35
+ def configure(conf)
36
+ compat_parameters_convert(conf, :buffer, :formatter)
37
+ super
38
+
39
+ if @host.nil? || @host.empty?
40
+ raise Fluent::ConfigError, "Host must be not null or empty"
41
+ end
42
+
43
+ if @cluster.nil? || @cluster.empty?
44
+ raise Fluent::ConfigError, "Cluster must be not null or empty"
45
+ end
46
+
47
+ if @database.nil? || @database.empty?
48
+ raise Fluent::ConfigError, "Database must be not null or empty"
49
+ end
50
+
51
+ if @container.nil? || @container.empty?
52
+ raise Fluent::ConfigError, "Container must be not null or empty"
53
+ end
54
+
55
+ if @username.nil? || @username.empty?
56
+ raise Fluent::ConfigError, "Username must be not null or empty"
57
+ end
58
+
59
+ if @password.nil? || @password.empty?
60
+ raise Fluent::ConfigError, "Password must be not null or empty"
61
+ end
62
+
63
+ raise Fluent::ConfigError, "'tag' in chunk_keys is required." if !@chunk_key_tag && @buffered
64
+
65
+ if @formatter_config = conf.elements('format').first
66
+ log.warn "griddb out plugin is not support format section"
67
+ end
68
+ end
69
+
70
+ def start
71
+ super
72
+ end
73
+
74
+ def shutdown
75
+ super
76
+ end
77
+
78
+ def prefer_buffered_processing
79
+ @buffered
80
+ end
81
+
82
+ # Format data is auto supported by Fluentd
83
+ def format(tag, time, record)
84
+ [time, record].to_msgpack
85
+ end
86
+
87
+ def formatted_to_msgpack_binary?
88
+ true
89
+ end
90
+
91
+ def multi_workers_ready?
92
+ true
93
+ end
94
+
95
+ # Put record to server
96
+ def handle_record(tag, time, record)
97
+ req, uri = create_request(record)
98
+ send_request(req, uri)
99
+ end
100
+
101
+ # Overwrite when Not use buffer
102
+ def process(tag, es)
103
+ es.each do |time, record|
104
+ arrays_2 = convert(record)
105
+ handle_record(tag, time, arrays_2)
106
+ end
107
+ end
108
+
109
+ # Overwrite when use buffer
110
+ def write(chunk)
111
+ tag = chunk.metadata.tag
112
+ $real_container = extract_placeholders(@container, chunk)
113
+ arrays_2 = chunk_convert(chunk)
114
+ handle_record(tag, DateTime.now, arrays_2)
115
+ end
116
+
117
+ end
118
+ end
119
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-griddb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - TOSHIBA Digital Solutions Corporation
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-12 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fluentd
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.10
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '2'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 0.14.10
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '2'
75
+ description: Put data to GridDB server via Put row API
76
+ email:
77
+ - contact@griddb.org
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - lib/fluent/plugin/griddb_auth.rb
83
+ - lib/fluent/plugin/griddb_data.rb
84
+ - lib/fluent/plugin/out_griddb.rb
85
+ homepage: https://github.com/griddb/fluent-plugin-griddb
86
+ licenses:
87
+ - Apache-2.0
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubygems_version: 3.0.3
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Put data to GridDB
108
+ test_files: []