logstash-filter-docker_metadata 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 000be01a06b8f7d60099cf0b4fb958cc8f4f1620
4
- data.tar.gz: 36332effcda2cd70d8d404b1066d1d6346a337ae
3
+ metadata.gz: 14333113d790da8f7dcb90098edff17202415619
4
+ data.tar.gz: 32845e1df70de9b55094da11470edb0c9d89d5a0
5
5
  SHA512:
6
- metadata.gz: 926be3f80c06cf3d560775bc4122e62c52de798328931233b38f68f6f04a98d1bbdf53b1eae860806ff6f054a1d20c5e7050feb9b02cef9a5716558bad68a374
7
- data.tar.gz: 8f906e5bb6ab7c8e9db7d3069cd8248f7d5918d09824ea727fbc7b50260cb7985e0f508d7ecb1fb4abc05cbd036bb8630fd9c987992da80748d3f420dc5fe7f2
6
+ metadata.gz: 47377aa16c3664d128ba4fa9e3e74bf147826e4e9f2401bc0d2938c2c995e4c33735b8105bdf3f74081a1663b5fae4be821a32ed739e6fa1085ae57d5adbc932
7
+ data.tar.gz: e3b6c7c146f68229d9c37ca9a13aed3ff5f1fa84d085f108aff73340b158f1d6dc9dacbbfc69cc175337b2dc92e774bab43976195dcfed3089adf538a8ee0991
@@ -0,0 +1,7 @@
1
+ require 'hashie'
2
+
3
+ class DockerHash < Hash
4
+
5
+ include Hashie::Extensions::IndifferentAccess
6
+
7
+ end
@@ -4,7 +4,9 @@ require "logstash/namespace"
4
4
  require 'docker'
5
5
  require 'json'
6
6
  require 'lru_redux'
7
- # This example filter will replace the contents of the default
7
+
8
+ require_relative 'docker_hash'
9
+ # This example filter will replace the contents of the default
8
10
  # message field with whatever you specify in the configuration.
9
11
  #
10
12
  # It is only intended to be used as an example.
@@ -12,7 +14,7 @@ class LogStash::Filters::DockerMetadata < LogStash::Filters::Base
12
14
 
13
15
  # Setting the config_name here is required.
14
16
  config_name "docker_metadata"
15
-
17
+
16
18
 
17
19
  config :docker_url,
18
20
  :validate => :string,
@@ -37,7 +39,7 @@ class LogStash::Filters::DockerMetadata < LogStash::Filters::Base
37
39
  :default => '(\w{64})',
38
40
  :required => false,
39
41
  :deprecated => false
40
-
42
+
41
43
  def get_metadata(container_id)
42
44
  begin
43
45
  Docker::Container.get(container_id).info
@@ -59,7 +61,7 @@ class LogStash::Filters::DockerMetadata < LogStash::Filters::Base
59
61
 
60
62
  public
61
63
  def register
62
- # Add instance variables
64
+ # Add instance variables
63
65
  Docker.url = @docker_url
64
66
 
65
67
  @cache = LruRedux::ThreadSafeCache.new(@cache_size)
@@ -68,13 +70,11 @@ class LogStash::Filters::DockerMetadata < LogStash::Filters::Base
68
70
 
69
71
  public
70
72
  def filter(event)
71
-
72
73
  # get container id from @field_docker_id field
73
74
  if event[@field_docker_id]
74
75
  container_id = event[@field_docker_id].match(@container_id_regexp_compiled)
75
76
  end
76
77
 
77
-
78
78
  if container_id && container_id[0]
79
79
  container_id = container_id[0]
80
80
  # try the cache else call the docker API
@@ -83,16 +83,17 @@ class LogStash::Filters::DockerMetadata < LogStash::Filters::Base
83
83
 
84
84
  if metadata
85
85
  # add a docker field with all informations
86
- event["docker"] = {
87
-
88
- :id => metadata['id'],
89
- :name => metadata['Name'],
90
- :container_hostname => metadata['Config']['Hostname'],
91
- :image => metadata['Config']['Image'],
92
- :image_id => metadata['Image'],
93
- :labels => metadata['Config']['Labels'],
94
- :env => self.format_env(metadata['Config']['Env'])
95
- }
86
+ # Added as custom hash so we get easy IndifferentAccess as symbol keys
87
+ # proved pretty hard to work with in logstash config
88
+ event["docker"] = DockerHash.new
89
+ event["docker"][:id] = metadata['id']
90
+ event["docker"][:name] = metadata['Name']
91
+ event["docker"][:container_hostname] = metadata['Config']['Hostname'],
92
+ event["docker"][:image] = metadata['Config']['Image'],
93
+ event["docker"][:image_id] = metadata['Image'],
94
+ event["docker"][:labels] = metadata['Config']['Labels'],
95
+ event["docker"][:env] = self.format_env(metadata['Config']['Env'])
96
+
96
97
  end
