fluent-plugin-oss 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 479e3eae96e9f6f94d41e0f9a4bd8ba126517f1b
4
+ data.tar.gz: 4cf891a7f1917911a4b280ab1d46dc1739519aa6
5
+ SHA512:
6
+ metadata.gz: b059f115c4236d68ef55d8105fd1044e915d62be5f8707aa16199a27f6d9cb1ca66b6f74966c255757f669b2f4d0aabfe5d8ac0cc35be2009217dbfb5be42474
7
+ data.tar.gz: d98ff286e683e6b5acc75a2e81b295fb318559c995f5699a03f30ccfdcd3d503a721185a65c736aa4f02e0a7257139844fb6657008f7d524a94433405e8baa52
@@ -0,0 +1,13 @@
1
+ ~*
2
+ #*
3
+ *~
4
+ [._]*.s[a-w][a-z]
5
+ .DS_Store
6
+
7
+ *.gem
8
+ .bundle
9
+ Gemfile.lock
10
+ vendor
11
+ .ruby-version
12
+
13
+ test/tmp/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,19 @@
1
+ # OSS plugin for [Fluentd](http://github.com/fluent/fluentd)
2
+
3
+ ## Output: Configuration
4
+
5
+ ```
6
+ <match **>
7
+ @type oss
8
+ oss_key_id xxx
9
+ oss_key_secret xxx
10
+ oss_bucket xxx
11
+ oss_endpoint xxx
12
+ oss_object_key_format "%{time_slice}/%{host}-%{uuid}.%{file_ext}"
13
+
14
+ buffer_path /var/log/fluent/myapp
15
+ time_slice_format %Y%m%d
16
+ time_slice_wait 10m
17
+ time_format %Y%m%dT%H%M%S%z
18
+ </match>
19
+ ```
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-oss"
6
+ gem.description = "Aliyun oss output plugin for Fluentd event collector"
7
+ gem.license = "MIT"
8
+ gem.homepage = "https://github.com/jicong/fluent-plugin-oss"
9
+ gem.summary = gem.description
10
+ gem.version = File.read("VERSION").strip
11
+ gem.authors = ["sjtubreeze"]
12
+ gem.email = "sjtubreeze@163.com"
13
+ gem.has_rdoc = false
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.3"]
20
+ gem.add_dependency "aliyun-sdk", [">= 0.6.0"]
21
+ gem.add_development_dependency "rake", ">= 0.9.2"
22
+ gem.add_development_dependency "test-unit", ">= 3.0.8"
23
+ end
@@ -0,0 +1,85 @@
1
+ require 'fluent/output'
2
+ require 'fluent/log'
3
+ require 'aliyun/oss'
4
+ require 'zlib'
5
+ require 'time'
6
+ require 'tempfile'
7
+ require 'securerandom'
8
+ require 'socket'
9
+
10
+ module Fluent
11
+ class OSSOutput < TimeSlicedOutput
12
+ Fluent::Plugin.register_output('oss', self)
13
+
14
+ desc "OSS access key id"
15
+ config_param :oss_key_id, :string
16
+ desc "OSS access key secret"
17
+ config_param :oss_key_secret, :string, secret: true
18
+ desc "OSS bucket name"
19
+ config_param :oss_bucket, :string
20
+ desc "OSS endpoint"
21
+ config_param :oss_endpoint, :string
22
+ desc "The format of OSS object keys"
23
+ config_param :oss_object_key_format, :string, default: "%{time_slice}/%{host}-%{uuid}.%{file_ext}"
24
+
25
+ def configure(conf)
26
+ super
27
+ end
28
+
29
+ def compress(chunk, tmp)
30
+ res = system "gzip -c #{chunk.path} > #{tmp.path}"
31
+ unless res
32
+ log.warn "failed to execute gzip command. Fallback to GzipWriter. status = #{$?}"
33
+ begin
34
+ tmp.truncate(0)
35
+ gw = Zlib::GzipWriter.new(tmp)
36
+ chunk.write_to(gw)
37
+ gw.close
38
+ ensure
39
+ gw.close rescue nil
40
+ end
41
+ end
42
+ end
43
+
44
+ def process_object_key_format(chunk, key_format)
45
+ key_map = {
46
+ host: Socket.gethostname,
47
+ time_slice: chunk.key,
48
+ uuid: SecureRandom.hex(4),
49
+ file_ext: 'gz'
50
+ }
51
+ result = key_format
52
+ key_map.each do |k, v|
53
+ result = result.gsub("%{#{k.to_s}}", v)
54
+ end
55
+ result
56
+ end
57
+
58
+ def start
59
+ super
60
+ @client = Aliyun::OSS::Client.new(
61
+ :endpoint => @oss_endpoint,
62
+ :access_key_id => @oss_key_id,
63
+ :access_key_secret => @oss_key_secret)
64
+
65
+ raise "Specific bucket not exists: #{@oss_bucket}" unless @client.bucket_exists? @oss_bucket
66
+
67
+ @bucket = @client.get_bucket(@oss_bucket)
68
+ end
69
+
70
+ def format(tag, time, record)
71
+ {tag: tag, timestamp: time, log: record}.to_json + "\n"
72
+ end
73
+
74
+ def write(chunk)
75
+ begin
76
+ f = Tempfile.new('oss-')
77
+ compress(chunk, f)
78
+ path = process_object_key_format(chunk, @oss_object_key_format)
79
+ raise "Upload #{f.path} failed" unless @bucket.resumable_upload(path, f.path)
80
+ ensure
81
+ f.close(true)
82
+ end
83
+ end
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-oss
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - sjtubreeze
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-31 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.3
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.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: aliyun-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.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.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.8
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.8
69
+ description: Aliyun oss output plugin for Fluentd event collector
70
+ email: sjtubreeze@163.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - Gemfile
77
+ - README.md
78
+ - VERSION
79
+ - fluent-plugin-oss.gemspec
80
+ - lib/fluent/plugin/out_oss.rb
81
+ homepage: https://github.com/jicong/fluent-plugin-oss
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.5.2
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Aliyun oss output plugin for Fluentd event collector
105
+ test_files: []