fluent-plugin-vault-storage 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 +2 -0
- data/Gemfile +3 -0
- data/LICENSE.md +192 -0
- data/README.rdoc +118 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/fluent-plugin-vault-storage.gemspec +25 -0
- data/lib/fluent/plugin/out_swift.rb +188 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a93292ab3ac8fe880f29e4df8969ce24c5a0cebd
|
4
|
+
data.tar.gz: f29f4154b8e8b6549b436d49e73518fd5d13e86d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ec023f13f5594eb963ee68b462e5b67fc8fc8b1ffea1469ff4333bb05ebc7c8ffd9c916157a98b60e7857eacb81573acb738fdad30fa4abf5af9283a389e726
|
7
|
+
data.tar.gz: f42bb114e4f1e5be592e10e6d3930b7a76ee557f18dc20376e2556c473454fca74dd53fd463239fae8c267bff731a26e2f321d7a66e2aa28a442f17920878bd1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,192 @@
|
|
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, and
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
13
|
+
owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
21
|
+
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
23
|
+
permissions granted by this License.
|
24
|
+
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
27
|
+
files.
|
28
|
+
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
31
|
+
generated documentation, and conversions to other media types.
|
32
|
+
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
34
|
+
available under the License, as indicated by a copyright notice that is included
|
35
|
+
in or attached to the work (an example is provided in the Appendix below).
|
36
|
+
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
38
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
39
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
40
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
41
|
+
shall not include works that remain separable from, or merely link (or bind by
|
42
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
43
|
+
|
44
|
+
"Contribution" shall mean any work of authorship, including the original version
|
45
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
46
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
47
|
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
48
|
+
on behalf of the copyright owner. For the purposes of this definition,
|
49
|
+
"submitted" means any form of electronic, verbal, or written communication sent
|
50
|
+
to the Licensor or its representatives, including but not limited to
|
51
|
+
communication on electronic mailing lists, source code control systems, and
|
52
|
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
53
|
+
the purpose of discussing and improving the Work, but excluding communication
|
54
|
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
55
|
+
owner as "Not a Contribution."
|
56
|
+
|
57
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
58
|
+
of whom a Contribution has been received by Licensor and subsequently
|
59
|
+
incorporated within the Work.
|
60
|
+
|
61
|
+
2. Grant of Copyright License.
|
62
|
+
|
63
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
64
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
65
|
+
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
66
|
+
publicly display, publicly perform, sublicense, and distribute the Work and such
|
67
|
+
Derivative Works in Source or Object form.
|
68
|
+
|
69
|
+
3. Grant of Patent License.
|
70
|
+
|
71
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
72
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
73
|
+
irrevocable (except as stated in this section) patent license to make, have
|
74
|
+
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
75
|
+
such license applies only to those patent claims licensable by such Contributor
|
76
|
+
that are necessarily infringed by their Contribution(s) alone or by combination
|
77
|
+
of their Contribution(s) with the Work to which such Contribution(s) was
|
78
|
+
submitted. If You institute patent litigation against any entity (including a
|
79
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
80
|
+
Contribution incorporated within the Work constitutes direct or contributory
|
81
|
+
patent infringement, then any patent licenses granted to You under this License
|
82
|
+
for that Work shall terminate as of the date such litigation is filed.
|
83
|
+
|
84
|
+
4. Redistribution.
|
85
|
+
|
86
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
87
|
+
in any medium, with or without modifications, and in Source or Object form,
|
88
|
+
provided that You meet the following conditions:
|
89
|
+
|
90
|
+
You must give any other recipients of the Work or Derivative Works a copy of
|
91
|
+
this License; and
|
92
|
+
You must cause any modified files to carry prominent notices stating that You
|
93
|
+
changed the files; and
|
94
|
+
You must retain, in the Source form of any Derivative Works that You distribute,
|
95
|
+
all copyright, patent, trademark, and attribution notices from the Source form
|
96
|
+
of the Work, excluding those notices that do not pertain to any part of the
|
97
|
+
Derivative Works; and
|
98
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
99
|
+
Derivative Works that You distribute must include a readable copy of the
|
100
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
101
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
102
|
+
following places: within a NOTICE text file distributed as part of the
|
103
|
+
Derivative Works; within the Source form or documentation, if provided along
|
104
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
105
|
+
Works, if and wherever such third-party notices normally appear. The contents of
|
106
|
+
the NOTICE file are for informational purposes only and do not modify the
|
107
|
+
License. You may add Your own attribution notices within Derivative Works that
|
108
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
109
|
+
provided that such additional attribution notices cannot be construed as
|
110
|
+
modifying the License.
|
111
|
+
You may add Your own copyright statement to Your modifications and may provide
|
112
|
+
additional or different license terms and conditions for use, reproduction, or
|
113
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
114
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
115
|
+
with the conditions stated in this License.
|
116
|
+
|
117
|
+
5. Submission of Contributions.
|
118
|
+
|
119
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
120
|
+
for inclusion in the Work by You to the Licensor shall be under the terms and
|
121
|
+
conditions of this License, without any additional terms or conditions.
|
122
|
+
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
123
|
+
any separate license agreement you may have executed with Licensor regarding
|
124
|
+
such Contributions.
|
125
|
+
|
126
|
+
6. Trademarks.
|
127
|
+
|
128
|
+
This License does not grant permission to use the trade names, trademarks,
|
129
|
+
service marks, or product names of the Licensor, except as required for
|
130
|
+
reasonable and customary use in describing the origin of the Work and
|
131
|
+
reproducing the content of the NOTICE file.
|
132
|
+
|
133
|
+
7. Disclaimer of Warranty.
|
134
|
+
|
135
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the
|
136
|
+
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
137
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
138
|
+
including, without limitation, any warranties or conditions of TITLE,
|
139
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
140
|
+
solely responsible for determining the appropriateness of using or
|
141
|
+
redistributing the Work and assume any risks associated with Your exercise of
|
142
|
+
permissions under this License.
|
143
|
+
|
144
|
+
8. Limitation of Liability.
|
145
|
+
|
146
|
+
In no event and under no legal theory, whether in tort (including negligence),
|
147
|
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
148
|
+
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
149
|
+
liable to You for damages, including any direct, indirect, special, incidental,
|
150
|
+
or consequential damages of any character arising as a result of this License or
|
151
|
+
out of the use or inability to use the Work (including but not limited to
|
152
|
+
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
153
|
+
any and all other commercial damages or losses), even if such Contributor has
|
154
|
+
been advised of the possibility of such damages.
|
155
|
+
|
156
|
+
9. Accepting Warranty or Additional Liability.
|
157
|
+
|
158
|
+
While redistributing the Work or Derivative Works thereof, You may choose to
|
159
|
+
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
160
|
+
other liability obligations and/or rights consistent with this License. However,
|
161
|
+
in accepting such obligations, You may act only on Your own behalf and on Your
|
162
|
+
sole responsibility, not on behalf of any other Contributor, and only if You
|
163
|
+
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
164
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
165
|
+
accepting any such warranty or additional liability.
|
166
|
+
|
167
|
+
END OF TERMS AND CONDITIONS
|
168
|
+
|
169
|
+
APPENDIX: How to apply the Apache License to your work
|
170
|
+
|
171
|
+
To apply the Apache License to your work, attach the following boilerplate
|
172
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
173
|
+
identifying information. (Don't include the brackets!) The text should be
|
174
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
175
|
+
recommend that a file or class name and description of purpose be included on
|
176
|
+
the same "printed page" as the copyright notice for easier identification within
|
177
|
+
third-party archives.
|
178
|
+
|
179
|
+
Copyright [yyyy] [name of copyright owner]
|
180
|
+
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
182
|
+
you may not use this file except in compliance with the License.
|
183
|
+
You may obtain a copy of the License at
|
184
|
+
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
186
|
+
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
190
|
+
See the License for the specific language governing permissions and
|
191
|
+
limitations under the License.
|
192
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
= OpenStack Storage Service (swift) output plugin for Fluent event collector
|
2
|
+
|
3
|
+
== Overview
|
4
|
+
|
5
|
+
*swift* output plugin buffers event logs in local file and upload it to Swift periodically.
|
6
|
+
|
7
|
+
This plugin splits files exactly by using the time of event logs (not the time when the logs are received). For example, a log '2011-01-02 message B' is reached, and then another log '2011-01-03 message B' is reached in this order, the former one is stored in "20110102.gz" file, and latter one in "20110103.gz" file.
|
8
|
+
|
9
|
+
|
10
|
+
== Installation
|
11
|
+
|
12
|
+
Simply use RubyGems:
|
13
|
+
|
14
|
+
gem install fluent-plugin-swift
|
15
|
+
|
16
|
+
== Configuration
|
17
|
+
|
18
|
+
<match pattern>
|
19
|
+
type swift
|
20
|
+
|
21
|
+
auth_url https://your.swift.proxy/auth/v1.0 _or_ https://your.keystone/v2.0
|
22
|
+
auth_user test:tester
|
23
|
+
auth_api_key testing
|
24
|
+
auth_region RegionOne
|
25
|
+
swift_container CONTAINER_NAME
|
26
|
+
swift_object_key_format %{path}%{time_slice}_%{index}.%{file_extension}
|
27
|
+
ssl_verify false
|
28
|
+
|
29
|
+
path logs/
|
30
|
+
buffer_path /var/log/fluent/swift
|
31
|
+
|
32
|
+
time_slice_format %Y%m%d-%H
|
33
|
+
time_slice_wait 10m
|
34
|
+
utc
|
35
|
+
</match>
|
36
|
+
|
37
|
+
[auth_url] Authentication URL. Keystone Auth isn't tested yet.
|
38
|
+
|
39
|
+
[auth_user] Authentication User Name. if you use TempAuth, auth_user is ACCOUNT:USER .
|
40
|
+
|
41
|
+
[auth_tenant (optional, for keystone)] Authentication Tenant. if you use TempAuth, this isn't required.
|
42
|
+
|
43
|
+
[auth_api_key] Authentication Key (Password).
|
44
|
+
|
45
|
+
[auth_region] Authentication Region. Optional, not required if there is only one region available.
|
46
|
+
|
47
|
+
[swift_account (optional)] Account name. if this isn't provided, use default Account.
|
48
|
+
|
49
|
+
[swift_container] Container name.
|
50
|
+
|
51
|
+
[swift_object_key_format] The format of Swift object keys. You can use several built-in variables:
|
52
|
+
|
53
|
+
- %{path}
|
54
|
+
- %{time_slice}
|
55
|
+
- %{index}
|
56
|
+
- %{file_extension}
|
57
|
+
|
58
|
+
to decide keys dynamically.
|
59
|
+
|
60
|
+
%{path} is exactly the value of *path* configured in the configuration file. E.g., "logs/" in the example configuration above.
|
61
|
+
%{time_slice} is the time-slice in text that are formatted with *time_slice_format*.
|
62
|
+
%{index} is the sequential number starts from 0, increments when multiple files are uploaded to S3 in the same time slice.
|
63
|
+
%{file_extention} is always "gz" for now.
|
64
|
+
|
65
|
+
The default format is "%{path}%{time_slice}_%{index}.%{file_extension}".
|
66
|
+
|
67
|
+
For instance, using the example configuration above, actual object keys on Swift will be something like:
|
68
|
+
|
69
|
+
"logs/20130111-22_0.gz"
|
70
|
+
"logs/20130111-23_0.gz"
|
71
|
+
"logs/20130111-23_1.gz"
|
72
|
+
"logs/20130112-00_0.gz"
|
73
|
+
|
74
|
+
With the configuration:
|
75
|
+
|
76
|
+
swift_object_key_format %{path}/events/ts=%{time_slice}/events_%{index}.%{file_extension}
|
77
|
+
path log
|
78
|
+
time_slice_format %Y%m%d-%H
|
79
|
+
|
80
|
+
You get:
|
81
|
+
|
82
|
+
"log/events/ts=20130111-22/events_0.gz"
|
83
|
+
"log/events/ts=20130111-23/events_0.gz"
|
84
|
+
"log/events/ts=20130111-23/events_1.gz"
|
85
|
+
"log/events/ts=20130112-00/events_0.gz"
|
86
|
+
|
87
|
+
The {fluent-mixin-config-placeholders}[https://github.com/tagomoris/fluent-mixin-config-placeholders] mixin is also incorporated, so additional variables such as %{hostname}, %{uuid}, etc. can be used in the s3_object_key_format. This could prove useful in preventing filename conflicts when writing from multiple servers.
|
88
|
+
|
89
|
+
swift_object_key_format %{path}/events/ts=%{time_slice}/events_%{index}-%{hostname}.%{file_extension}
|
90
|
+
|
91
|
+
[store_as] archive format on Swift. You can use serveral format:
|
92
|
+
|
93
|
+
- gzip (default)
|
94
|
+
- json
|
95
|
+
- text
|
96
|
+
- lzo (Need lzop command)
|
97
|
+
|
98
|
+
[auto_create_container] Create Swift bucket if it does not exists. Default is true.
|
99
|
+
|
100
|
+
[path] path prefix of the files on Swift. Default is "" (no prefix).
|
101
|
+
|
102
|
+
[buffer_path (required)] path prefix of the files to buffer logs.
|
103
|
+
|
104
|
+
[time_slice_format] Format of the time used as the file name. Default is '%Y%m%d'. Use '%Y%m%d%H' to split files hourly.
|
105
|
+
|
106
|
+
[time_slice_wait] The time to wait old logs. Default is 10 minutes. Specify larger value if old logs may reache.
|
107
|
+
|
108
|
+
[utc] Use UTC instead of local time.
|
109
|
+
|
110
|
+
|
111
|
+
== Copyright
|
112
|
+
|
113
|
+
Copyright:: Copyright (c) 2013 Yuji Hagiwara.
|
114
|
+
|
115
|
+
This software is based on fluent-plugin-s3 ( https://github.com/fluent/fluent-plugin-s3 ), written by Sadayuki Furuhashi, licensed by Apache License, Version 2.0.
|
116
|
+
|
117
|
+
License:: Apache License, Version 2.0
|
118
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require 'bundler'
|
3
|
+
Bundler::GemHelper.install_tasks
|
4
|
+
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Rake::TestTask.new(:test) do |test|
|
8
|
+
test.libs << 'lib' << 'test'
|
9
|
+
test.test_files = FileList['test/*.rb']
|
10
|
+
test.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => [:build]
|
14
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = "fluent-plugin-vault-storage"
|
6
|
+
gem.description = "OpenStack Storage Service (Swift) output plugin for Fluentd event collector"
|
7
|
+
gem.homepage = "https://github.com/yuuzi41/fluent-plugin-swift"
|
8
|
+
gem.summary = gem.description
|
9
|
+
gem.version = File.read("VERSION").strip
|
10
|
+
gem.authors = ["yuuzi41"]
|
11
|
+
gem.email = ""
|
12
|
+
gem.has_rdoc = false
|
13
|
+
#gem.platform = Gem::Platform::RUBY
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
|
19
|
+
gem.add_dependency "fluentd", "~> 0.12.0"
|
20
|
+
gem.add_dependency "fog-openstack"
|
21
|
+
gem.add_dependency "yajl-ruby", "~> 1.0"
|
22
|
+
gem.add_dependency "fluent-mixin-config-placeholders", "~> 0.2.0"
|
23
|
+
gem.add_development_dependency "rake", ">= 0.9.2"
|
24
|
+
gem.add_development_dependency "flexmock", ">= 1.2.0"
|
25
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
module Fluent
|
2
|
+
|
3
|
+
require 'fluent/mixin/config_placeholders'
|
4
|
+
|
5
|
+
class SwiftOutput < Fluent::TimeSlicedOutput
|
6
|
+
Fluent::Plugin.register_output('swift', self)
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
require 'fog/openstack'
|
11
|
+
require 'zlib'
|
12
|
+
require 'time'
|
13
|
+
require 'tempfile'
|
14
|
+
require 'open3'
|
15
|
+
end
|
16
|
+
|
17
|
+
config_param :path, :string, :default => ""
|
18
|
+
config_param :time_format, :string, :default => nil
|
19
|
+
|
20
|
+
include SetTagKeyMixin
|
21
|
+
config_set_default :include_tag_key, false
|
22
|
+
|
23
|
+
include SetTimeKeyMixin
|
24
|
+
config_set_default :include_time_key, false
|
25
|
+
|
26
|
+
config_param :auth_url, :string
|
27
|
+
config_param :auth_user, :string
|
28
|
+
config_param :auth_tenant, :string, :default => nil
|
29
|
+
config_param :auth_api_key, :string
|
30
|
+
config_param :auth_region, :string, :default => nil
|
31
|
+
config_param :swift_account, :string, :default => nil
|
32
|
+
config_param :swift_container, :string
|
33
|
+
config_param :swift_object_key_format, :string, :default => "%{path}%{time_slice}_%{index}.%{file_extension}"
|
34
|
+
config_param :store_as, :string, :default => "gzip"
|
35
|
+
config_param :auto_create_container, :bool, :default => true
|
36
|
+
config_param :check_apikey_on_start, :bool, :default => true
|
37
|
+
config_param :proxy_uri, :string, :default => nil
|
38
|
+
config_param :ssl_verify, :bool, :default => true
|
39
|
+
|
40
|
+
# attr_reader :container
|
41
|
+
|
42
|
+
include Fluent::Mixin::ConfigPlaceholders
|
43
|
+
|
44
|
+
def placeholders
|
45
|
+
[:percent]
|
46
|
+
end
|
47
|
+
|
48
|
+
def configure(conf)
|
49
|
+
super
|
50
|
+
|
51
|
+
if format_json = conf['format_json']
|
52
|
+
@format_json = true
|
53
|
+
else
|
54
|
+
@format_json = false
|
55
|
+
end
|
56
|
+
|
57
|
+
@ext, @mime_type = case @store_as
|
58
|
+
when 'gzip' then ['gz', 'application/x-gzip']
|
59
|
+
when 'lzo' then
|
60
|
+
begin
|
61
|
+
Open3.capture3('lzop -V')
|
62
|
+
rescue Errno::ENOENT
|
63
|
+
raise ConfigError, "'lzop' utility must be in PATH for LZO compression"
|
64
|
+
end
|
65
|
+
['lzo', 'application/x-lzop']
|
66
|
+
when 'json' then ['json', 'application/json']
|
67
|
+
else ['txt', 'text/plain']
|
68
|
+
end
|
69
|
+
|
70
|
+
@timef = TimeFormatter.new(@time_format, @localtime)
|
71
|
+
|
72
|
+
if @localtime
|
73
|
+
@path_slicer = Proc.new {|path|
|
74
|
+
Time.now.strftime(path)
|
75
|
+
}
|
76
|
+
else
|
77
|
+
@path_slicer = Proc.new {|path|
|
78
|
+
Time.now.utc.strftime(path)
|
79
|
+
}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def start
|
84
|
+
super
|
85
|
+
|
86
|
+
Excon.defaults[:ssl_verify_peer] = @ssl_verify
|
87
|
+
|
88
|
+
@storage = Fog::Storage::OpenStack.new :openstack_auth_url => @auth_url,
|
89
|
+
:openstack_username => @auth_user,
|
90
|
+
:openstack_tenant => @auth_tenant,
|
91
|
+
:openstack_api_key => @auth_api_key,
|
92
|
+
:openstack_region => @auth_region
|
93
|
+
@storage.change_account @swift_account if @swift_account
|
94
|
+
|
95
|
+
check_container
|
96
|
+
end
|
97
|
+
|
98
|
+
def format(tag, time, record)
|
99
|
+
if @include_time_key || !@format_json
|
100
|
+
time_str = @timef.format(time)
|
101
|
+
end
|
102
|
+
|
103
|
+
# copied from each mixin because current TimeSlicedOutput can't support mixins.
|
104
|
+
if @include_tag_key
|
105
|
+
record[@tag_key] = tag
|
106
|
+
end
|
107
|
+
if @include_time_key
|
108
|
+
record[@time_key] = time_str
|
109
|
+
end
|
110
|
+
|
111
|
+
if @format_json
|
112
|
+
Yajl.dump(record) + "\n"
|
113
|
+
else
|
114
|
+
"#{time_str}\t#{tag}\t#{Yajl.dump(record)}\n"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def write(chunk)
|
119
|
+
i = 0
|
120
|
+
|
121
|
+
begin
|
122
|
+
path = @path_slicer.call(@path)
|
123
|
+
values_for_swift_object_key = {
|
124
|
+
"path" => path,
|
125
|
+
"time_slice" => chunk.key,
|
126
|
+
"file_extension" => @ext,
|
127
|
+
"index" => i
|
128
|
+
}
|
129
|
+
swift_path = @swift_object_key_format.gsub(%r(%{[^}]+})) { |expr|
|
130
|
+
values_for_swift_object_key[expr[2...expr.size-1]]
|
131
|
+
}
|
132
|
+
i += 1
|
133
|
+
end while check_object_exists(@swift_container, swift_path)
|
134
|
+
|
135
|
+
tmp = Tempfile.new("swift-")
|
136
|
+
begin
|
137
|
+
if @store_as == "gzip"
|
138
|
+
w = Zlib::GzipWriter.new(tmp)
|
139
|
+
chunk.write_to(w)
|
140
|
+
w.close
|
141
|
+
elsif @store_as == "lzo"
|
142
|
+
w = Tempfile.new("chunk-tmp")
|
143
|
+
chunk.write_to(w)
|
144
|
+
w.close
|
145
|
+
tmp.close
|
146
|
+
# We don't check the return code because we can't recover lzop failure.
|
147
|
+
system "lzop -qf1 -o #{tmp.path} #{w.path}"
|
148
|
+
else
|
149
|
+
chunk.write_to(tmp)
|
150
|
+
tmp.close
|
151
|
+
end
|
152
|
+
File.open(tmp.path) do |file|
|
153
|
+
@storage.put_object(@swift_container, swift_path, file, {:content_type => @mime_type})
|
154
|
+
end
|
155
|
+
$log.info "Put Log to Swift. container=#{@swift_container} object=#{swift_path}"
|
156
|
+
ensure
|
157
|
+
tmp.close(true) rescue nil
|
158
|
+
w.close rescue nil
|
159
|
+
w.unlink rescue nil
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
private
|
164
|
+
|
165
|
+
def check_container
|
166
|
+
begin
|
167
|
+
@storage.get_container(@swift_container)
|
168
|
+
rescue Fog::Storage::OpenStack::NotFound
|
169
|
+
if @auto_create_container
|
170
|
+
$log.info "Creating container #{@swift_container} on #{@auth_url}, #{@swift_account}"
|
171
|
+
@storage.put_container(@swift_container)
|
172
|
+
else
|
173
|
+
raise "The specified container does not exist: container = #{swift_container}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def check_object_exists(container, object)
|
179
|
+
begin
|
180
|
+
@storage.head_object(container, object)
|
181
|
+
rescue Fog::Storage::OpenStack::NotFound
|
182
|
+
return false
|
183
|
+
end
|
184
|
+
return true
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-vault-storage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yuuzi41
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.12.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.12.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fog-openstack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yajl-ruby
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fluent-mixin-config-placeholders
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: flexmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.2.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.2.0
|
97
|
+
description: OpenStack Storage Service (Swift) output plugin for Fluentd event collector
|
98
|
+
email: ''
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- ".gitignore"
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.md
|
106
|
+
- README.rdoc
|
107
|
+
- Rakefile
|
108
|
+
- VERSION
|
109
|
+
- fluent-plugin-vault-storage.gemspec
|
110
|
+
- lib/fluent/plugin/out_swift.rb
|
111
|
+
homepage: https://github.com/yuuzi41/fluent-plugin-swift
|
112
|
+
licenses: []
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.6.14
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: OpenStack Storage Service (Swift) output plugin for Fluentd event collector
|
134
|
+
test_files: []
|