logstash-filter-rancher_metadata 0.0.1

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: e76fdee2884c47ea727fe867a3cfa5b65a50105e
4
+ data.tar.gz: 1baff144bf47f92e722c39859d9fd53046f76546
5
+ SHA512:
6
+ metadata.gz: cacbb87ea9d3e63bf958df523044cd71106f4a9bede3b7aa5d2a6f410764a346b4fc25a003467b0a1128e40c24157083af5d9b3f7f267af08a9dbe95ea5ac514
7
+ data.tar.gz: 5f1c222089adb8a64b15cf968c78ecc05bd512dbcdbc2be78f8623287419b4a12c6335c2a2d85e29d06fb41d96c7926450bd750da274fae48f076189fb0f8efa
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 0.0.1
2
+ - First release
data/CONTRIBUTORS ADDED
@@ -0,0 +1,9 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped.
3
+
4
+ Contributors:
5
+
6
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
7
+ Logstash, and you aren't on the list above and want to be, please let us know
8
+ and we'll make sure you're here. Contributions from folks like you are what make
9
+ open source awesome.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2016 Matteo Cerutti <matteo.cerutti@hotmail.co.uk>
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/NOTICE.txt ADDED
@@ -0,0 +1,5 @@
1
+ Elasticsearch
2
+ Copyright 2012-2015 Elasticsearch
3
+
4
+ This product includes software developed by The Apache Software
5
+ Foundation (http://www.apache.org/).
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # Logstash Plugin
2
+
3
+ This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
4
+
5
+ This filter add rancher metadata to messages that contain a Docker container ID.
6
+
7
+ At current, the filter enriches the messages with the following tags
8
+ - Container name (name)
9
+ - Container IP (primary_ip)
10
+ - Container service name (service_name)
11
+ - Container stack name (stack_name)
12
+
13
+ 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.
14
+
15
+ ## Usage
16
+
17
+ Configuration used : `logstash agent -e "filter { rancher_metadata {} }"`
18
+
19
+ ```
20
+ ## Filter parameters
21
+
22
+ | name | default value | comment |
23
+ | :------------- | :------------- | :------------- |
24
+ | `api_url` | `[]` | Rancher Metadata API URL |
25
+ | `field_docker_id` | `'container_id'` | The docker container ID message field |
26
+ | `cache_size` | 100 | |
27
+
28
+ ## Developing
29
+
30
+ ### 1. Plugin Developement and Testing
31
+
32
+ #### Code
33
+ - To get started, you'll need JRuby with the Bundler gem installed.
34
+
35
+ - Install dependencies
36
+ ```sh
37
+ bundle install
38
+ ```
39
+
40
+ #### Test
41
+ There are no tests units.
42
+
43
+ #### Build gem
44
+ ```sh
45
+ gem build logstash-filter-rancher_metadata.gemspec
46
+ ```
47
+
48
+ ### 2. Running your unpublished Plugin in Logstash
49
+
50
+ #### 2.1 Run in a local Logstash clone
51
+
52
+ - Edit Logstash `Gemfile` and add the local plugin path, for example:
53
+ ```ruby
54
+ gem "logstash-filter-rancher_metadata", :path => "/your/local/logstash-filter-rancher_metadata"
55
+ ```
56
+ - Install plugin
57
+ ```sh
58
+ bin/plugin install --no-verify
59
+ ```
60
+ - Run Logstash with your plugin
61
+ ```sh
62
+ bin/logstash -e 'filter { rancher_metadata {} }'
63
+ ```
64
+ At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
65
+
66
+ #### 2.2 Run in an installed Logstash
67
+
68
+ 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:
69
+
70
+ - Build your plugin gem
71
+ ```sh
72
+ gem build logstash-filter-rancher_metadata.gemspec
73
+ ```
74
+ - Install the plugin from the Logstash home
75
+ ```sh
76
+ bin/plugin install /your/local/plugin/logstash-filter-rancher_metadata.gem
77
+ ```
78
+ - Start Logstash and proceed to test the plugin
79
+
80
+ ## Contributing
81
+
82
+ All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
83
+
84
+ 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.
85
+
86
+ It is more important to the community that you are able to contribute.
87
+
88
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
89
+
90
+ ## Author
91
+ Matteo Cerutti - <matteo.cerutti@hotmail.co.uk>
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ require "logstash/filters/base"
4
+ require "logstash/namespace"
5
+ require 'json'
6
+ require 'lru_redux'
7
+ require 'rancher-metadata'
8
+
9
+ class LogStash::Filters::RancherMetadata < LogStash::Filters::Base
10
+
11
+ # Setting the config_name here is required.
12
+ config_name "rancher_metadata"
13
+
14
+
15
+ config :api_url,
16
+ :validate => :array,
17
+ :default => [],
18
+ :required => false,
19
+ :deprecated => false
20
+
21
+ config :field_docker_id,
22
+ :validate => :string,
23
+ :default => 'path',
24
+ :required => false,
25
+ :deprecated => false
26
+
27
+ config :tags,
28
+ :validate => :array,
29
+ :default => ["name", "primary_ip", "service_name", "stack_name"],
30
+ :required => false,
31
+ :deprecated => false
32
+
33
+ config :cache_size,
34
+ :validate => :number,
35
+ :default => 100,
36
+ :required => false,
37
+ :deprecated => false
38
+
39
+ def get_metadata(container_id)
40
+ self.metadata_api.get_containers.each do |container|
41
+ return if container['uuid'] == container_id
42
+ end
43
+
44
+ nil
45
+ end
46
+
47
+ public
48
+ def register
49
+ # Add instance variables
50
+ @metadata_api = RancherMetadata::API.new({:api_url => @api_url})
51
+
52
+ @cache = LruRedux::ThreadSafeCache.new(@cache_size)
53
+ end # def register
54
+
55
+ public
56
+ def filter(event)
57
+ if event[@field_docker_id]
58
+ container_id = event[@field_docker_id]
59
+ metadata = @cache.getset(container_id){self.get_metadata(container_id)}
60
+ end
61
+
62
+ if metadata
63
+ event['rancher'] = {}
64
+
65
+ @tags.each do |tag|
66
+ event['rancher'][tag] = metadata[tag]
67
+ end
68
+ end
69
+
70
+ # filter_matched should go in the last line of our successful code
71
+ filter_matched(event)
72
+ end # def filter
73
+ end # class LogStash::Filters::RancherMetadata
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-filter-rancher_metadata'
3
+ s.version = '0.0.1'
4
+ s.licenses = ['Apache License (2.0)']
5
+ s.summary = "This filter add rancher metadata to messages that contain a Docker container ID"
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 = ["Matteo Cerutti"]
8
+ s.email = 'matteo.cerutti@hotmail.co.uk'
9
+ s.homepage = "http://github.com/m4ce/logstash-filter-rancher_metadata"
10
+ s.require_paths = ["lib"]
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+
15
+ # Tests
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+
18
+ # Special flag to let us know this is actually a logstash plugin
19
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
20
+
21
+ # Gem dependencies
22
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
23
+ s.add_runtime_dependency "rancher-metadata", "0.0.2"
24
+ s.add_runtime_dependency "lru_redux"
25
+ s.add_runtime_dependency "json"
26
+
27
+ s.add_development_dependency 'logstash-devutils'
28
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-rancher_metadata
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matteo Cerutti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-25 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: 2.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: rancher-metadata
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.0.2
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: lru_redux
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: json
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: logstash-devutils
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ description: This gem is a logstash plugin required to be installed on top of the
90
+ Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not
91
+ a stand-alone program
92
+ email: matteo.cerutti@hotmail.co.uk
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - CHANGELOG.md
98
+ - CONTRIBUTORS
99
+ - Gemfile
100
+ - LICENSE
101
+ - NOTICE.txt
102
+ - README.md
103
+ - lib/logstash/filters/rancher_metadata.rb
104
+ - logstash-filter-rancher_metadata.gemspec
105
+ homepage: http://github.com/m4ce/logstash-filter-rancher_metadata
106
+ licenses:
107
+ - Apache License (2.0)
108
+ metadata:
109
+ logstash_plugin: 'true'
110
+ logstash_group: filter
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: This filter add rancher metadata to messages that contain a Docker container
131
+ ID
132
+ test_files: []