logstash-filter-kubernetes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5dfcb85cd093c59c6bc57c69c4dd232f0853b83d
4
+ data.tar.gz: 092b5463d4abd4fa85aff9b94ddbaadde52009cf
5
+ SHA512:
6
+ metadata.gz: 4f2eeca7e1f07eb075a6cab522a39cc1ace8b8a32a80687167f9006cc3362a7d5299f2e6e258413008a9c5299e34fde831bff8af7e47a444717383217b786134
7
+ data.tar.gz: 94e30526eb5c9f5c4f9300f871c0323e5b35c4dee74176b0875424daa8ea9656b7b38d9c750811e18a6caaae7637ca4ebb261e21f84470459777dcbc16146a2e
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.
data/README.md ADDED
@@ -0,0 +1,87 @@
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
+ ## Documentation
9
+
10
+ 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/).
11
+
12
+ - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
13
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
14
+
15
+ ## Need Help?
16
+
17
+ Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
18
+
19
+ ## Developing
20
+
21
+ ### 1. Plugin Developement and Testing
22
+
23
+ #### Code
24
+ - To get started, you'll need JRuby with the Bundler gem installed.
25
+
26
+ - 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).
27
+
28
+ - Install dependencies
29
+ ```sh
30
+ bundle install
31
+ ```
32
+
33
+ #### Test
34
+
35
+ - Update your dependencies
36
+
37
+ ```sh
38
+ bundle install
39
+ ```
40
+
41
+ - Run tests
42
+
43
+ ```sh
44
+ bundle exec rspec
45
+ ```
46
+
47
+ ### 2. Running your unpublished Plugin in Logstash
48
+
49
+ #### 2.1 Run in a local Logstash clone
50
+
51
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
52
+ ```ruby
53
+ gem "logstash-filter-kubernetes", :path => "/your/local/logstash-filter-kubernetes"
54
+ ```
55
+ - Install plugin
56
+ ```sh
57
+ bin/plugin install --no-verify
58
+ ```
59
+ - Run Logstash with your plugin
60
+ ```sh
61
+ bin/logstash -e 'filter {kubernetes {}}'
62
+ ```
63
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
64
+
65
+ #### 2.2 Run in an installed Logstash
66
+
67
+ 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:
68
+
69
+ - Build your plugin gem
70
+ ```sh
71
+ gem build logstash-filter-kubernetes.gemspec
72
+ ```
73
+ - Install the plugin from the Logstash home
74
+ ```sh
75
+ bin/plugin install /your/local/plugin/logstash-filter-kubernetes.gem
76
+ ```
77
+ - Start Logstash and proceed to test the plugin
78
+
79
+ ## Contributing
80
+
81
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
82
+
83
+ 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.
84
+
85
+ It is more important to the community that you are able to contribute.
86
+
87
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -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
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,23 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-kubernetes'
3
+ s.version = '0.1.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", ">= 1.4.0", "< 2.0.0"
22
+ s.add_development_dependency 'logstash-devutils', '~> 0'
23
+ end
@@ -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,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-kubernetes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vaidas Jablonskis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-30 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: 1.4.0
19
+ - - <
20
+ - !ruby/object:Gem::Version
21
+ version: 2.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: 1.4.0
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: logstash-devutils
40
+ prerelease: false
41
+ type: :development
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ 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
48
+ email: jablonskis@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - Gemfile
54
+ - LICENSE
55
+ - README.md
56
+ - lib/logstash/filters/kubernetes.rb
57
+ - logstash-filter-kubernetes.gemspec
58
+ - spec/filters/kubernetes_spec.rb
59
+ - spec/spec_helper.rb
60
+ homepage: https://github.com/vaijab/logstash-filter-kubernetes
61
+ licenses:
62
+ - Apache License (2.0)
63
+ metadata:
64
+ logstash_plugin: 'true'
65
+ logstash_group: filter
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.5
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: This filter extracts useful kubernetes information from kubelet logfile symlinks.
86
+ test_files:
87
+ - spec/filters/kubernetes_spec.rb
88
+ - spec/spec_helper.rb