logstash-filter-docker_container 0.1.0

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: 1622d74b418ee109102656edde38f595b14fa112
4
+ data.tar.gz: 784f7e6c23f0b874b3207d089f85286b7a7fe6a9
5
+ SHA512:
6
+ metadata.gz: 043d0a774f01e72fb9e810b35a09ec741c9ae0ad51f994630ac3dd0008abf40acee9e5ea5e01aa90b759491747c91c1a70ad860b21acd3a5c9252c521cecbc57
7
+ data.tar.gz: a083587689682b383597c4d8c5b648256940a9894402b6ce1188796840a8ad8747a69ddc42b5592ccfa6c298d0df8d994ea877270355bf5efbeb3ebf124a5c65
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ Gemfile.bak
4
+ .bundle
5
+ vendor
6
+ /.idea
7
+ /out
@@ -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,86 @@
1
+ # Docker Container Logstash Filter Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
4
+
5
+ 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.
6
+
7
+ ## Documentation
8
+
9
+ 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/).
10
+
11
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide
13
+
14
+ ## Need Help?
15
+
16
+ Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list.
17
+
18
+ ## Developing
19
+
20
+ ### 1. Plugin Developement and Testing
21
+
22
+ #### Code
23
+ - To get started, you'll need JRuby with the Bundler gem installed.
24
+
25
+ - 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).
26
+
27
+ - Install dependencies
28
+ ```sh
29
+ bundle install
30
+ ```
31
+
32
+ #### Test
33
+
34
+ - Update your dependencies
35
+
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ - Run tests
41
+
42
+ ```sh
43
+ bundle exec rspec
44
+ ```
45
+
46
+ ### 2. Running your unpublished Plugin in Logstash
47
+
48
+ #### 2.1 Run in a local Logstash clone
49
+
50
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
51
+ ```ruby
52
+ gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
53
+ ```
54
+ - Install plugin
55
+ ```sh
56
+ bin/plugin install --no-verify
57
+ ```
58
+ - Run Logstash with your plugin
59
+ ```sh
60
+ bin/logstash -e 'filter {awesome {}}'
61
+ ```
62
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
63
+
64
+ #### 2.2 Run in an installed Logstash
65
+
66
+ 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:
67
+
68
+ - Build your plugin gem
69
+ ```sh
70
+ gem build logstash-filter-awesome.gemspec
71
+ ```
72
+ - Install the plugin from the Logstash home
73
+ ```sh
74
+ bin/plugin install /your/local/plugin/logstash-filter-awesome.gem
75
+ ```
76
+ - Start Logstash and proceed to test the plugin
77
+
78
+ ## Contributing
79
+
80
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
81
+
82
+ 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.
83
+
84
+ It is more important to the community that you are able to contribute.
85
+
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rake"
@@ -0,0 +1,14 @@
1
+ machine:
2
+ ruby:
3
+ version: jruby-1.7.19
4
+
5
+ test:
6
+ post:
7
+ - bundle install
8
+ - bundle exec rspec
9
+
10
+ deployment:
11
+ publish:
12
+ branch: master
13
+ commands:
14
+ - ./gem_publish.sh
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ mkdir -p ~/.gem
4
+ echo ":rubygems_api_key: ${RUBYGEMS_API_KEY}" > ~/.gem/credentials
5
+ chmod 600 ~/.gem/credentials
6
+ bundle exec rake publish_gem
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ require 'logstash/filters/base'
3
+ require 'logstash/namespace'
4
+ require 'lib/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
+ end # def register
22
+
23
+ public
24
+ def filter(event)
25
+ return unless filter? event
26
+
27
+ @match.each { |in_field,out_field|
28
+ event[out_field] = resolve_from(event[in_field])
29
+ }
30
+
31
+ filter_matched(event)
32
+ end
33
+
34
+ def resolve_from(container_id)
35
+ blob = @inspector.inspect container_id
36
+ details = JSON.parse(blob)
37
+
38
+ return nil if details.empty?
39
+
40
+ detail = details.first
41
+ detail['Name']
42
+
43
+ end # def filter
44
+ 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,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-docker_container'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache License (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 = `git ls-files`.split($\)
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", '>= 1.4.0', '< 2.0.0'
22
+ s.add_development_dependency 'logstash-devutils'
23
+ 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,34 @@
1
+ require 'spec_helper'
2
+ require "logstash/filters/docker_container"
3
+ require 'rspec/mocks'
4
+
5
+ describe LogStash::Filters::DockerContainer do
6
+ let(:inspector) { double 'LogStash::Filters::DockerContainerSupport::DockerContainerInspector' }
7
+
8
+ before do
9
+ allow(LogStash::Filters::DockerContainerSupport::DockerContainerInspector).to receive(:new).and_return(inspector)
10
+ end
11
+
12
+ describe "typical case" do
13
+ let(:config) do <<-CONFIG
14
+ filter {
15
+ docker_container {
16
+ match => { 'container_id' => 'container_name' }
17
+ }
18
+ }
19
+ CONFIG
20
+ end
21
+
22
+ before do
23
+ content = File.new(File.join(File.dirname(__FILE__),'container_logstash.json')).read()
24
+ expect(inspector).to receive(:inspect)
25
+ .with('bd30193a3b9d')
26
+ .and_return(content)
27
+ end
28
+
29
+ sample('container_id' => 'bd30193a3b9d') do
30
+ expect(subject).to include('container_name')
31
+ expect(subject['container_name']).to eq('/logstash')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-docker_container
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Geoff Bourne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: 2.0.0
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.4.0
28
+ - - <
29
+ - !ruby/object:Gem::Version
30
+ version: 2.0.0
31
+ prerelease: false
32
+ type: :runtime
33
+ - !ruby/object:Gem::Dependency
34
+ name: logstash-devutils
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirement: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ prerelease: false
46
+ type: :development
47
+ description: With Docker's syslog log-driver the log entries contain just container ID, but seeing the name is even better
48
+ email: itzgeoff@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - CONTRIBUTORS
55
+ - DEVELOPER.md
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - circle.yml
61
+ - gem_publish.sh
62
+ - lib/logstash/filters/docker_container.rb
63
+ - lib/logstash/filters/docker_container/docker_container_inspector.rb
64
+ - logstash-filter-docker_container.gemspec
65
+ - spec/filters/container_logstash.json
66
+ - spec/filters/docker_container_spec.rb
67
+ - spec/spec_helper.rb
68
+ homepage: https://github.com/itzg/logstash-filter-docker_container
69
+ licenses:
70
+ - Apache License (2.0)
71
+ metadata:
72
+ logstash_plugin: 'true'
73
+ logstash_group: filter
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.4.5
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Resolves Docker container IDs into the container's name.
94
+ test_files:
95
+ - spec/filters/container_logstash.json
96
+ - spec/filters/docker_container_spec.rb
97
+ - spec/spec_helper.rb