97
98
 
98
99
  # filter_matched should go in the last line of our successful code
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-docker_metadata'
3
- s.version = '0.1.4'
3
+ s.version = '0.1.5'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "This filter add docker metadata to messages that contain a docker ID. It's heavily inspired from https://github.com/fabric8io/fluent-plugin-docker_metadata_filter."
6
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"
@@ -18,10 +18,11 @@ Gem::Specification.new do |s|
18
18
  s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
19
19
 
20
20
  # Gem dependencies
21
- s.add_runtime_dependency "logstash-core", '>= 1.4.0', '< 2.0.0'
22
- s.add_runtime_dependency 'docker-api'
23
- s.add_runtime_dependency 'lru_redux'
24
- s.add_runtime_dependency 'json'
21
+ s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
22
+ s.add_runtime_dependency 'docker-api'
23
+ s.add_runtime_dependency 'lru_redux'
24
+ s.add_runtime_dependency 'json'
25
+ s.add_runtime_dependency 'hashie'
25
26
 
26
27
  s.add_development_dependency 'logstash-devutils'
27
28
  end
@@ -1,20 +1,44 @@
1
- require 'spec_helper'
2
- require "logstash/filters/dockerMetadata"
1
+ require_relative "../spec_helper"
2
+ require "logstash/filters/docker_metadata"
3
3
 
4
- describe LogStash::Filters::dockerMetadata do
5
- describe "Set to Hello World" do
4
+ describe LogStash::Filters::DockerMetadata do
5
+
6
+ let(:container_info) do
7
+ metadata = {}
8
+ metadata['id'] = "123456789"
9
+ metadata['Name'] = "container"
10
+ metadata['Image'] = "image_id"
11
+ metadata['Config'] = {}
12
+ metadata['Config']['Hostname'] = "hostname"
13
+ metadata['Config']['Image'] = "image"
14
+ metadata['Config']['Labels'] = { "label1" => "label_value"}
15
+ metadata['Config']['Env'] = [
16
+ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
17
+ "NGINX_VERSION=1.9.5-1~jessie"
18
+ ]
19
+ metadata
20
+ end
21
+
22
+
23
+ describe "Docker container metadada as symbol keys in hash by default" do
6
24
  let(:config) do <<-CONFIG
7
25
  filter {
8
26
  docker_metadata {
9
-
27
+
10
28
  }
11
29
  }
12
30
  CONFIG
13
31
  end
14
32
 
15
- sample("message" => "some text") do
16
- expect(subject).to include("message")
17
- expect(subject['message']).to eq('Hello World')
33
+ sample("path" => "/var/lib/docker/containers/d58155b6b2979776ef3594838536375ec19c6452431888f1d71bb7b2d5b8d84b/d58155b6b2979776ef3594838536375ec19c6452431888f1d71bb7b2d5b8d84b-json.log") do
34
+ c = double()
35
+ expect(Docker::Container).to receive(:get).with('d58155b6b2979776ef3594838536375ec19c6452431888f1d71bb7b2d5b8d84b').and_return(c)
36
+ expect(c).to receive(:info).and_return(container_info)
37
+
38
+ expect(subject['docker']).not_to be_nil
39
+ expect(subject['docker']['name']).to eq('container')
40
+ expect(subject['docker']['name']).to eq(subject['docker'][:name])
41
+ expect(subject['docker']['env']['NGINX_VERSION']).to eq('1.9.5-1~jessie')
18
42
  end
19
43
  end
20
44
  end
metadata CHANGED
@@ -1,24 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-docker_metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-05 00:00:00.000000000 Z
11
+ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - '>='
17
17
  - !ruby/object:Gem::Version
18
- version: 1.4.0
18
+ version: 2.0.0
19
19
  - - <
20
20
  - !ruby/object:Gem::Version
21
- version: 2.0.0
21
+ version: 3.0.0
22
22
  name: logstash-core
23
23
  prerelease: false
24
24
  type: :runtime
@@ -26,10 +26,10 @@ dependencies:
26
26
  requirements:
27
27
  - - '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 1.4.0
29
+ version: 2.0.0
30
30
  - - <
31
31
  - !ruby/object:Gem::Version
32
- version: 2.0.0
32
+ version: 3.0.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - '>='
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ name: hashie
82
+ prerelease: false
83
+ type: :runtime
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
75
89
  - !ruby/object:Gem::Dependency
76
90
  requirement: !ruby/object:Gem::Requirement
77
91
  requirements:
@@ -99,6 +113,7 @@ files:
99
113
  - README.md
100
114
  - Rakefile
101
115
  - dockerTest.sh
116
+ - lib/logstash/filters/docker_hash.rb
102
117
  - lib/logstash/filters/docker_metadata.rb
103
118
  - logstash-filter-docker_metadata.gemspec
104
119
  - setup.sh