fluent-plugin-synerex 0.1.0

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
+ SHA1:
3
+ metadata.gz: bd78e7ef290d2db2641330bfcdc1b2ec5f0c99df
4
+ data.tar.gz: 943f53c2d65368b4e61e7c62b3e75a363f168287
5
+ SHA512:
6
+ metadata.gz: 34180f9bd1b3882abc8b139a7fbcef24c5dceba44a6a6a20e8acd6259efd9b01f82b2f30872a7832236715a375b35e5ba93228c14de9fe29077fbf29517ed967
7
+ data.tar.gz: 2254c5de1e4be134c0c5f3d51d148b508b43a36355b6f0ba3f11c142efb7ab85b923dac2f8f02c1a588cf274563c51f4a90f4f3e98cb3791852610e11d7d26b5
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
@@ -0,0 +1,3 @@
1
+ [submodule "proto_fluentd"]
2
+ path = proto_fluentd
3
+ url = https://github.com/synerex/proto_fluentd.git
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) {|repo_name| "https://github.com/synerex/fluentd-plugin-out-synerex" }
6
+
7
+ # gem "rails"
8
+
9
+ gem "grpc"
10
+ gem "grpc-tools"
11
+ gem "anyflake"
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ anyflake (0.0.1)
5
+ google-protobuf (3.9.2)
6
+ googleapis-common-protos-types (1.0.4)
7
+ google-protobuf (~> 3.0)
8
+ grpc (1.24.0)
9
+ google-protobuf (~> 3.8)
10
+ googleapis-common-protos-types (~> 1.0)
11
+ grpc-tools (1.24.0)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ anyflake
18
+ grpc
19
+ grpc-tools
20
+
21
+ BUNDLED WITH
22
+ 2.0.2
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,40 @@
1
+ # fluent-plugin-out-synerex
2
+
3
+ [Fluentd](https://fluentd.org/) output plugin for Synerex Beta (http://github.com/synerex)
4
+
5
+ ## Installation
6
+
7
+ ### RubyGems
8
+
9
+ ```
10
+ $ gem install fluent-plugin-out-synerex
11
+ ```
12
+ ### Bundler
13
+
14
+ Add following line to your Gemfile:
15
+
16
+ ```ruby
17
+ gem "fluent-plugin-out-synerex"
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ ```
23
+ $ bundle
24
+ ```
25
+
26
+ ## Configuration
27
+
28
+ You can generate configuration template:
29
+
30
+ ```
31
+ $ fluent-plugin-config-format output synerex
32
+ ```
33
+
34
+ You can copy and paste generated documents here.
35
+
36
+ ## Copyright
37
+
38
+ * Copyright(c) 2019- Nobuo Kawaguchi, Synerex project.
39
+ * License
40
+ * Apache License, Version 2.0
@@ -0,0 +1,13 @@
1
+ require "bundler"
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs.push("lib", "test")
8
+ t.test_files = FileList["test/**/test_*.rb"]
9
+ t.verbose = true
10
+ t.warning = true
11
+ end
12
+
13
+ task default: [:test]
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "fluent-plugin-synerex"
6
+ spec.version = "0.1.0"
7
+ spec.authors = ["Nobuo Kawaguchi"]
8
+ spec.email = ["rubygems@synerex.net"]
9
+
10
+ spec.summary = %q{Synerex output plugin for fluentd}
11
+ spec.description = %q{Synerex output plugin for fluentd}
12
+ spec.homepage = "http://github.com/synerex/fluent-plugin-out-synerex/"
13
+ spec.license = "Apache-2.0"
14
+
15
+ test_files, files = `git ls-files -z`.split("\x0").partition do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.files = files
19
+ spec.executables = files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = test_files
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 2.0"
24
+ spec.add_development_dependency "rake", "~> 12.0"
25
+ spec.add_development_dependency "test-unit", "~> 3.0"
26
+ spec.add_runtime_dependency "fluentd", [">= 0.14.10", "< 2"]
27
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+
3
+
4
+ bundle exec grpc_tools_ruby_protoc --ruby_out=./lib/fluent/plugin --grpc_out=./lib/fluent/plugin -I ./proto_fluentd fluentd.proto
5
+
6
+
7
+
@@ -0,0 +1,21 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: fluentd.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'google/protobuf/timestamp_pb'
7
+ Google::Protobuf::DescriptorPool.generated_pool.build do
8
+ add_file("fluentd.proto", :syntax => :proto3) do
9
+ add_message "proto.fluentd.FluentdRecord" do
10
+ optional :tag, :string, 1
11
+ optional :time, :message, 2, "google.protobuf.Timestamp"
12
+ optional :record, :bytes, 3
13
+ end
14
+ end
15
+ end
16
+
17
+ module Proto
18
+ module Fluentd
19
+ FluentdRecord = Google::Protobuf::DescriptorPool.generated_pool.lookup("proto.fluentd.FluentdRecord").msgclass
20
+ end
21
+ end
@@ -0,0 +1,56 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: nodeapi.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_file("nodeapi.proto", :syntax => :proto3) do
8
+ add_message "nodeapi.NodeInfo" do
9
+ optional :node_name, :string, 1
10
+ optional :node_type, :enum, 2, "nodeapi.NodeType"
11
+ optional :server_info, :string, 3
12
+ optional :node_pbase_version, :string, 4
13
+ optional :with_node_id, :int32, 5
14
+ optional :cluster_id, :int32, 6
15
+ optional :area_id, :string, 7
16
+ repeated :channelTypes, :uint32, 8
17
+ end
18
+ add_message "nodeapi.NodeID" do
19
+ optional :node_id, :int32, 1
20
+ optional :secret, :fixed64, 2
21
+ optional :server_info, :string, 3
22
+ optional :keepalive_duration, :int32, 4
23
+ end
24
+ add_message "nodeapi.NodeUpdate" do
25
+ optional :node_id, :int32, 1
26
+ optional :secret, :fixed64, 2
27
+ optional :update_count, :int32, 3
28
+ optional :node_status, :int32, 4
29
+ optional :node_arg, :string, 5
30
+ end
31
+ add_message "nodeapi.Response" do
32
+ optional :ok, :bool, 1
33
+ optional :command, :enum, 2, "nodeapi.KeepAliveCommand"
34
+ optional :err, :string, 3
35
+ end
36
+ add_enum "nodeapi.NodeType" do
37
+ value :PROVIDER, 0
38
+ value :SERVER, 1
39
+ value :GATEWAY, 2
40
+ end
41
+ add_enum "nodeapi.KeepAliveCommand" do
42
+ value :NONE, 0
43
+ value :RECONNECT, 1
44
+ value :SERVER_CHANGE, 2
45
+ end
46
+ end
47
+ end
48
+
49
+ module Nodeapi
50
+ NodeInfo = Google::Protobuf::DescriptorPool.generated_pool.lookup("nodeapi.NodeInfo").msgclass
51
+ NodeID = Google::Protobuf::DescriptorPool.generated_pool.lookup("nodeapi.NodeID").msgclass
52
+ NodeUpdate = Google::Protobuf::DescriptorPool.generated_pool.lookup("nodeapi.NodeUpdate").msgclass
53
+ Response = Google::Protobuf::DescriptorPool.generated_pool.lookup("nodeapi.Response").msgclass
54
+ NodeType = Google::Protobuf::DescriptorPool.generated_pool.lookup("nodeapi.NodeType").enummodule
55
+ KeepAliveCommand = Google::Protobuf::DescriptorPool.generated_pool.lookup("nodeapi.KeepAliveCommand").enummodule
56
+ end
@@ -0,0 +1,25 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: nodeapi.proto for package 'nodeapi'
3
+
4
+ require 'grpc'
5
+ require_relative 'nodeapi_pb'
6
+
7
+ module Nodeapi
8
+ module Node
9
+ class Service
10
+
11
+ include GRPC::GenericService
12
+
13
+ self.marshal_class_method = :encode
14
+ self.unmarshal_class_method = :decode
15
+ self.service_name = 'nodeapi.Node'
16
+
17
+ rpc :RegisterNode, NodeInfo, NodeID
18
+ rpc :QueryNode, NodeID, NodeInfo
19
+ rpc :KeepAlive, NodeUpdate, Response
20
+ rpc :UnRegisterNode, NodeID, Response
21
+ end
22
+
23
+ Stub = Service.rpc_stub_class
24
+ end
25
+ end
@@ -0,0 +1,106 @@
1
+ #
2
+ # Copyright 2019- Synerex Project (Nobuo Kawaguchi)
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ require 'grpc'
17
+ require 'fluent/plugin/output'
18
+ require_relative 'provider-util'
19
+ require_relative 'fluentd_pb'
20
+ require 'google/protobuf/well_known_types'
21
+
22
+
23
+ module Fluent
24
+ module Plugin
25
+ class SynerexOutput < Fluent::Plugin::Output
26
+ Fluent::Plugin.register_output("synerex", self)
27
+
28
+ desc "Synerex NodeServer address"
29
+ config_param :server, :string, default: "127.0.0.1"
30
+ desc "Synerex NodeServer port"
31
+ config_param :port, :string, default: "9990"
32
+
33
+ config_section :buffer do
34
+ config_set_default :chunk_keys, ['tag']
35
+ config_set_default :flush_at_shutdown, true
36
+ config_set_default :chunk_limit_size, 10*1024
37
+ end
38
+
39
+ # def prefer_buffered_processing
40
+ # false
41
+ # end
42
+
43
+ def multi_workers_ready?
44
+ true
45
+ end
46
+
47
+ def configure(conf)
48
+ GRPC.logger.info("Configure start ")
49
+ super
50
+
51
+ # @lfile = File.open('/tmp/synerex_out.txt',"w+")
52
+
53
+ end
54
+
55
+
56
+ # called befor start
57
+ def start
58
+ super
59
+ nodeserv = @server+":"+@port
60
+ # @lfile.puts("NodeServer:"+nodeserv)
61
+ registerServ(nodeserv,"Fluentd-Provider")
62
+ end
63
+
64
+ # called befor stop
65
+ def shutdown
66
+ super
67
+ end
68
+
69
+ attr_accessor :formatter
70
+
71
+ def process(tag, es)
72
+ # @lfile.puts ( "from process:"+tag.class.to_s+":"+tag.to_s)
73
+ es.each do |time, record|
74
+ process_record(tag, time, record)
75
+ end
76
+ end
77
+
78
+ def write(chunk)
79
+ # @lfile.puts("from chunk["+chunk.metadata.class.to_s+"]"+chunk.metadata.to_s)
80
+ tag = chunk.metadata.tag
81
+ chunk.each do |time, record|
82
+ process_record(tag, time, record)
83
+ end
84
+ end
85
+
86
+ def process_record(tag, time, record)
87
+ response = send_message(tag, time, record)
88
+ end
89
+
90
+ def send_message(tag, time, record)
91
+ # @lfile.puts ( "tag :"+tag.class.to_s+":"+tag.to_s)
92
+ # @lfile.puts ("time :"+time.class.to_s+":"+time.to_s)
93
+ # @lfile.puts ("record:"+record.class.to_s+":"+record.to_s)
94
+
95
+ ts = Google::Protobuf::Timestamp.new(seconds: time)
96
+
97
+ rec = Proto::Fluentd::FluentdRecord.new(tag: tag.to_s, time:ts, record: record.to_s)
98
+ code = Proto::Fluentd::FluentdRecord.encode(rec)
99
+
100
+ do_notifySupply("Fluentd","tag",code)
101
+ return nil
102
+ end
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,147 @@
1
+
2
+ require 'grpc'
3
+ require_relative 'synerex_services_pb'
4
+ require_relative 'nodeapi_services_pb'
5
+ require 'optparse'
6
+ require 'logger'
7
+ require 'anyflake'
8
+ require 'google/protobuf/well_known_types'
9
+
10
+ include GRPC::Core::TimeConsts
11
+
12
+ # Globals Variables
13
+
14
+ $sxstub = nil
15
+ $nodeInfo = nil
16
+ $nodestub = nil
17
+ $threads = []
18
+ $updateCount = 0
19
+ $status = ""
20
+ $clientID = 0
21
+ $idgen = nil
22
+
23
+
24
+ module StdoutLogger
25
+ def logger
26
+ LOGGER
27
+ end
28
+
29
+ LOGGER = Logger.new(STDOUT)
30
+ end
31
+
32
+ GRPC.extend(StdoutLogger)
33
+
34
+ def do_notifyDemand(name,arg,msg)
35
+
36
+ ts = Google::Protobuf::Timestamp.new
37
+ p ts
38
+ ts.from_time(Time.now)
39
+ cdata = Api::Content.new(entity: msg)
40
+
41
+ req = Api::Demand.new(id: generateIntID(),
42
+ sender_id: $clientID,
43
+ target_id: 0,
44
+ channel_type: 7,
45
+ demand_name: name,
46
+ ts: ts,
47
+ arg_json: arg,
48
+ mbus_id: 0,
49
+ cdata: cdata)
50
+
51
+ # GRPC.logger.info("NotifyDemand Call #{req.inspect}")
52
+ resp = $sxstub.notify_demand(req)
53
+ GRPC.logger.info("NotifyDemand Response #{resp.inspect}")
54
+
55
+ end
56
+
57
+ def do_notifySupply(name,arg,msg)
58
+
59
+ ts = Google::Protobuf::Timestamp.new
60
+
61
+ # $log.puts("Do notify Supply:"+ts.to_s+":"+$clientID.to_s)
62
+
63
+ ts.from_time(Time.now)
64
+ cdata = Api::Content.new(entity: msg)
65
+
66
+ req = Api::Supply.new(id: generateIntID(),
67
+ sender_id: $clientID,
68
+ target_id: 0,
69
+ channel_type: 7, # for fluentd
70
+ supply_name: name,
71
+ ts: ts,
72
+ arg_json: arg,
73
+ mbus_id: 0,
74
+ cdata: cdata)
75
+
76
+ # GRPC.logger.info("NotifySupply Call #{req.inspect}")
77
+ resp = $sxstub.notify_supply(req)
78
+ GRPC.logger.info("NotifySupply Response #{resp.inspect}")
79
+
80
+ end
81
+
82
+
83
+ def keepAlive()
84
+ while $nodeInfo['secret'] != 0 do
85
+ sleep( $nodeInfo['keepalive_duration'])
86
+ $updateCount += 1
87
+ req = Nodeapi::NodeUpdate.new(node_id: $nodeInfo['node_id'],
88
+ secret: $nodeInfo['secret'],
89
+ update_count: $updateCount,
90
+ node_status: 0,
91
+ node_arg: $status)
92
+ resp = $nodestub.keep_alive(req)
93
+ GRPC.logger.info("Response for #{$nodeInfo['node_id']}, #{resp.inspect}")
94
+
95
+ end
96
+ end
97
+
98
+
99
+
100
+ def startKeepAlive()
101
+ $threads << Thread.new { keepAlive() }
102
+ end
103
+
104
+
105
+
106
+ def do_registerNode(stub,name)
107
+ GRPC.logger.info("Register Node")
108
+ req = Nodeapi::NodeInfo.new(node_name: name,
109
+ node_type: Nodeapi::NodeType::PROVIDER,
110
+ server_info: "",
111
+ node_pbase_version: "0.1.2",
112
+ with_node_id: -1,
113
+ cluster_id: 0,
114
+ area_id: "Default",
115
+ channelTypes: [7]) #fluentd
116
+ resp = stub.register_node(req)
117
+ GRPC.logger.info("RN:Answer: #{resp.inspect}")
118
+
119
+ return resp
120
+ end
121
+
122
+ def generateIntID()
123
+ return $idgen.next_id
124
+ end
125
+
126
+ def registerServ(nodesv,name)
127
+ # connect to nodeserv
128
+ $nodestub = Nodeapi::Node::Stub.new(nodesv, :this_channel_is_insecure, timeout: INFINITE_FUTURE)
129
+ GRPC.logger.info(".. connecting insecurely on nodeserv #{nodesv}")
130
+ $nodeInfo = do_registerNode($nodestub,name) # got server info
131
+
132
+ service_epoch = Time.new(2010, 11, 4, 1, 42, 54).strftime('%s%L').to_i
133
+ # may Twitter epoch of snowflake,
134
+ # 1288834974657
135
+
136
+ $idgen = AnyFlake.new(service_epoch, $nodeInfo.node_id)
137
+ $clientID = generateIntID()
138
+
139
+ GRPC.logger.info(".. connecting insecurely on synerex server to #{$nodeInfo['server_info']}")
140
+ $sxstub = Api::Synerex::Stub.new($nodeInfo.server_info, :this_channel_is_insecure, timeout: INFINITE_FUTURE)
141
+
142
+ startKeepAlive
143
+ end
144
+
145
+
146
+
147
+
@@ -0,0 +1,117 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: synerex.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'google/protobuf/timestamp_pb'
7
+ require 'google/protobuf/duration_pb'
8
+ Google::Protobuf::DescriptorPool.generated_pool.build do
9
+ add_file("synerex.proto", :syntax => :proto3) do
10
+ add_message "api.Response" do
11
+ optional :ok, :bool, 1
12
+ optional :err, :string, 2
13
+ end
14
+ add_message "api.ConfirmResponse" do
15
+ optional :ok, :bool, 1
16
+ optional :mbus_id, :fixed64, 2
17
+ optional :wait, :message, 3, "google.protobuf.Duration"
18
+ optional :err, :string, 4
19
+ end
20
+ add_message "api.Content" do
21
+ optional :entity, :bytes, 1
22
+ end
23
+ add_message "api.Supply" do
24
+ optional :id, :fixed64, 1
25
+ optional :sender_id, :fixed64, 2
26
+ optional :target_id, :fixed64, 3
27
+ optional :channel_type, :uint32, 4
28
+ optional :supply_name, :string, 5
29
+ optional :ts, :message, 6, "google.protobuf.Timestamp"
30
+ optional :arg_json, :string, 7
31
+ optional :mbus_id, :fixed64, 8
32
+ optional :cdata, :message, 9, "api.Content"
33
+ end
34
+ add_message "api.Demand" do
35
+ optional :id, :fixed64, 1
36
+ optional :sender_id, :fixed64, 2
37
+ optional :target_id, :fixed64, 3
38
+ optional :channel_type, :uint32, 4
39
+ optional :demand_name, :string, 5
40
+ optional :ts, :message, 6, "google.protobuf.Timestamp"
41
+ optional :arg_json, :string, 7
42
+ optional :mbus_id, :fixed64, 8
43
+ optional :cdata, :message, 9, "api.Content"
44
+ end
45
+ add_message "api.Target" do
46
+ optional :id, :fixed64, 1
47
+ optional :sender_id, :fixed64, 2
48
+ optional :target_id, :fixed64, 3
49
+ optional :channel_type, :uint32, 4
50
+ optional :wait, :message, 5, "google.protobuf.Duration"
51
+ optional :mbus_id, :fixed64, 6
52
+ end
53
+ add_message "api.Channel" do
54
+ optional :client_id, :fixed64, 1
55
+ optional :channel_type, :uint32, 2
56
+ optional :arg_json, :string, 3
57
+ end
58
+ add_message "api.Mbus" do
59
+ optional :client_id, :fixed64, 1
60
+ optional :mbus_id, :fixed64, 2
61
+ optional :arg_json, :string, 3
62
+ end
63
+ add_message "api.MbusMsg" do
64
+ optional :msg_id, :fixed64, 1
65
+ optional :sender_id, :fixed64, 2
66
+ optional :target_id, :fixed64, 3
67
+ optional :mbus_id, :fixed64, 4
68
+ optional :msg_type, :uint32, 5
69
+ optional :msg_info, :string, 6
70
+ optional :arg_json, :string, 7
71
+ end
72
+ add_message "api.GatewayInfo" do
73
+ optional :client_id, :fixed64, 1
74
+ optional :gateway_type, :enum, 2, "api.GatewayType"
75
+ repeated :channels, :uint32, 3
76
+ end
77
+ add_message "api.GatewayMsg" do
78
+ optional :src_synerex_id, :fixed64, 1
79
+ optional :msg_type, :enum, 2, "api.MsgType"
80
+ oneof :msg_oneof do
81
+ optional :demand, :message, 3, "api.Demand"
82
+ optional :supply, :message, 4, "api.Supply"
83
+ optional :target, :message, 5, "api.Target"
84
+ optional :mbus, :message, 6, "api.Mbus"
85
+ optional :mbus_msg, :message, 7, "api.MbusMsg"
86
+ end
87
+ end
88
+ add_enum "api.GatewayType" do
89
+ value :BIDIRECTIONAL, 0
90
+ value :WRITE_ONLY, 1
91
+ value :READ_ONLY, 2
92
+ end
93
+ add_enum "api.MsgType" do
94
+ value :DEMAND, 0
95
+ value :SUPPLY, 1
96
+ value :TARGET, 2
97
+ value :MBUS, 3
98
+ value :MBUSMSG, 4
99
+ end
100
+ end
101
+ end
102
+
103
+ module Api
104
+ Response = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.Response").msgclass
105
+ ConfirmResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.ConfirmResponse").msgclass
106
+ Content = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.Content").msgclass
107
+ Supply = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.Supply").msgclass
108
+ Demand = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.Demand").msgclass
109
+ Target = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.Target").msgclass
110
+ Channel = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.Channel").msgclass
111
+ Mbus = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.Mbus").msgclass
112
+ MbusMsg = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.MbusMsg").msgclass
113
+ GatewayInfo = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.GatewayInfo").msgclass
114
+ GatewayMsg = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.GatewayMsg").msgclass
115
+ GatewayType = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.GatewayType").enummodule
116
+ MsgType = Google::Protobuf::DescriptorPool.generated_pool.lookup("api.MsgType").enummodule
117
+ end
@@ -0,0 +1,35 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: synerex.proto for package 'api'
3
+
4
+ require 'grpc'
5
+ require_relative 'synerex_pb'
6
+
7
+ module Api
8
+ module Synerex
9
+ class Service
10
+
11
+ include GRPC::GenericService
12
+
13
+ self.marshal_class_method = :encode
14
+ self.unmarshal_class_method = :decode
15
+ self.service_name = 'api.Synerex'
16
+
17
+ rpc :NotifyDemand, Demand, Response
18
+ rpc :NotifySupply, Supply, Response
19
+ rpc :ProposeDemand, Demand, Response
20
+ rpc :ProposeSupply, Supply, Response
21
+ rpc :SelectSupply, Target, ConfirmResponse
22
+ rpc :SelectDemand, Target, ConfirmResponse
23
+ rpc :Confirm, Target, Response
24
+ rpc :SubscribeDemand, Channel, stream(Demand)
25
+ rpc :SubscribeSupply, Channel, stream(Supply)
26
+ rpc :SubscribeMbus, Mbus, stream(MbusMsg)
27
+ rpc :SendMsg, MbusMsg, Response
28
+ rpc :CloseMbus, Mbus, Response
29
+ rpc :SubscribeGateway, GatewayInfo, stream(GatewayMsg)
30
+ rpc :ForwardToGateway, GatewayMsg, Response
31
+ end
32
+
33
+ Stub = Service.rpc_stub_class
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
2
+ require "test-unit"
3
+ require "fluent/test"
4
+ require "fluent/test/driver/output"
5
+ require "fluent/test/helpers"
6
+
7
+ Test::Unit::TestCase.include(Fluent::Test::Helpers)
8
+ Test::Unit::TestCase.extend(Fluent::Test::Helpers)
@@ -0,0 +1,30 @@
1
+ require "helper"
2
+ require "fluent/plugin/out_synerex.rb"
3
+
4
+ class SynerexOutputTest < Test::Unit::TestCase
5
+ include Fluent::Test::Helpers
6
+
7
+
8
+ setup do
9
+ Fluent::Test.setup
10
+ end
11
+
12
+
13
+ private
14
+
15
+ def create_driver(conf)
16
+ Fluent::Test::Driver::Output.new(Fluent::Plugin::SynerexOutput).configure(conf)
17
+ end
18
+
19
+ sub_test_case 'path' do
20
+ test 'normal' do
21
+ d = create_driver('...')
22
+ time = Fluent::Engine.now
23
+ d.run(default_tag:'test') do
24
+ d.feed(time,{'target' => '200'})
25
+ end
26
+ events = d.events
27
+
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-synerex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nobuo Kawaguchi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-09 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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: Synerex output plugin for fluentd
76
+ email:
77
+ - rubygems@synerex.net
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".gitmodules"
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - LICENSE
87
+ - README.md
88
+ - Rakefile
89
+ - fluent-plugin-out-synerex.gemspec
90
+ - generate.sh
91
+ - lib/fluent/plugin/fluentd_pb.rb
92
+ - lib/fluent/plugin/nodeapi_pb.rb
93
+ - lib/fluent/plugin/nodeapi_services_pb.rb
94
+ - lib/fluent/plugin/out_synerex.rb
95
+ - lib/fluent/plugin/provider-util.rb
96
+ - lib/fluent/plugin/synerex_pb.rb
97
+ - lib/fluent/plugin/synerex_services_pb.rb
98
+ - test/helper.rb
99
+ - test/plugin/test_out_synerex.rb
100
+ homepage: http://github.com/synerex/fluent-plugin-out-synerex/
101
+ licenses:
102
+ - Apache-2.0
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.5.2.1
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Synerex output plugin for fluentd
124
+ test_files:
125
+ - test/helper.rb
126
+ - test/plugin/test_out_synerex.rb