logstash-input-http 1.0.2 → 1.0.3

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: 34ad637b9e0f1ec241080767dabe27e43727f3ac
4
- data.tar.gz: 449a5cce6f0eb2c433408a35ca8d6cdbd9c80a54
3
+ metadata.gz: 926b7ec73541a14bbfd73aa3dd61f41fbc8befad
4
+ data.tar.gz: 95fa17563b93c0f59fb51679c4c776b1703f0ede
5
5
  SHA512:
6
- metadata.gz: 146e1fa095905455cbef0f915e57fcab08c5c751884c5dbc8dc4d73ece2ec0e403a8e1f90e9c220e88e2c02eccceeebe88a4d9e76bf430170903cb79a7ec63e1
7
- data.tar.gz: 84766bfd189c89c44c54087c5296ceaa962164251830c80e77066248b77dc3ba62007e60f76b37edfd3c129cc0a62a16e83c6a23f721fa2d45637abd4e613d25
6
+ metadata.gz: 3423047bb3e9f7649697e2882de6cf2776c656c2c03895b6fb01e37e78d27ee06e493fc2e966c6ee8a3b1461d708284b36bd211372dd7c57d403322c75bc1410
7
+ data.tar.gz: 0bbcb9985b09ac11d5463861805d6ea749307bdbfe4179030ab801a58992091dd21c6340c97379ce9b98b43530de39efa16fd30159770d21292ee5fe92f1b02b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.0.3 (September 2, 2015)
2
+ * Include remote host address to events (#25)
3
+
1
4
  ## 1.0.2 (July 28, 2015)
2
5
  * Fix for missing base64 require which was crashing Logstash (#17)
3
6
 
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # Logstash Plugin
2
2
 
3
- This is a plugin for [Logstash](https://github.com/elasticsearch/logstash).
3
+ This is a plugin for [Logstash](https://github.com/elastic/logstash).
4
4
 
5
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
6
 
7
7
  ## Documentation
8
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/).
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.elastic.co/guide/en/logstash/current/).
10
10
 
11
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
12
+ - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
13
13
 
14
14
  ## Need Help?
15
15
 
@@ -83,4 +83,4 @@ Programming is not a required skill. Whatever you've seen about open source and
83
83
 
84
84
  It is more important to the community that you are able to contribute.
85
85
 
86
- For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file.
86
+ For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
@@ -38,6 +38,8 @@ class LogStash::Inputs::Http < LogStash::Inputs::Base
38
38
  config_name "http"
39
39
 
40
40
  # Codec used to decode the incoming data.
41
+ # This codec will be used as a fall-back if the content-type
42
+ # is not found in the "additional_codecs" hash
41
43
  default :codec, "plain"
42
44
 
43
45
  # The host or ip to bind
@@ -66,8 +68,9 @@ class LogStash::Inputs::Http < LogStash::Inputs::Base
66
68
  # Set the truststore password
67
69
  config :keystore_password, :validate => :password
68
70
 
69
- # Here you can set how to decode specific content-types in the body of the request.
70
- # By default, the plain codec will be used
71
+ # Apply specific codecs for specific content types.
72
+ # The default codec will be applied only after this list is checked
73
+ # and no codec for the request's content-type is found
71
74
  config :additional_codecs, :validate => :hash, :default => { "application/json" => "json" }
72
75
 
73
76
  # useless headers puma adds to the requests
@@ -108,10 +111,12 @@ class LogStash::Inputs::Http < LogStash::Inputs::Base
108
111
  # to capture @codecs, @logger and lowercase_keys
109
112
  p = Proc.new do |req|
110
113
  begin
114
+ remote_host = req['puma.socket'].peeraddr[3]
111
115
  REJECTED_HEADERS.each {|k| req.delete(k) }
112
116
  req = lowercase_keys(req)
113
117
  body = req.delete("rack.input")
114
118
  @codecs.fetch(req["content_type"], @codec).decode(body.read) do |event|
119
+ event["host"] = remote_host
115
120
  event["headers"] = req
116
121
  decorate(event)
117
122
  queue << event
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-input-http'
3
- s.version = '1.0.2'
3
+ s.version = '1.0.3'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Logstash Input plugin that receives HTTP requests"
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"
@@ -6,20 +6,40 @@ require "stud/temporary"
6
6
 
7
7
  describe LogStash::Inputs::Http do
8
8
 
9
+ before do
10
+ srand(RSpec.configuration.seed)
11
+ end
12
+
9
13
  let(:agent) { FTW::Agent.new }
10
14
  let(:queue) { Queue.new }
15
+ let(:port) { rand(5000) + 1025 }
11
16
 
12
17
  after :each do
13
18
  subject.teardown
14
19
  end
15
20
 
16
- context "with default codec" do
21
+ describe "#run" do
17
22
  subject { LogStash::Inputs::Http.new }
23
+ before :each do
24
+ subject.register
25
+ Thread.new { subject.run(queue) }
26
+ end
27
+ it "should include remote host in \"host\" property" do
28
+ agent.post!("http://localhost:8080/meh.json",
29
+ :headers => { "content-type" => "text/plain" },
30
+ :body => "hello")
31
+ event = queue.pop
32
+ expect(event["host"]).to eq("127.0.0.1")
33
+ end
34
+ end
35
+
36
+ context "with default codec" do
37
+ subject { LogStash::Inputs::Http.new("port" => port) }
18
38
  context "when receiving a text/plain request" do
19
39
  it "should process the request normally" do
20
40
  subject.register
21
41
  Thread.new { subject.run(queue) }
22
- agent.post!("http://localhost:8080/meh.json",
42
+ agent.post!("http://localhost:#{port}/meh.json",
23
43
  :headers => { "content-type" => "text/plain" },
24
44
  :body => "hello")
25
45
  event = queue.pop
@@ -30,7 +50,7 @@ describe LogStash::Inputs::Http do
30
50
  it "should parse the json body" do
31
51
  subject.register
32
52
  Thread.new { subject.run(queue) }
33
- agent.post!("http://localhost:8080/meh.json",
53
+ agent.post!("http://localhost:#{port}/meh.json",
34
54
  :headers => { "content-type" => "application/json" },
35
55
  :body => { "message_body" => "Hello" }.to_json)
36
56
  event = queue.pop
@@ -40,23 +60,24 @@ describe LogStash::Inputs::Http do
40
60
  end
41
61
 
42
62
  context "with json codec" do
43
- subject { LogStash::Inputs::Http.new("codec" => "json") }
63
+ subject { LogStash::Inputs::Http.new("port" => port, "codec" => "json") }
44
64
  it "should parse the json body" do
45
65
  subject.register
46
66
  Thread.new { subject.run(queue) }
47
- agent.post!("http://localhost:8080/meh.json", :body => { "message" => "Hello" }.to_json)
67
+ agent.post!("http://localhost:#{port}/meh.json", :body => { "message" => "Hello" }.to_json)
48
68
  event = queue.pop
49
69
  expect(event["message"]).to eq("Hello")
50
70
  end
51
71
  end
52
72
 
53
73
  context "when using a custom codec mapping" do
54
- subject { LogStash::Inputs::Http.new("additional_codecs" => { "application/json" => "plain" }) }
74
+ subject { LogStash::Inputs::Http.new("port" => port,
75
+ "additional_codecs" => { "application/json" => "plain" }) }
55
76
  it "should decode the message accordingly" do
56
77
  body = { "message" => "Hello" }.to_json
57
78
  subject.register
58
79
  Thread.new { subject.run(queue) }
59
- agent.post!("http://localhost:8080/meh.json",
80
+ agent.post!("http://localhost:#{port}/meh.json",
60
81
  :headers => { "content-type" => "application/json" },
61
82
  :body => body)
62
83
  event = queue.pop
@@ -65,21 +86,21 @@ describe LogStash::Inputs::Http do
65
86
  end
66
87
 
67
88
  context "with :ssl => false" do
68
- subject { LogStash::Inputs::Http.new("ssl" => false) }
89
+ subject { LogStash::Inputs::Http.new("port" => port, "ssl" => false) }
69
90
  it "should not raise exception" do
70
91
  expect { subject.register }.to_not raise_exception
71
92
  end
72
93
  end
73
94
  context "with :ssl => true" do
74
95
  context "without :keystore and :keystore_password" do
75
- subject { LogStash::Inputs::Http.new("ssl" => true) }
96
+ subject { LogStash::Inputs::Http.new("port" => port, "ssl" => true) }
76
97
  it "should raise exception" do
77
98
  expect { subject.register }.to raise_exception(LogStash::ConfigurationError)
78
99
  end
79
100
  end
80
101
  context "with :keystore and :keystore_password" do
81
102
  let(:keystore) { Stud::Temporary.file }
82
- subject { LogStash::Inputs::Http.new("ssl" => true,
103
+ subject { LogStash::Inputs::Http.new("port" => port, "ssl" => true,
83
104
  "keystore" => keystore.path,
84
105
  "keystore_password" => "pass") }
85
106
  it "should not raise exception" do
@@ -89,14 +110,14 @@ describe LogStash::Inputs::Http do
89
110
  end
90
111
  describe "basic auth" do
91
112
  user = "test"; password = "pwd"
92
- subject { LogStash::Inputs::Http.new("user" => user, "password" => password) }
113
+ subject { LogStash::Inputs::Http.new("port" => port, "user" => user, "password" => password) }
93
114
  let(:auth_token) { Base64.strict_encode64("#{user}:#{password}") }
94
115
  before :each do
95
116
  subject.register
96
117
  Thread.new { subject.run(queue) }
97
118
  end
98
119
  context "when client doesn't present auth token" do
99
- let!(:response) { agent.post!("http://localhost:8080/meh", :body => "hi") }
120
+ let!(:response) { agent.post!("http://localhost:#{port}/meh", :body => "hi") }
100
121
  it "should respond with 401" do
101
122
  expect(response.status).to eq(401)
102
123
  end
@@ -106,7 +127,7 @@ describe LogStash::Inputs::Http do
106
127
  end
107
128
  context "when client presents incorrect auth token" do
108
129
  let!(:response) do
109
- agent.post!("http://localhost:8080/meh",
130
+ agent.post!("http://localhost:#{port}/meh",
110
131
  :headers => {
111
132
  "content-type" => "text/plain",
112
133
  "authorization" => "Basic meh"
@@ -122,7 +143,7 @@ describe LogStash::Inputs::Http do
122
143
  end
123
144
  context "when client presents correct auth token" do
124
145
  let!(:response) do
125
- agent.post!("http://localhost:8080/meh",
146
+ agent.post!("http://localhost:#{port}/meh",
126
147
  :headers => {
127
148
  "content-type" => "text/plain",
128
149
  "authorization" => "Basic #{auth_token}"
metadata CHANGED
@@ -1,18 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-input-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-29 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: logstash-core
15
- version_requirements: !ruby/object:Gem::Requirement
14
+ requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - '>='
18
17
  - !ruby/object:Gem::Version
@@ -20,7 +19,10 @@ dependencies:
20
19
  - - <
21
20
  - !ruby/object:Gem::Version
22
21
  version: 2.0.0
23
- requirement: !ruby/object:Gem::Requirement
22
+ name: logstash-core
23
+ prerelease: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
24
26
  requirements:
25
27
  - - '>='
26
28
  - !ruby/object:Gem::Version
@@ -28,92 +30,90 @@ dependencies:
28
30
  - - <
29
31
  - !ruby/object:Gem::Version
30
32
  version: 2.0.0
31
- prerelease: false
32
- type: :runtime
33
33
  - !ruby/object:Gem::Dependency
34
- name: logstash-codec-plain
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - '>='
38
- - !ruby/object:Gem::Version
39
- version: '0'
40
34
  requirement: !ruby/object:Gem::Requirement
41
35
  requirements:
42
36
  - - '>='
43
37
  - !ruby/object:Gem::Version
44
38
  version: '0'
39
+ name: logstash-codec-plain
45
40
  prerelease: false
46
41
  type: :runtime
47
- - !ruby/object:Gem::Dependency
48
- name: stud
49
42
  version_requirements: !ruby/object:Gem::Requirement
50
43
  requirements:
51
44
  - - '>='
52
45
  - !ruby/object:Gem::Version
53
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
54
48
  requirement: !ruby/object:Gem::Requirement
55
49
  requirements:
56
50
  - - '>='
57
51
  - !ruby/object:Gem::Version
58
52
  version: '0'
53
+ name: stud
59
54
  prerelease: false
60
55
  type: :runtime
61
- - !ruby/object:Gem::Dependency
62
- name: puma
63
56
  version_requirements: !ruby/object:Gem::Requirement
64
57
  requirements:
65
- - - ~>
58
+ - - '>='
66
59
  - !ruby/object:Gem::Version
67
- version: 2.11.3
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
68
62
  requirement: !ruby/object:Gem::Requirement
69
63
  requirements:
70
64
  - - ~>
71
65
  - !ruby/object:Gem::Version
72
66
  version: 2.11.3
67
+ name: puma
73
68
  prerelease: false
74
69
  type: :runtime
75
- - !ruby/object:Gem::Dependency
76
- name: logstash-devutils
77
70
  version_requirements: !ruby/object:Gem::Requirement
78
71
  requirements:
79
- - - '>='
72
+ - - ~>
80
73
  - !ruby/object:Gem::Version
81
- version: '0'
74
+ version: 2.11.3
75
+ - !ruby/object:Gem::Dependency
82
76
  requirement: !ruby/object:Gem::Requirement
83
77
  requirements:
84
78
  - - '>='
85
79
  - !ruby/object:Gem::Version
86
80
  version: '0'
81
+ name: logstash-devutils
87
82
  prerelease: false
88
83
  type: :development
89
- - !ruby/object:Gem::Dependency
90
- name: logstash-codec-json
91
84
  version_requirements: !ruby/object:Gem::Requirement
92
85
  requirements:
93
86
  - - '>='
94
87
  - !ruby/object:Gem::Version
95
88
  version: '0'
89
+ - !ruby/object:Gem::Dependency
96
90
  requirement: !ruby/object:Gem::Requirement
97
91
  requirements:
98
92
  - - '>='
99
93
  - !ruby/object:Gem::Version
100
94
  version: '0'
95
+ name: logstash-codec-json
101
96
  prerelease: false
102
97
  type: :development
103
- - !ruby/object:Gem::Dependency
104
- name: ftw
105
98
  version_requirements: !ruby/object:Gem::Requirement
106
99
  requirements:
107
100
  - - '>='
108
101
  - !ruby/object:Gem::Version
109
102
  version: '0'
103
+ - !ruby/object:Gem::Dependency
110
104
  requirement: !ruby/object:Gem::Requirement
111
105
  requirements:
112
106
  - - '>='
113
107
  - !ruby/object:Gem::Version
114
108
  version: '0'
109
+ name: ftw
115
110
  prerelease: false
116
111
  type: :development
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
117
  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
118
118
  email: info@elastic.co
119
119
  executables: []
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  requirements: []
155
155
  rubyforge_project:
156
- rubygems_version: 2.2.2
156
+ rubygems_version: 2.4.5
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: Logstash Input plugin that receives HTTP requests