File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 6161 let ( :curl_opts ) { nil }
6262
6363 def curl_and_get_json_response ( url , method : :get ) ; require 'open3'
64+ cmd = "curl -s -v --show-error #{ curl_opts } -X #{ method . to_s . upcase } -k #{ url } "
6465 begin
65- stdout , status = Open3 . capture2 ( "curl -s --show-error #{ curl_opts } -X #{ method . to_s . upcase } -k #{ url } " )
66+ out , err , status = Open3 . capture3 ( cmd )
6667 rescue Errno ::ENOENT
6768 fail "curl not available, make sure curl binary is installed and available on $PATH"
6869 end
6970
7071 if status . success?
71- LogStash ::Json . load ( stdout )
72+ http_status = err . match ( /< HTTP\/ 1.1 (.*?)/ ) [ 1 ] || '0' # < HTTP/1.1 200 OK\r\n
73+ if http_status [ 1 ] . strip [ 0 ] . to_i > 2
74+ warn out
75+ fail "#{ cmd . inspect } unexpected response: #{ http_status } \n \n #{ err } "
76+ end
77+
78+ LogStash ::Json . load ( out )
7279 else
73- fail "curl failed: #{ status } \n #{ stdout } "
80+ warn out
81+ fail "#{ cmd . inspect } process failed: #{ status } \n \n #{ err } "
7482 end
7583 end
7684
You can’t perform that action at this time.
0 commit comments