Skip to content

Commit fd4fd78

Browse files
committed
Fix broken sniffing code
1 parent 840a8d0 commit fd4fd78

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

lib/logstash/outputs/elasticsearch/http_client/manticore_adapter.rb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,8 @@ def perform_request(url, method, path, params={}, body=nil)
2727
params[:body] = body if body
2828
url_and_path = (url + path).to_s # Convert URI object to string
2929

30-
case method
31-
when :get
32-
resp = @manticore.get(url_and_path, params)
33-
when :head
34-
resp = @manticore.head(url_and_path, params)
35-
when :put
36-
resp = @manticore.put(url_and_path, params)
37-
when :post
38-
resp = @manticore.post(url_and_path, params)
39-
when :delete
40-
resp = @manticore.delete(url_and_path, params)
41-
else
42-
raise ArgumentError.new "Method #{method} not supported"
43-
end
30+
31+
resp = @manticore.send(method.downcase, url_and_path, params)
4432

4533
# Manticore returns lazy responses by default
4634
# We want to block for our usage, this will wait for the repsonse

lib/logstash/outputs/elasticsearch/http_client/pool.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def sniff!
130130
ES2_SNIFF_RE_URL = /([^\/]*)?\/?([^:]*):([0-9]+)/
131131
# Sniffs and returns the results. Does not update internal URLs!
132132
def check_sniff
133-
resp = perform_request('GET', '_nodes')
133+
url, resp = perform_request('GET', '_nodes')
134134
parsed = LogStash::Json.load(resp.body)
135135
parsed['nodes'].map do |id,info|
136136
# TODO Make sure this works with shield. Does that listed
@@ -146,11 +146,11 @@ def check_sniff
146146
attributes = info['attributes']
147147
next if attributes && attributes['data'] == 'false'
148148

149-
matches = addr_str.match(ES1_RE_URL) || addr_str.match(ES2_RE_URL)
149+
matches = addr_str.match(ES1_SNIFF_RE_URL) || addr_str.match(ES2_SNIFF_RE_URL)
150150
if matches
151151
host = matches[1].empty? ? matches[2] : matches[1]
152152
port = matches[3]
153-
info.merge :host => host, :port => port, :id => id
153+
URI.parse("#{@scheme}://#{host}:#{port}")
154154
end
155155
end.compact
156156
end

0 commit comments

Comments
 (0)