fluent-plugin-bcdb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Dockerfile +28 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +51 -0
- data/LICENSE +204 -0
- data/README.md +78 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/dev/fluent.conf +37 -0
- data/docker-compose.yaml +38 -0
- data/fluent-plugin-bcdb.gemspec +48 -0
- data/lib/fluent/plugin/bcdb/version.rb +7 -0
- data/lib/fluent/plugin/out_bcdb.rb +459 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 98b39e5a8b2ac790a5e7bc53baa1381756ea0f76a65f88693aca421aecbcfeb3
|
4
|
+
data.tar.gz: ff504db40716d7f4a3486499620f2cf07ce3c36d16a3dac7e79adae8688b4377
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7dd58c903129d67e9d7d017a1a583217aef0faef99877b9b216b693e7d0069a39ad4d4e1afbb04c8dd559c3514d1d069b81d8144cd201b5b118c5306126d843
|
7
|
+
data.tar.gz: 11b7985b329d822face35e003aa30674cc8aeb43f2cff8646cea95c2f4885e9b8ee30e00c60ff7d19e8466b8072c8aaacc7192cc60ed1e48777ca25b5078fbe2
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Dockerfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Copyright ©2019. MODEX (Gibraltar) LIMITED
|
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
|
+
FROM fluent/fluentd
|
17
|
+
|
18
|
+
USER root
|
19
|
+
|
20
|
+
RUN apk add --no-cache --update --virtual .build-deps \
|
21
|
+
sudo build-base ruby-dev git bash
|
22
|
+
COPY ./ /fluent-plugin-bcdb/
|
23
|
+
RUN gem install bundler
|
24
|
+
WORKDIR /fluent-plugin-bcdb/
|
25
|
+
RUN bundle install
|
26
|
+
RUN bundle exec rake install
|
27
|
+
# cutomize following instruction as you wish
|
28
|
+
# USER root
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fluent-plugin-bcdb (0.1.0)
|
5
|
+
fluentd (>= 0.14.22, < 2)
|
6
|
+
yajl-ruby (~> 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
concurrent-ruby (1.1.5)
|
12
|
+
cool.io (1.5.4)
|
13
|
+
dig_rb (1.0.1)
|
14
|
+
fluentd (1.7.2)
|
15
|
+
cool.io (>= 1.4.5, < 2.0.0)
|
16
|
+
dig_rb (~> 1.0.0)
|
17
|
+
http_parser.rb (>= 0.5.1, < 0.7.0)
|
18
|
+
msgpack (>= 1.2.0, < 2.0.0)
|
19
|
+
serverengine (>= 2.0.4, < 3.0.0)
|
20
|
+
sigdump (~> 0.2.2)
|
21
|
+
strptime (>= 0.2.2, < 1.0.0)
|
22
|
+
tzinfo (~> 2.0)
|
23
|
+
tzinfo-data (~> 1.0)
|
24
|
+
yajl-ruby (~> 1.0)
|
25
|
+
http_parser.rb (0.6.0)
|
26
|
+
msgpack (1.3.1)
|
27
|
+
power_assert (1.1.5)
|
28
|
+
rake (10.5.0)
|
29
|
+
serverengine (2.1.1)
|
30
|
+
sigdump (~> 0.2.2)
|
31
|
+
sigdump (0.2.4)
|
32
|
+
strptime (0.2.3)
|
33
|
+
test-unit (3.3.3)
|
34
|
+
power_assert
|
35
|
+
tzinfo (2.0.0)
|
36
|
+
concurrent-ruby (~> 1.0)
|
37
|
+
tzinfo-data (1.2019.3)
|
38
|
+
tzinfo (>= 1.0.0)
|
39
|
+
yajl-ruby (1.4.1)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bundler (~> 2.0)
|
46
|
+
fluent-plugin-bcdb!
|
47
|
+
rake (~> 10.0)
|
48
|
+
test-unit (>= 3.1.0)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.0.2
|
data/LICENSE
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
Copyright [2019] [MODEX (Gibraltar) LIMITED]
|
193
|
+
|
194
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
195
|
+
you may not use this file except in compliance with the License.
|
196
|
+
You may obtain a copy of the License at
|
197
|
+
|
198
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
199
|
+
|
200
|
+
Unless required by applicable law or agreed to in writing, software
|
201
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
202
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
203
|
+
See the License for the specific language governing permissions and
|
204
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Fluentd Modex BCDB connector
|
2
|
+
|
3
|
+
fluentd-bcdb-connector enables immutable logs using [Modex BCDB](https://bcdb.modex.tech). Main features:
|
4
|
+
|
5
|
+
* Bulk insert of records
|
6
|
+
* Buffered insert of records
|
7
|
+
* Request compression
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
> **NOTE:** First see [here](https://bcdb.modex.tech/docs/#/install/install) the installation guide for Modex BCDB
|
12
|
+
---
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'fluent-plugin-bcdb'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install fluent-plugin-bcdb
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
## Configuration options
|
31
|
+
|
32
|
+
> **NOTE:** this is a configuration example using Modex BCDB [sandbox](https://bcdb.modex.tech)
|
33
|
+
|
34
|
+
<match>
|
35
|
+
@type bcdb
|
36
|
+
base_url https://bcdb.modex.tech/node-03/services/core/v1/api
|
37
|
+
auth_url https://bcdb.modex.tech/oauth/token
|
38
|
+
ssl_no_verify false # default: false
|
39
|
+
rate_limit_msec 100 # default: 0 = no rate limiting
|
40
|
+
raise_on_error true # default: true
|
41
|
+
recoverable_status_codes 403, 400, 503, 500 # default: 503
|
42
|
+
cacert_file /etc/ssl/endpoint1.cert # default: ''
|
43
|
+
client_cert_path /path/to/client_cert.crt # default: ''
|
44
|
+
private_key_path /path/to/private_key.key # default: ''
|
45
|
+
private_key_passphrase yourpassphrase # default: ''
|
46
|
+
username bcdb.admin@modex.tech # default: ''
|
47
|
+
password BCDBDemo2019! # default: '', secret: true
|
48
|
+
client_id 0x01 # BDCB client_id
|
49
|
+
client_secret 0x000001 # BDCB client_secret
|
50
|
+
buffered false # default: false. Switch non-buffered/buffered mode
|
51
|
+
bulk_request false # default: false. Send events as application/x-ndjson
|
52
|
+
compress_request false # default: false. Send compressed events
|
53
|
+
</match>
|
54
|
+
|
55
|
+
|
56
|
+
## Usage notes
|
57
|
+
|
58
|
+
If you want to retry failed requests, specify the appropriate `recoverable_status_codes` parameter.
|
59
|
+
|
60
|
+
To send events with bulk_request, you need to specify bulk_request as true. Note that when this parameter is true, Fluentd will always send events as application/x-ndjson. Currently, application/x-ndjson is the only supported MIME type for bulk_request.
|
61
|
+
|
62
|
+
## Development
|
63
|
+
|
64
|
+
After you checkout the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
65
|
+
|
66
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
[Bug reports](https://github.com/modex-bcdb/fluentd-bcdb-connector/issues) and [pull requests](https://github.com/modex-bcdb/fluentd-bcdb-connector/pulls) are welcomed on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
71
|
+
|
72
|
+
## License
|
73
|
+
|
74
|
+
The gem is available as open source under the terms of the [Apache License](https://opensource.org/licenses/Apache-2.0).
|
75
|
+
|
76
|
+
## Code of Conduct
|
77
|
+
|
78
|
+
Everyone interacting in the Fluent::Plugin::Bcdb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/modex-bcdb/fluentd-bcdb-connector/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fluent/plugin/bcdb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/dev/fluent.conf
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
<source>
|
2
|
+
@type http
|
3
|
+
@id input1
|
4
|
+
@label @mainstream
|
5
|
+
@log_level trace
|
6
|
+
port 24224
|
7
|
+
</source>
|
8
|
+
|
9
|
+
<system>
|
10
|
+
# equal to -qq option
|
11
|
+
log_level trace
|
12
|
+
</system>
|
13
|
+
|
14
|
+
<label @mainstream>
|
15
|
+
<match **>
|
16
|
+
@type bcdb
|
17
|
+
base_url "http://<ip>:<port>/services/core/v1/api" # Api endpoint like https://bcdb.modex.tech/node-03/services/core/v1/api
|
18
|
+
auth_url "http://<ip>:<port>/token" # OAuth token endpoint like https://bcdb.modex.tech/oauth/token
|
19
|
+
bcdb_entity "log" # default: logline
|
20
|
+
ssl_no_verify false # default: false
|
21
|
+
rate_limit_msec 100 # default: 0 = no rate limiting
|
22
|
+
raise_on_error true # default: true
|
23
|
+
recoverable_status_codes 5000, 400 # default: 503
|
24
|
+
cacert_file /etc/ssl/endpoint1.cert # default: ''
|
25
|
+
client_cert_path /path/to/client_cert.crt # default: ''
|
26
|
+
private_key_path /path/to/private_key.key # default: ''
|
27
|
+
private_key_passphrase yourpassphrase # default: ''
|
28
|
+
username <username> # ex. bcdb.admin@modex.tech default: ''
|
29
|
+
password <password> # ex. admin default: '', secret: true
|
30
|
+
client_id 0x01 # default: ''. BDCB client_id
|
31
|
+
client_secret 0x000001 # default: ''. BDCB client_secret
|
32
|
+
buffered true # default: false. Switch non-buffered/buffered mode
|
33
|
+
bulk_request true # default: false. Send events as application/x-ndjson
|
34
|
+
compress_request false # default: false. Send compressed events
|
35
|
+
@log_level trace
|
36
|
+
</match>
|
37
|
+
</label>
|
data/docker-compose.yaml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# Copyright ©2019. MODEX (Gibraltar) LIMITED
|
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
|
+
version: '2'
|
17
|
+
services:
|
18
|
+
web:
|
19
|
+
image: httpd
|
20
|
+
ports:
|
21
|
+
- "81:80"
|
22
|
+
links:
|
23
|
+
- fluentd
|
24
|
+
logging:
|
25
|
+
driver: "fluentd"
|
26
|
+
options:
|
27
|
+
fluentd-address: localhost:24224
|
28
|
+
tag: httpd.access
|
29
|
+
fluentd:
|
30
|
+
build: ./
|
31
|
+
volumes:
|
32
|
+
- ./dev/fluent.conf:/fluentd/etc/fluent.conf
|
33
|
+
- ./:/plugins
|
34
|
+
ports:
|
35
|
+
- "24224:24224"
|
36
|
+
- "24224:24224/udp"
|
37
|
+
tty: true
|
38
|
+
command: ["/usr/bin/ruby", "-Eascii-8bit:ascii-8bit", "/usr/bin/fluentd", "-c","/fluentd/etc/fluent.conf"]
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#
|
2
|
+
# Copyright ©2019. MODEX (Gibraltar) LIMITED
|
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
|
+
lib = File.expand_path("lib", __dir__)
|
17
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
18
|
+
require "fluent/plugin/bcdb/version"
|
19
|
+
|
20
|
+
Gem::Specification.new do |spec|
|
21
|
+
spec.name = "fluent-plugin-bcdb"
|
22
|
+
spec.version = Fluent::Plugin::Bcdb::VERSION
|
23
|
+
spec.authors = ["Silviu Panaite"]
|
24
|
+
spec.email = ["silviu@messbusters.org"]
|
25
|
+
|
26
|
+
spec.summary = %q{Fluent output plugin to Modex Blockchain Database}
|
27
|
+
spec.homepage = "https://github.com/messbusters/fluent-plugin-bcdb"
|
28
|
+
spec.license = "APACHE"
|
29
|
+
|
30
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
31
|
+
spec.metadata["source_code_uri"] = "https://github.com/messbusters/fluent-plugin-bcdb"
|
32
|
+
spec.metadata["changelog_uri"] = "https://github.com/messbusters/fluent-plugin-bcdb"
|
33
|
+
|
34
|
+
# Specify which files should be added to the gem when it is released.
|
35
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
36
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
37
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
38
|
+
end
|
39
|
+
spec.bindir = "exe"
|
40
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
41
|
+
spec.require_paths = ["lib"]
|
42
|
+
|
43
|
+
spec.add_dependency "yajl-ruby", "~> 1.0"
|
44
|
+
spec.add_dependency "fluentd", [">= 0.14.22", "< 2"]
|
45
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
46
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
47
|
+
spec.add_development_dependency "test-unit", ">= 3.1.0"
|
48
|
+
end
|
@@ -0,0 +1,459 @@
|
|
1
|
+
#
|
2
|
+
# Copyright ©2019. MODEX (Gibraltar) LIMITED
|
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 'net/http'
|
17
|
+
require 'uri'
|
18
|
+
require 'yajl'
|
19
|
+
require 'fluent/plugin/output'
|
20
|
+
require "fluent/plugin/bcdb/version"
|
21
|
+
require 'tempfile'
|
22
|
+
require 'openssl'
|
23
|
+
require 'zlib'
|
24
|
+
|
25
|
+
class BcdbOut < Fluent::Plugin::Output
|
26
|
+
Fluent::Plugin.register_output('bcdb', self)
|
27
|
+
|
28
|
+
class RecoverableResponse < StandardError; end
|
29
|
+
|
30
|
+
helpers :compat_parameters, :formatter
|
31
|
+
|
32
|
+
DEFAULT_BUFFER_TYPE = "memory"
|
33
|
+
DEFAULT_FORMATTER = "json"
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
39
|
+
# BCDB data endpoint
|
40
|
+
config_param :base_url, :string
|
41
|
+
|
42
|
+
# BCDB Auth endpoint
|
43
|
+
config_param :auth_url, :string
|
44
|
+
|
45
|
+
# BCDB database entity model name
|
46
|
+
config_param :bcdb_entity, :string, :default => 'loglines'
|
47
|
+
|
48
|
+
# Set Net::HTTP.verify_mode to `OpenSSL::SSL::VERIFY_NONE`
|
49
|
+
config_param :ssl_no_verify, :bool, :default => false
|
50
|
+
|
51
|
+
# HTTP method
|
52
|
+
config_param :http_method, :enum, list: [:get, :put, :post, :delete], :default => :post
|
53
|
+
|
54
|
+
# form | json | text | raw
|
55
|
+
config_param :serializer, :enum, list: [:json, :form, :text, :raw], :default => :json
|
56
|
+
|
57
|
+
# Simple rate limiting: ignore any records within `rate_limit_msec`
|
58
|
+
# since the last one.
|
59
|
+
config_param :rate_limit_msec, :integer, :default => 0
|
60
|
+
|
61
|
+
# Raise errors that were rescued during HTTP requests?
|
62
|
+
config_param :raise_on_error, :bool, :default => true
|
63
|
+
|
64
|
+
# Specify recoverable error codes
|
65
|
+
config_param :recoverable_status_codes, :array, value_type: :integer, default: [503]
|
66
|
+
|
67
|
+
# ca file to use for https request
|
68
|
+
config_param :cacert_file, :string, :default => ''
|
69
|
+
|
70
|
+
# specify client sertificate
|
71
|
+
config_param :client_cert_path, :string, :default => ''
|
72
|
+
|
73
|
+
# specify private key path
|
74
|
+
config_param :private_key_path, :string, :default => ''
|
75
|
+
|
76
|
+
# specify private key passphrase
|
77
|
+
config_param :private_key_passphrase, :string, :default => '', :secret => true
|
78
|
+
|
79
|
+
# custom headers
|
80
|
+
config_param :custom_headers, :hash, :default => nil
|
81
|
+
|
82
|
+
# 'none' | 'basic' | 'jwt' | 'bearer'
|
83
|
+
config_param :authentication, :enum, list: [:none, :basic, :jwt, :bearer, :oauth], :default => :oauth
|
84
|
+
config_param :username, :string, :default => ''
|
85
|
+
config_param :password, :string, :default => '', :secret => true
|
86
|
+
config_param :client_id, :string, :default => ''
|
87
|
+
config_param :client_secret, :string, :default => '', :secret => true
|
88
|
+
config_param :grant_type, :enum, list: [:password, :authorization_code], :default => :password
|
89
|
+
config_param :token, :string, :default => ''
|
90
|
+
# Switch non-buffered/buffered plugin
|
91
|
+
config_param :buffered, :bool, :default => false
|
92
|
+
config_param :bulk_request, :bool, :default => false
|
93
|
+
# Compress with gzip except for form serializer
|
94
|
+
config_param :compress_request, :bool, :default => false
|
95
|
+
|
96
|
+
config_section :buffer do
|
97
|
+
config_set_default :@type, DEFAULT_BUFFER_TYPE
|
98
|
+
config_set_default :chunk_keys, ['tag']
|
99
|
+
end
|
100
|
+
|
101
|
+
config_section :format do
|
102
|
+
config_set_default :@type, DEFAULT_FORMATTER
|
103
|
+
end
|
104
|
+
|
105
|
+
def configure(conf)
|
106
|
+
compat_parameters_convert(conf, :buffer, :formatter)
|
107
|
+
super
|
108
|
+
@create_schema_url = "#{@base_url}" + "/catalog/_JsonSchema/" + "#{@bcdb_entity}"
|
109
|
+
if @bulk_request
|
110
|
+
@base_url = "#{@base_url}" + "/data/bulk/" + "#{@bcdb_entity}"
|
111
|
+
else
|
112
|
+
@base_url = "#{@base_url}" + "/data/" + "#{@bcdb_entity}"
|
113
|
+
end
|
114
|
+
|
115
|
+
bcdb_authorise() if @authentication == :oauth
|
116
|
+
|
117
|
+
@ssl_verify_mode = if @ssl_no_verify
|
118
|
+
OpenSSL::SSL::VERIFY_NONE
|
119
|
+
else
|
120
|
+
OpenSSL::SSL::VERIFY_PEER
|
121
|
+
end
|
122
|
+
|
123
|
+
@ca_file = @cacert_file
|
124
|
+
@last_request_time = nil
|
125
|
+
raise Fluent::ConfigError, "'tag' in chunk_keys is required." if !@chunk_key_tag && @buffered
|
126
|
+
|
127
|
+
if @formatter_config = conf.elements('format').first
|
128
|
+
@formatter = formatter_create
|
129
|
+
end
|
130
|
+
|
131
|
+
if @bulk_request
|
132
|
+
class << self
|
133
|
+
alias_method :format, :bulk_request_format
|
134
|
+
end
|
135
|
+
@formatter = formatter_create(type: :json)
|
136
|
+
@serializer = :x_ndjson # secret settings for bulk_request
|
137
|
+
else
|
138
|
+
class << self
|
139
|
+
alias_method :format, :split_request_format
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def bcdb_authorise()
|
145
|
+
auth_uri = URI.parse(@auth_url)
|
146
|
+
auth_data = {
|
147
|
+
:username => @username,
|
148
|
+
:password => @password,
|
149
|
+
:client_id => @client_id,
|
150
|
+
:client_secret => @client_secret,
|
151
|
+
:grant_type => @grant_type
|
152
|
+
}
|
153
|
+
status = true
|
154
|
+
unless @token_oauth || (@expires_token && Time.now.utc > @expires_token)
|
155
|
+
https= Net::HTTP.new(auth_uri.host,auth_uri.port)
|
156
|
+
https.use_ssl = auth_uri.scheme == 'https'
|
157
|
+
|
158
|
+
request = Net::HTTP::Post.new(auth_uri.path)
|
159
|
+
request.set_form_data(auth_data)
|
160
|
+
request['Content-Type'] = "application/x-www-form-urlencoded"
|
161
|
+
resp = https.request(request)
|
162
|
+
log.debug("#{resp.body}")
|
163
|
+
bcdb_response = JSON.parse(resp.body)
|
164
|
+
if bcdb_response["code"] == 5000
|
165
|
+
status = false
|
166
|
+
log.error("Authentification failed please check your credentials")
|
167
|
+
else
|
168
|
+
@token_oauth = bcdb_response['access_token']
|
169
|
+
@expires_token = Time.now.utc + bcdb_response['expires_in'].to_i
|
170
|
+
end
|
171
|
+
end
|
172
|
+
return status
|
173
|
+
end
|
174
|
+
|
175
|
+
def bcdb_update_schema(data, cached_keys=false)
|
176
|
+
schema_uri = URI.parse(@create_schema_url)
|
177
|
+
schema_properties = {}
|
178
|
+
data.each do |key|
|
179
|
+
log.debug("KEY #{key.inspect}")
|
180
|
+
schema_properties["#{key}"] = {
|
181
|
+
:"$id" => "/properties/#{schema_properties["#{key}"]}",
|
182
|
+
:type => "string",
|
183
|
+
:title => "The #{schema_properties["#{key}"]} Schema"
|
184
|
+
}
|
185
|
+
end
|
186
|
+
schema_data = {
|
187
|
+
:type => "object",
|
188
|
+
:"$id" => @bcdb_entity,
|
189
|
+
:"$schema" => "http://json-schema.org/draft-07/schema#",
|
190
|
+
:title => "The Root Schema",
|
191
|
+
:properties => schema_properties,
|
192
|
+
:autoId => true
|
193
|
+
}
|
194
|
+
body = JSON(schema_data)
|
195
|
+
|
196
|
+
if cached_keys
|
197
|
+
request = bcdb_url(schema_uri,'put', body)
|
198
|
+
else
|
199
|
+
request = bcdb_url(schema_uri,'post',body)
|
200
|
+
if JSON.parse(request.body)["code"] == 4009
|
201
|
+
request = bcdb_url(schema_uri,'put', body)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
log.debug("UPDATE SCHEMA: #{body}")
|
205
|
+
|
206
|
+
log.debug("UPDATE SCHEMA RESPONSE: #{request.body}")
|
207
|
+
return data, true
|
208
|
+
end
|
209
|
+
def bcdb_url(uri,type,body)
|
210
|
+
bcdb_request = Net::HTTP.new(uri.host,uri.port)
|
211
|
+
bcdb_request.use_ssl = uri.scheme == 'https'
|
212
|
+
case type
|
213
|
+
when 'post'
|
214
|
+
request = Net::HTTP::Post.new(uri.path)
|
215
|
+
when 'put'
|
216
|
+
request = Net::HTTP::Put.new(uri.path)
|
217
|
+
end
|
218
|
+
request.body = body
|
219
|
+
request['Content-Type'] = "application/json"
|
220
|
+
request['authorization'] = "Bearer #{@token_oauth}"
|
221
|
+
response = bcdb_request.request(request)
|
222
|
+
return response
|
223
|
+
end
|
224
|
+
|
225
|
+
def start
|
226
|
+
super
|
227
|
+
end
|
228
|
+
|
229
|
+
def shutdown
|
230
|
+
super
|
231
|
+
end
|
232
|
+
|
233
|
+
def format_url(tag, time, record)
|
234
|
+
@base_url
|
235
|
+
end
|
236
|
+
|
237
|
+
def set_body(req, tag, time, record)
|
238
|
+
if @serializer == :json
|
239
|
+
set_json_body(req, record)
|
240
|
+
elsif @serializer == :text
|
241
|
+
set_text_body(req, record)
|
242
|
+
elsif @serializer == :raw
|
243
|
+
set_raw_body(req, record)
|
244
|
+
elsif @serializer == :x_ndjson
|
245
|
+
set_bulk_body(req, record)
|
246
|
+
else
|
247
|
+
req.set_form_data(record)
|
248
|
+
end
|
249
|
+
req
|
250
|
+
end
|
251
|
+
|
252
|
+
def set_header(req, tag, time, record)
|
253
|
+
if @custom_headers
|
254
|
+
@custom_headers.each do |k,v|
|
255
|
+
req[k] = v
|
256
|
+
end
|
257
|
+
req
|
258
|
+
else
|
259
|
+
req
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def compress_body(req, data)
|
264
|
+
return unless @compress_request
|
265
|
+
gz = Zlib::GzipWriter.new(StringIO.new)
|
266
|
+
gz << data
|
267
|
+
|
268
|
+
req['Content-Encoding'] = "gzip"
|
269
|
+
req.body = gz.close.string
|
270
|
+
end
|
271
|
+
|
272
|
+
def set_json_body(req, data)
|
273
|
+
bcdb_authorise()
|
274
|
+
unless @cached_keys && @keys.sort == data.keys.sort
|
275
|
+
@keys, @cached_keys = bcdb_update_schema(data.keys, @cached_keys)
|
276
|
+
end
|
277
|
+
# data = { :records => [data] } if @bulk_request
|
278
|
+
req.body = Yajl.dump(data)
|
279
|
+
req['Content-Type'] = "application/json"
|
280
|
+
compress_body(req, req.body)
|
281
|
+
end
|
282
|
+
|
283
|
+
def set_text_body(req, data)
|
284
|
+
req.body = data["message"]
|
285
|
+
req['Content-Type'] = 'text/plain'
|
286
|
+
compress_body(req, req.body)
|
287
|
+
end
|
288
|
+
|
289
|
+
def set_raw_body(req, data)
|
290
|
+
req.body = data.to_s
|
291
|
+
req['Content-Type'] = 'application/octet-stream'
|
292
|
+
compress_body(req, req.body)
|
293
|
+
end
|
294
|
+
|
295
|
+
def set_bulk_body(req, data)
|
296
|
+
bcdb_authorise()
|
297
|
+
if data.is_a? String
|
298
|
+
flat_keys = []
|
299
|
+
bcdb_data = data.split("\n").map{ |x| JSON.parse(x) }
|
300
|
+
bcdb_data.each do |data|
|
301
|
+
flat_keys = flat_keys + data.keys
|
302
|
+
end
|
303
|
+
flat_keys.uniq!
|
304
|
+
unless @cached_keys && @keys.sort == flat_keys.sort
|
305
|
+
@keys, @cached_keys = bcdb_update_schema(flat_keys, @cached_keys)
|
306
|
+
end
|
307
|
+
data = { :records => bcdb_data }
|
308
|
+
@base_url = "#{@base_url_}" + "/data/bulk/" + "#{@bcdb_entity}"
|
309
|
+
else
|
310
|
+
log.debug("DATA: #{data.inspect}")
|
311
|
+
unless @cached_keys && @keys.sort == data.keys.sort
|
312
|
+
@keys, @cached_keys = bcdb_update_schema(data.keys, @cached_keys)
|
313
|
+
end
|
314
|
+
data = { :records => [data] }
|
315
|
+
end
|
316
|
+
req.body = Yajl.dump(data)
|
317
|
+
# req['Content-Type'] = 'application/x-ndjson'
|
318
|
+
req['Content-Type'] = 'application/json'
|
319
|
+
compress_body(req, req.body)
|
320
|
+
end
|
321
|
+
|
322
|
+
def create_request(tag, time, record)
|
323
|
+
url = format_url(tag, time, record)
|
324
|
+
uri = URI.parse(url)
|
325
|
+
req = Net::HTTP.const_get(@http_method.to_s.capitalize).new(uri.request_uri)
|
326
|
+
set_body(req, tag, time, record)
|
327
|
+
set_header(req, tag, time, record)
|
328
|
+
log.trace("CREATE REQUEST: #{req}, #{uri}")
|
329
|
+
return req, uri
|
330
|
+
end
|
331
|
+
|
332
|
+
def http_opts(uri)
|
333
|
+
opts = {
|
334
|
+
:use_ssl => uri.scheme == 'https'
|
335
|
+
}
|
336
|
+
opts[:verify_mode] = @ssl_verify_mode if opts[:use_ssl]
|
337
|
+
opts[:ca_file] = File.join(@ca_file) if File.file?(@ca_file)
|
338
|
+
opts[:cert] = OpenSSL::X509::Certificate.new(File.read(@client_cert_path)) if File.file?(@client_cert_path)
|
339
|
+
opts[:key] = OpenSSL::PKey.read(File.read(@private_key_path), @private_key_passphrase) if File.file?(@private_key_path)
|
340
|
+
opts
|
341
|
+
end
|
342
|
+
|
343
|
+
def proxies
|
344
|
+
ENV['HTTPS_PROXY'] || ENV['HTTP_PROXY'] || ENV['http_proxy'] || ENV['https_proxy']
|
345
|
+
end
|
346
|
+
|
347
|
+
def send_request(req, uri)
|
348
|
+
is_rate_limited = (@rate_limit_msec != 0 and not @last_request_time.nil?)
|
349
|
+
if is_rate_limited and ((Time.now.to_f - @last_request_time) * 1000.0 < @rate_limit_msec)
|
350
|
+
log.info('Dropped request due to rate limiting')
|
351
|
+
return
|
352
|
+
end
|
353
|
+
|
354
|
+
res = nil
|
355
|
+
|
356
|
+
begin
|
357
|
+
if @authentication == :basic
|
358
|
+
req.basic_auth(@username, @password)
|
359
|
+
elsif @authentication == :bearer
|
360
|
+
req['authorization'] = "bearer #{@token}"
|
361
|
+
elsif @authentication == :jwt
|
362
|
+
req['authorization'] = "jwt #{@token}"
|
363
|
+
elsif @authentication == :oauth
|
364
|
+
req['authorization'] = "Bearer #{@token_oauth}"
|
365
|
+
end
|
366
|
+
@last_request_time = Time.now.to_f
|
367
|
+
|
368
|
+
if proxy = proxies
|
369
|
+
proxy_uri = URI.parse(proxy)
|
370
|
+
|
371
|
+
res = Net::HTTP.start(uri.host, uri.port,
|
372
|
+
proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password,
|
373
|
+
**http_opts(uri)) {|http| http.request(req) }
|
374
|
+
else
|
375
|
+
res = Net::HTTP.start(uri.host, uri.port, **http_opts(uri)) {|http| http.request(req) }
|
376
|
+
log.debug("REQUEST BODY: #{req.body}")
|
377
|
+
log.debug("RESPONSE BODY: #{res.body}")
|
378
|
+
end
|
379
|
+
rescue => e # rescue all StandardErrors
|
380
|
+
# server didn't respond
|
381
|
+
log.warn "Net::HTTP.#{req.method.capitalize} raises exception: #{e.class}, '#{e.message}'"
|
382
|
+
raise e if @raise_on_error
|
383
|
+
else
|
384
|
+
unless res and res.is_a?(Net::HTTPSuccess)
|
385
|
+
res_summary = if res
|
386
|
+
"#{res.code} #{res.message} #{res.body}"
|
387
|
+
else
|
388
|
+
"res=nil"
|
389
|
+
end
|
390
|
+
if @recoverable_status_codes.include?(res.code.to_i)
|
391
|
+
raise RecoverableResponse, res_summary
|
392
|
+
else
|
393
|
+
log.warn "failed to #{req.method} #{uri} (#{res_summary})"
|
394
|
+
end
|
395
|
+
end #end unless
|
396
|
+
end # end begin
|
397
|
+
end # end send_request
|
398
|
+
|
399
|
+
def handle_record(tag, time, record)
|
400
|
+
if @formatter_config
|
401
|
+
record = @formatter.format(tag, time, record)
|
402
|
+
end
|
403
|
+
req, uri = create_request(tag, time, record)
|
404
|
+
send_request(req, uri)
|
405
|
+
end
|
406
|
+
|
407
|
+
def handle_records(tag, time, chunk)
|
408
|
+
req, uri = create_request(tag, time, chunk.read)
|
409
|
+
send_request(req, uri)
|
410
|
+
end
|
411
|
+
|
412
|
+
def prefer_buffered_processing
|
413
|
+
@buffered
|
414
|
+
end
|
415
|
+
|
416
|
+
def format(tag, time, record)
|
417
|
+
# For safety.
|
418
|
+
end
|
419
|
+
|
420
|
+
def split_request_format(tag, time, record)
|
421
|
+
[time, record].to_msgpack
|
422
|
+
end
|
423
|
+
|
424
|
+
def bulk_request_format(tag, time, record)
|
425
|
+
@formatter.format(tag, time, record)
|
426
|
+
end
|
427
|
+
|
428
|
+
def formatted_to_msgpack_binary?
|
429
|
+
if @bulk_request
|
430
|
+
false
|
431
|
+
else
|
432
|
+
true
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
def multi_workers_ready?
|
437
|
+
true
|
438
|
+
end
|
439
|
+
|
440
|
+
def process(tag, es)
|
441
|
+
log.trace("TRACE PROCESS: #{tag}, #{es}")
|
442
|
+
es.each do |time, record|
|
443
|
+
handle_record(tag, time, record)
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
def write(chunk)
|
448
|
+
tag = chunk.metadata.tag
|
449
|
+
@base_url = extract_placeholders(@base_url, chunk)
|
450
|
+
if @bulk_request
|
451
|
+
time = Fluent::Engine.now
|
452
|
+
handle_records(tag, time, chunk)
|
453
|
+
else
|
454
|
+
chunk.msgpack_each do |time, record|
|
455
|
+
handle_record(tag, time, record)
|
456
|
+
end
|
457
|
+
end
|
458
|
+
end
|
459
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-bcdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Silviu Panaite
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yajl-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fluentd
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.14.22
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '2'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.14.22
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: test-unit
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 3.1.0
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 3.1.0
|
89
|
+
description:
|
90
|
+
email:
|
91
|
+
- silviu@messbusters.org
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- CODE_OF_CONDUCT.md
|
98
|
+
- Dockerfile
|
99
|
+
- Gemfile
|
100
|
+
- Gemfile.lock
|
101
|
+
- LICENSE
|
102
|
+
- README.md
|
103
|
+
- Rakefile
|
104
|
+
- bin/console
|
105
|
+
- bin/setup
|
106
|
+
- dev/fluent.conf
|
107
|
+
- docker-compose.yaml
|
108
|
+
- fluent-plugin-bcdb.gemspec
|
109
|
+
- lib/fluent/plugin/bcdb/version.rb
|
110
|
+
- lib/fluent/plugin/out_bcdb.rb
|
111
|
+
homepage: https://github.com/messbusters/fluent-plugin-bcdb
|
112
|
+
licenses:
|
113
|
+
- APACHE
|
114
|
+
metadata:
|
115
|
+
homepage_uri: https://github.com/messbusters/fluent-plugin-bcdb
|
116
|
+
source_code_uri: https://github.com/messbusters/fluent-plugin-bcdb
|
117
|
+
changelog_uri: https://github.com/messbusters/fluent-plugin-bcdb
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.7.6.2
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Fluent output plugin to Modex Blockchain Database
|
138
|
+
test_files: []
|