ant31-logstash-filter-kubernetes 5.0.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: 9c5e7e5922310a9d9df5e7a65ac465b8483b087c
4
+ data.tar.gz: 4186881eb76c366fa9073a771f5e30a3897e1013
5
+ SHA512:
6
+ metadata.gz: 19742e9de3d8ebd4891b8f32c8dd53989a3c683fb84862f0d6374f3dbab829763e550b14452595ef879ad3ea5db5685350b41941a60ba2949e894e3f65b24523
7
+ data.tar.gz: 0b6fbc21e9fb2f396e73ee483c34903f72f23033e6895cf2b28c98b2b316e7bd31ac6af7d11a23f9257f9915f85760fec480697ecef73fb4f77c32ba55b55de4
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2015 Vaidas Jablonskis <jablonskis@gmail.com>
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,114 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
+
5
+ It is fully free and fully open source. The license is Apache 2.0, meaning you
6
+ are pretty much free to use it however you want in whatever way.
7
+
8
+ Rubygems: https://rubygems.org/gems/logstash-filter-kubernetes
9
+
10
+ ## Documentation
11
+
12
+ This plugin does not require access to Kubernetes API.
13
+
14
+ ### Example configuration
15
+ ```ruby
16
+ input {
17
+ file {
18
+ # Path to kubelet created symlinks to docker logs, by default, symlinks look like
19
+ # /var/log/containers/*.log --> /var/lib/docker/containers/*/*-json.log
20
+ path => "/var/log/containers/*.log"
21
+ }
22
+ }
23
+
24
+ filter {
25
+ kubernetes {}
26
+ }
27
+
28
+ output {
29
+ stdout {}
30
+ }
31
+ ```
32
+
33
+ If you're running logstash in a container, make sure that you mount both,
34
+ `/var/log/containers` and `/var/lib/docker/containers` for logstash input to be
35
+ able to follow symlinks.
36
+
37
+ 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.elastic.co/guide/en/logstash/current/).
38
+
39
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
40
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
41
+
42
+ ## Need Help?
43
+
44
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
45
+
46
+ ## Developing
47
+
48
+ ### 1. Plugin Developement and Testing
49
+
50
+ #### Code
51
+ - To get started, you'll need JRuby with the Bundler gem installed.
52
+
53
+ - 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).
54
+
55
+ - Install dependencies
56
+ ```sh
57
+ bundle install
58
+ ```
59
+
60
+ #### Test
61
+
62
+ - Update your dependencies
63
+
64
+ ```sh
65
+ bundle install
66
+ ```
67
+
68
+ - Run tests
69
+
70
+ ```sh
71
+ bundle exec rspec
72
+ ```
73
+
74
+ ### 2. Running your unpublished Plugin in Logstash
75
+
76
+ #### 2.1 Run in a local Logstash clone
77
+
78
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
79
+ ```ruby
80
+ gem "logstash-filter-kubernetes", :path => "/your/local/logstash-filter-kubernetes"
81
+ ```
82
+ - Install plugin
83
+ ```sh
84
+ bin/plugin install --no-verify
85
+ ```
86
+ - Run Logstash with your plugin
87
+ ```sh
88
+ bin/logstash -e 'filter {kubernetes {}}'
89
+ ```
90
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
91
+
92
+ #### 2.2 Run in an installed Logstash
93
+
94
+ 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:
95
+
96
+ - Build your plugin gem
97
+ ```sh
98
+ gem build logstash-filter-kubernetes.gemspec
99
+ ```
100
+ - Install the plugin from the Logstash home
101
+ ```sh
102
+ bin/plugin install /your/local/plugin/logstash-filter-kubernetes.gem
103
+ ```
104
+ - Start Logstash and proceed to test the plugin
105
+
106
+ ## Contributing
107
+
108
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
109
+
110
+ 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.
111
+
112
+ It is more important to the community that you are able to contribute.
113
+
114
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'ant31-logstash-filter-kubernetes'
3
+ s.version = '5.0.0'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This filter extracts useful kubernetes information from kubelet logfile symlinks."
6
+ s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
7
+ s.authors = ["Vaidas Jablonskis"]
8
+ s.email = 'jablonskis@gmail.com'
9
+ s.homepage = "https://github.com/vaijab/logstash-filter-kubernetes"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','Gemfile','LICENSE']
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"
22
+ s.add_development_dependency 'logstash-devutils', '~> 0'
23
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ # This filter plugin allows you extract Pod, Namespace, etc from kubernetes.
6
+ # The way this filter works is very simple. It looks at an event field which
7
+ # contains full path to kubelet created symlinks to docker container logs and
8
+ # extracts useful information from a symlink name. No access to Kubernetes API
9
+ # is required.
10
+ class LogStash::Filters::Kubernetes < LogStash::Filters::Base
11
+
12
+ # This is how you configure this filter from your Logstash config.
13
+ #
14
+ # Example:
15
+ # [source,ruby]
16
+ # input {
17
+ # file {
18
+ # # Path to kubelet symlinks to docker logs, by default, symlinks look like
19
+ # # /var/log/containers/*.log --> /var/lib/docker/containers/*/*-json.log
20
+ # path => "/var/log/containers/*.log"
21
+ # }
22
+ # }
23
+ #
24
+ # filter {
25
+ # kubernetes {
26
+ # source => "path"
27
+ # target => "kubernetes"
28
+ # }
29
+ # }
30
+ #
31
+ config_name "kubernetes"
32
+
33
+ # The source field name which contains full path to kubelet log file.
34
+ config :source, :validate => :string, :default => "path"
35
+
36
+ # The target field name to write event kubernetes metadata.
37
+ config :target, :validate => :string, :default => "kubernetes"
38
+
39
+
40
+ public
41
+ def register
42
+ # Nothing to do
43
+ end # def register
44
+
45
+ public
46
+ def filter(event)
47
+
48
+ if @source and event[@source]
49
+ parts = event[@source].split(File::SEPARATOR).last.gsub(/.log$/, '').split('_')
50
+
51
+ # We do not care about empty POD log files
52
+ if parts.length != 3 || parts[2].start_with?('POD-')
53
+ return
54
+ else
55
+ kubernetes = {}
56
+ kubernetes['replication_controller'] = parts[0].gsub(/-[0-9a-z]*$/, '')
57
+ kubernetes['pod'] = parts[0]
58
+ kubernetes['namespace'] = parts[1]
59
+ kubernetes['container_name'] = parts[2].gsub(/-[0-9a-z]*$/, '')
60
+ kubernetes['container_id'] = parts[2].split('-').last
61
+
62
+ event[@target] = kubernetes
63
+ end
64
+ end
65
+
66
+ # filter_matched should go in the last line of our successful code
67
+ filter_matched(event)
68
+ end # def filter
69
+ end # class LogStash::Filters::Kubernetes
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require "logstash/filters/kubernetes"
3
+
4
+ describe LogStash::Filters::Kubernetes do
5
+ describe "Split path into kubernetes key-value pairs." do
6
+ let(:config) do <<-CONFIG
7
+ filter {
8
+ kubernetes {
9
+ source => "path"
10
+ }
11
+ }
12
+ CONFIG
13
+ end
14
+
15
+ sample("path" => "/var/log/containers/kube-dns-v9-6mnxk_default_skydns-47d3a3bfb112dbd2fd6e255e1e3d9eb91a10b62342e620e4917e2f5e24398507.log") do
16
+ insist { subject["kubernetes"] } == {"replication_controller"=>"kube-dns-v9", "pod"=>"kube-dns-v9-6mnxk", "namespace"=>"default", "container_name"=>"skydns", "container_id"=>"47d3a3bfb112dbd2fd6e255e1e3d9eb91a10b62342e620e4917e2f5e24398507"}
17
+ end
18
+ end
19
+ end
20
+
21
+ describe LogStash::Filters::Kubernetes do
22
+ describe "Set target field name." do
23
+ let(:config) do <<-CONFIG
24
+ filter {
25
+ kubernetes {
26
+ source => "path"
27
+ target => "foobar"
28
+ }
29
+ }
30
+ CONFIG
31
+ end
32
+
33
+ sample("path" => "/var/log/containers/kube-dns-v9-6mnxk_default_skydns-47d3a3bfb112dbd2fd6e255e1e3d9eb91a10b62342e620e4917e2f5e24398507.log") do
34
+ insist { subject["foobar"] } == {"replication_controller"=>"kube-dns-v9", "pod"=>"kube-dns-v9-6mnxk", "namespace"=>"default", "container_name"=>"skydns", "container_id"=>"47d3a3bfb112dbd2fd6e255e1e3d9eb91a10b62342e620e4917e2f5e24398507"}
35
+ end
36
+ end
37
+ end
38
+
39
+ describe LogStash::Filters::Kubernetes do
40
+ describe "Skip parsing empty POD event." do
41
+ let(:config) do <<-CONFIG
42
+ filter {
43
+ kubernetes {
44
+ source => "path"
45
+ }
46
+ }
47
+ CONFIG
48
+ end
49
+
50
+ sample("path" => "/var/log/containers/kube-dns-v9-6mnxk_default_POD-eaca2cf56e761c25dc4878d48fbe056402ba01f3f6448650d93f988ec121b8cd.log") do
51
+ insist { subject["kubernetes"] } == nil
52
+ end
53
+ end
54
+ end
@@ -0,0 +1 @@
1
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ant31-logstash-filter-kubernetes
3
+ version: !ruby/object:Gem::Version
4
+ version: 5.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vaidas Jablonskis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: logstash-devutils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This gem is a logstash plugin required to be installed on top of the
42
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
43
+ a stand-alone program
44
+ email: jablonskis@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - ant31-logstash-filter-kubernetes.gemspec
53
+ - lib/logstash/filters/kubernetes.rb
54
+ - spec/filters/kubernetes_spec.rb
55
+ - spec/spec_helper.rb
56
+ homepage: https://github.com/vaijab/logstash-filter-kubernetes
57
+ licenses:
58
+ - Apache License (2.0)
59
+ metadata:
60
+ logstash_plugin: 'true'
61
+ logstash_group: filter
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.5.1
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: This filter extracts useful kubernetes information from kubelet logfile symlinks.
82
+ test_files:
83
+ - spec/filters/kubernetes_spec.rb
84
+ - spec/spec_helper.rb