fluent-plugin-docker-format_nebo15 0.2.5

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e8ddd42a9c4506783ec1d95b72c062005e4380b2
4
+ data.tar.gz: 4bb8890a08d16a05eda82e82ed5619e9fb1e0c69
5
+ SHA512:
6
+ metadata.gz: 8248e842cb289213ed713254ab35c8a928c24c44765cdfdbfba06b8d337720d307f86359b81712d05ae903e8769faba43b5f8f5f3607f19a87805667af963a99
7
+ data.tar.gz: fab1641479fe65a9f969465dcf5c95fc03839eb2c1706533eaaa501a3d75b84572614906447695b6a0e1ca66a04fcf6117db1b13adb94c001e114d76b86b5b01
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fluent-plugin-docker-format.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Alex Hornung
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Fluent::Plugin::Docker::Format
2
+
3
+ This fluentd output filter plugin can parse a docker container's config.json associated with a certain log entry and add information from config.json to the record.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'fluent-plugin-docker-format'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install fluent-plugin-docker-format
19
+
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ <match docker.var.lib.docker.containers.*.*.log>
25
+ type docker_format
26
+ docker_containers_path /var/lib/docker/containers
27
+ container_id ${tag_parts[5]}
28
+ tag docker.all
29
+ </match>
30
+ ```
31
+
32
+ The `docker_containers_path` is optional and defaults to `/var/lib/docker/containers`.
33
+
34
+ The `container_id` parameter can either be a string with the id, or use the special interpolated substitution `${tag_parts[<some number>]}`. The tag parts are the dot-separated parts of the incoming tag, so that in the above example they would match the first star.
35
+
36
+ A full example:
37
+
38
+ ```
39
+ <source>
40
+ type tail
41
+ path /var/lib/docker/containers/*/*-json.log
42
+ pos_file /var/log/fluentd-docker.pos
43
+ time_format %Y-%m-%dT%H:%M:%S
44
+ tag docker.*
45
+ format json
46
+ </source>
47
+
48
+ <match docker.var.lib.docker.containers.*.*.log>
49
+ type docker_format
50
+ container_id ${tag_parts[5]}
51
+ tag docker.${name}
52
+ </match>
53
+ ```
54
+
55
+ The output record will have three additional fields, `container_id`, `container_name` and `image_name`.
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.5
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fluent-plugin-docker-format_nebo15"
7
+ spec.version = File.read("VERSION").strip
8
+ spec.authors = ["Alex Hornung"]
9
+ spec.email = ["alex@alexhornung.com"]
10
+ spec.description = %q{fluentd output filter plugin to parse the docker config.json related to a container log file.}
11
+ spec.summary = spec.description
12
+ spec.homepage = "https://github.com/bwalex/fluent-plugin-docker-format"
13
+ spec.license = "MIT"
14
+ spec.has_rdoc = false
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake", "~> 10.4.2"
23
+
24
+ spec.add_dependency "fluentd", "~> 0.10.17"
25
+ end
@@ -0,0 +1,90 @@
1
+ require 'json'
2
+
3
+ module Fluent
4
+ class DockerFormatOutput < Output
5
+ Fluent::Plugin.register_output('docker_format', self)
6
+ config_param :tag, :string
7
+ config_param :container_id, :string
8
+ config_param :docker_containers_path, :string, :default => '/var/lib/docker/containers'
9
+
10
+ def configure(conf)
11
+ super
12
+ @id_to_docker_cfg = {}
13
+ end
14
+
15
+ def emit(tag, es, chain)
16
+ es.each do |time,record|
17
+ Engine.emit(interpolate_tag(tag), time, format_record(tag, record))
18
+ end
19
+
20
+ chain.next
21
+ end
22
+
23
+ private
24
+
25
+ def interpolate(tag, str)
26
+ tag_parts = tag.split('.')
27
+
28
+ str.gsub(/\$\{tag_parts\[(\d+)\]\}/) { |m| tag_parts[$1.to_i] }
29
+ end
30
+
31
+ def interpolate_tag(tag)
32
+ id = interpolate(tag, @container_id)
33
+
34
+ container_name = get_container_name(id)
35
+ @tag.gsub(/\$\{name\}/, container_name || id)
36
+ @tag.gsub(/\$\{container_name\}/, container_name || id)
37
+
38
+ image_name = get_image_name(id)
39
+ image_name.gsub!(/\:.*$/,'') if image_name # strip the docker tag
40
+ @tag.gsub(/\$\{image_name\}/, image_name || id)
41
+ end
42
+
43
+ def get_docker_cfg_from_id(id)
44
+ begin
45
+ docker_cfg = JSON.parse(File.read("#{@docker_containers_path}/#{id}/config.json"))
46
+ rescue
47
+ docker_cfg = nil
48
+ end
49
+ docker_cfg
50
+ end
51
+
52
+ def get_container_name(id)
53
+ @id_to_docker_cfg[id] = get_docker_cfg_from_id(id) unless @id_to_docker_cfg.has_key? id
54
+ if @id_to_docker_cfg[id] == nil
55
+ container_name = nil
56
+ else
57
+ container_name = @id_to_docker_cfg[id]['Name'][1..-1]
58
+ end
59
+ container_name
60
+ end
61
+
62
+ def get_image_name(id)
63
+ @id_to_docker_cfg[id] = get_docker_cfg_from_id(id) unless @id_to_docker_cfg.has_key? id
64
+ if @id_to_docker_cfg[id] == nil
65
+ image_name = nil
66
+ else
67
+ image_name = @id_to_docker_cfg[id]['Config']['Image'].dup
68
+ end
69
+ image_name
70
+ end
71
+
72
+ def get_image_name(id)
73
+ @id_to_docker_cfg[id] = get_docker_cfg_from_id(id) unless @id_to_docker_cfg.has_key? id
74
+ if @id_to_docker_cfg[id] == nil
75
+ image_name = nil
76
+ else
77
+ image_name = @id_to_docker_cfg[id]['Config']['Image'].dup
78
+ end
79
+ image_name
80
+ end
81
+
82
+ def format_record(tag, record)
83
+ id = interpolate(tag, @container_id)
84
+ record['container_id'] = id
85
+ record['container_name'] = get_container_name(id) || "<unknown>"
86
+ record['image_name'] = get_image_name(id) || "<unknown>"
87
+ record
88
+ end
89
+ end
90
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-docker-format_nebo15
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5
5
+ platform: ruby
6
+ authors:
7
+ - Alex Hornung
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 10.4.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 10.4.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: fluentd
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.17
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.17
55
+ description: fluentd output filter plugin to parse the docker config.json related
56
+ to a container log file.
57
+ email:
58
+ - alex@alexhornung.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - VERSION
69
+ - fluent-plugin-docker-format.gemspec
70
+ - lib/fluent/plugin/out_docker_format.rb
71
+ homepage: https://github.com/bwalex/fluent-plugin-docker-format
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.6
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: fluentd output filter plugin to parse the docker config.json related to a
95
+ container log file.
96
+ test_files: []