logstash-filter-docker_container 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b7fae9f92138bcbee4d52f4038e6e2ac2df2891
4
+ data.tar.gz: eb0953bffab5a56c452783138790e22a32ebef7b
5
+ SHA512:
6
+ metadata.gz: 7a03b8a6650098c3923f32b30bb649db9f2a4e45671ad18f31bc574d651be7561ab4e3616ec2a617aaee16c3b1fb30909e353e2e9b818d08906a970ee57b0869
7
+ data.tar.gz: c5da6a9c38decf2bb38c9b8df4f18b3c2b03d816b2a4148e54f05f3494260f31372cedd231d009d482c2453cf3ff9be38e456ba594abcf8b9082dc1de86b5f31
@@ -0,0 +1,11 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * Aaron Mildenstein (untergeek)
6
+ * Pier-Hugues Pellerin (ph)
7
+
8
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
9
+ Logstash, and you aren't on the list above and want to be, please let us know
10
+ and we'll make sure you're here. Contributions from folks like you are what make
11
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-filter-example
2
+ Example filter plugin. This should help bootstrap your effort to write your own filter plugin!
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012-2015 Elasticsearch <http://www.elasticsearch.org>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,91 @@
1
+
2
+ This is a Logstash filter plugin that resolves Docker container IDs into the container's name.
3
+
4
+ [![Gem](https://img.shields.io/gem/v/logstash-filter-docker_container.svg)](https://rubygems.org/gems/logstash-filter-docker_container)
5
+
6
+ # Docker Container Logstash Filter Plugin
7
+
8
+ This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
9
+
10
+ It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
11
+
12
+ ## Documentation
13
+
14
+ Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/).
15
+
16
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
17
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
18
+
19
+ ## Need Help?
20
+
21
+ Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
22
+
23
+ ## Developing
24
+
25
+ ### 1. Plugin Developement and Testing
26
+
27
+ #### Code
28
+ - To get started, you'll need JRuby with the Bundler gem installed.
29
+
30
+ - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
31
+
32
+ - Install dependencies
33
+ ```sh
34
+ bundle install
35
+ ```
36
+
37
+ #### Test
38
+
39
+ - Update your dependencies
40
+
41
+ ```sh
42
+ bundle install
43
+ ```
44
+
45
+ - Run tests
46
+
47
+ ```sh
48
+ bundle exec rspec
49
+ ```
50
+
51
+ ### 2. Running your unpublished Plugin in Logstash
52
+
53
+ #### 2.1 Run in a local Logstash clone
54
+
55
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
56
+ ```ruby
57
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
58
+ ```
59
+ - Install plugin
60
+ ```sh
61
+ bin/plugin install --no-verify
62
+ ```
63
+ - Run Logstash with your plugin
64
+ ```sh
65
+ bin/logstash -e 'filter {awesome {}}'
66
+ ```
67
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
68
+
69
+ #### 2.2 Run in an installed Logstash
70
+
71
+ You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
72
+
73
+ - Build your plugin gem
74
+ ```sh
75
+ gem build logstash-filter-awesome.gemspec
76
+ ```
77
+ - Install the plugin from the Logstash home
78
+ ```sh
79
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
80
+ ```
81
+ - Start Logstash and proceed to test the plugin
82
+
83
+ ## Contributing
84
+
85
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
86
+
87
+ Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
88
+
89
+ It is more important to the community that you are able to contribute.
90
+
91
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ require 'logstash/filters/base'
3
+ require 'logstash/namespace'
4
+ require 'logstash/filters/docker_container/docker_container_inspector'
5
+ require 'json'
6
+
7
+ class LogStash::Filters::DockerContainer < LogStash::Filters::Base
8
+
9
+ config_name "docker_container"
10
+
11
+ config :match, :validate => :hash, :default => {'container_id' => 'container_name'}, :required => true
12
+
13
+ config :docker_client, :validate => :string, :default => 'docker'
14
+
15
+ config :client_options, :validate => :string, :default => ''
16
+
17
+ public
18
+ def register
19
+ # Add instance variables
20
+ @inspector = LogStash::Filters::DockerContainerSupport::DockerContainerInspector.new(@docker_client, @client_options)
21
+ @cached = Hash.new
22
+ end # def register
23
+
24
+ public
25
+ def filter(event)
26
+ return unless filter? event
27
+
28
+ @match.each { |in_field,out_field|
29
+ event.set(out_field, resolve_from(event.get(in_field)))
30
+ }
31
+
32
+ filter_matched(event)
33
+ end
34
+
35
+ def resolve_from(container_id)
36
+ if @cached.has_key?(container_id)
37
+ return @cached[container_id]
38
+ end
39
+
40
+ blob = @inspector.inspect container_id
41
+ details = JSON.parse(blob)
42
+
43
+ return nil if details.empty?
44
+
45
+ detail = details.first
46
+ @cached[container_id] = detail['Name']
47
+
48
+ end # def filter
49
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module LogStash::Filters::DockerContainerSupport
3
+
4
+ class DockerContainerInspector
5
+
6
+ public
7
+ # @param [String] docker_client the Docker client executable to run. Either needs to be in $PATH or an absolute path
8
+ # @param [String] client_options the command-line options to fine tune connectivity to the Docker daemon
9
+ def initialize(docker_client, client_options)
10
+ @docker_client = docker_client
11
+ @client_options = client_options
12
+ end
13
+
14
+ public
15
+ # @return [String] the `docker inspect` content or '[]' if unable to find the container
16
+ # @param [String] container_id
17
+ def inspect(container_id)
18
+ content = `#{@docker_client} #{@client_options} inspect #{container_id}`
19
+ return $?.success? ? content : '[]'
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-docker_container'
3
+ s.version = '0.2.3'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = "Resolves Docker container IDs into the container's name."
6
+ s.description = "With Docker's syslog log-driver the log entries contain just container ID, but seeing the name is even better"
7
+ s.authors = ["Geoff Bourne"]
8
+ s.email = 'itzgeoff@gmail.com'
9
+ s.homepage = "https://github.com/itzg/logstash-filter-docker_container"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core", '>= 5.0.0', '< 7.0.0'
22
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
23
+ s.add_development_dependency 'logstash-devutils'
24
+ end
@@ -0,0 +1,149 @@
1
+ [{
2
+ "AppArmorProfile": "",
3
+ "Args": [
4
+ "agent",
5
+ "-f",
6
+ "/conf"
7
+ ],
8
+ "Config": {
9
+ "AttachStderr": false,
10
+ "AttachStdin": false,
11
+ "AttachStdout": false,
12
+ "Cmd": [
13
+ "bin/logstash",
14
+ "agent",
15
+ "-f",
16
+ "/conf"
17
+ ],
18
+ "CpuShares": 0,
19
+ "Cpuset": "",
20
+ "Domainname": "",
21
+ "Entrypoint": null,
22
+ "Env": [
23
+ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
24
+ "APT_GET_UPDATE=2015-03-08",
25
+ "JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64",
26
+ "DOCKER_VERSION=1.5.0.rc2-1",
27
+ "PLUGIN_UPDATES=2015-04-12"
28
+ ],
29
+ "ExposedPorts": {
30
+ "25826/tcp": {},
31
+ "25826/udp": {}
32
+ },
33
+ "Hostname": "bd30193a3b9d",
34
+ "Image": "itzg/logstash",
35
+ "Labels": {},
36
+ "MacAddress": "",
37
+ "Memory": 0,
38
+ "MemorySwap": 0,
39
+ "NetworkDisabled": false,
40
+ "OnBuild": null,
41
+ "OpenStdin": false,
42
+ "PortSpecs": null,
43
+ "StdinOnce": false,
44
+ "Tty": false,
45
+ "User": "",
46
+ "Volumes": {
47
+ "/conf": {},
48
+ "/logs": {}
49
+ },
50
+ "WorkingDir": "/opt/logstash"
51
+ },
52
+ "Created": "2015-04-18T22:09:07.380052053Z",
53
+ "Driver": "aufs",
54
+ "ExecDriver": "native-0.2",
55
+ "ExecIDs": null,
56
+ "HostConfig": {
57
+ "Binds": [
58
+ "/var/log:/logs",
59
+ "/home/geoff/logstash-conf:/conf"
60
+ ],
61
+ "CapAdd": null,
62
+ "CapDrop": null,
63
+ "CgroupParent": "",
64
+ "ContainerIDFile": "",
65
+ "CpuShares": 0,
66
+ "CpusetCpus": "",
67
+ "Devices": [],
68
+ "Dns": null,
69
+ "DnsSearch": null,
70
+ "ExtraHosts": null,
71
+ "IpcMode": "",
72
+ "Links": [
73
+ "/es-00:/logstash/es"
74
+ ],
75
+ "LogConfig": {
76
+ "Config": null,
77
+ "Type": "syslog"
78
+ },
79
+ "LxcConf": [],
80
+ "Memory": 0,
81
+ "MemorySwap": 0,
82
+ "NetworkMode": "bridge",
83
+ "PidMode": "",
84
+ "PortBindings": {
85
+ "25826/udp": [
86
+ {
87
+ "HostIp": "",
88
+ "HostPort": "25827"
89
+ }
90
+ ]
91
+ },
92
+ "Privileged": false,
93
+ "PublishAllPorts": false,
94
+ "ReadonlyRootfs": false,
95
+ "RestartPolicy": {
96
+ "MaximumRetryCount": 0,
97
+ "Name": "always"
98
+ },
99
+ "SecurityOpt": null,
100
+ "Ulimits": null,
101
+ "VolumesFrom": null
102
+ },
103
+ "HostnamePath": "/var/lib/docker/containers/bd30193a3b9d4a9fddf2e20a763cec9bcd5888725b1ec2cd765ad5813e6fe831/hostname",
104
+ "HostsPath": "/var/lib/docker/containers/bd30193a3b9d4a9fddf2e20a763cec9bcd5888725b1ec2cd765ad5813e6fe831/hosts",
105
+ "Id": "bd30193a3b9d4a9fddf2e20a763cec9bcd5888725b1ec2cd765ad5813e6fe831",
106
+ "Image": "262c2f8dd6f8a34822efe638b5cb9798b31bfee61201e4c14f05067e72373b86",
107
+ "LogPath": "",
108
+ "MountLabel": "",
109
+ "Name": "/logstash",
110
+ "NetworkSettings": {
111
+ "Bridge": "",
112
+ "Gateway": "",
113
+ "GlobalIPv6Address": "",
114
+ "GlobalIPv6PrefixLen": 0,
115
+ "IPAddress": "",
116
+ "IPPrefixLen": 0,
117
+ "IPv6Gateway": "",
118
+ "LinkLocalIPv6Address": "",
119
+ "LinkLocalIPv6PrefixLen": 0,
120
+ "MacAddress": "",
121
+ "PortMapping": null,
122
+ "Ports": null
123
+ },
124
+ "Path": "bin/logstash",
125
+ "ProcessLabel": "",
126
+ "ResolvConfPath": "/var/lib/docker/containers/bd30193a3b9d4a9fddf2e20a763cec9bcd5888725b1ec2cd765ad5813e6fe831/resolv.conf",
127
+ "RestartCount": 0,
128
+ "State": {
129
+ "Dead": false,
130
+ "Error": "",
131
+ "ExitCode": 0,
132
+ "FinishedAt": "2015-04-19T01:31:06.671382823Z",
133
+ "OOMKilled": false,
134
+ "Paused": false,
135
+ "Pid": 0,
136
+ "Restarting": false,
137
+ "Running": false,
138
+ "StartedAt": "2015-04-18T22:09:07.594669634Z"
139
+ },
140
+ "Volumes": {
141
+ "/conf": "/home/geoff/logstash-conf",
142
+ "/logs": "/var/log"
143
+ },
144
+ "VolumesRW": {
145
+ "/conf": true,
146
+ "/logs": true
147
+ }
148
+ }
149
+ ]
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/docker_container"
4
+ require 'rspec/mocks'
5
+
6
+ describe LogStash::Filters::DockerContainer do
7
+ let(:inspector) { double 'LogStash::Filters::DockerContainerSupport::DockerContainerInspector' }
8
+
9
+ before do
10
+ allow(LogStash::Filters::DockerContainerSupport::DockerContainerInspector).to receive(:new).and_return(inspector)
11
+ end
12
+
13
+ describe "typical case and cached" do
14
+ let(:config) do <<-CONFIG
15
+ filter {
16
+ docker_container {
17
+ match => { 'container_id' => 'container_name' }
18
+ }
19
+ }
20
+ CONFIG
21
+ end
22
+
23
+ before do
24
+ content = File.new(File.join(File.dirname(__FILE__),'container_logstash.json')).read()
25
+ # Due to caching of the Docker findings, the inspector should only be consulted once
26
+ # since the sample includes the same container ID both times
27
+ expect(inspector).to receive(:inspect).once
28
+ .with('bd30193a3b9d')
29
+ .and_return(content)
30
+ end
31
+
32
+ sample([{'seq' => 1, 'container_id' => 'bd30193a3b9d'}, {'seq' => 2, 'container_id' => 'bd30193a3b9d'}]) do
33
+ subject.each do |e|
34
+ expect(e).to include('container_name')
35
+ expect(e.get('container_name')).to eq('/logstash')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-docker_container
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
5
+ platform: ruby
6
+ authors:
7
+ - Geoff Bourne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 5.0.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: 7.0.0
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '2.0'
39
+ name: logstash-core-plugin-api
40
+ prerelease: false
41
+ type: :runtime
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ name: logstash-devutils
54
+ prerelease: false
55
+ type: :development
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ description: With Docker's syslog log-driver the log entries contain just container
62
+ ID, but seeing the name is even better
63
+ email: itzgeoff@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - CONTRIBUTORS
69
+ - DEVELOPER.md
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - lib/logstash/filters/docker_container.rb
74
+ - lib/logstash/filters/docker_container/docker_container_inspector.rb
75
+ - logstash-filter-docker_container.gemspec
76
+ - spec/filters/container_logstash.json
77
+ - spec/filters/docker_container_spec.rb
78
+ - spec/spec_helper.rb
79
+ homepage: https://github.com/itzg/logstash-filter-docker_container
80
+ licenses:
81
+ - Apache-2.0
82
+ metadata:
83
+ logstash_plugin: 'true'
84
+ logstash_group: filter
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.6.14.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Resolves Docker container IDs into the container's name.
105
+ test_files:
106
+ - spec/filters/container_logstash.json
107
+ - spec/filters/docker_container_spec.rb
108
+ - spec/spec_helper.rb