logstash version : 6.3.1
curl -k -v -i -u 'API Key for V3':'API Secret for V3' 'https://api.com/v3/token' -d 'grant_type=password&username=&password=< Password>&scope=< Area UUID>'
Using above curl command I am able to connect to server.
I need to transform curl command to logstash http_poller plugin format.After doing the changes, I couldn't establish the connection.
Could you pleease let me where I am doing mistake.
Do I sent request body data in add_field ??? If not how to sent request body data in http_poller plugin during the request
input {
http_poller {
urls => {
test => {
url => "https://api.com/v3/token"
method => post
headers => {
Accept => "application/json"
Content-Type=>"application/x-www-form-urlencoded"
Authorization => "Basic Oh4NXRilNGcWNidHdONjk="
}
user => "username"
password => "password"
# Adding request body data in add_field, is this correct
add_field =>{
"grant_type"=> "password"
"username'=> 'username"
"password'=> 'password"
"scope'=> '5caf04b4"
}
}
request_timeout => 60
schedule => { cron => "* * * * * UTC"}
codec => "json"
metadata_target => "http_poller_metadata"
}
}
}
same way i tried with http filter, but no luck .
I need to transform curl command to logstash http filter plugin format.After doing the changes, I couldn't establish the connection.
Could you pleease let me where I am doing mistake.
filter {
http {
url =>"https://api.com/v3/token"
verb =>"POST"
user =>"username"
password => "password"
headers => {
"Content-Type"=>"application/x-www-form-urlencoded"
"Accept" => "application/json"
}
#body_format => "json"
body => {
grant_type => "password"
username => "username"
password => "password"
scope => "5caf04b4"
}
target_body => "response_message"
}
}
Error showing , response_type or grant_type required when i am executing it in logstash http filter.
same way I tried with ruby filter, but no luck.
filter {
ruby{
code => "
require 'net/http'
require 'uri'
require 'json'
uri = URI('https://api.com/v3/token')
header = {'Content-Type'=>'application/x-www-form-urlencoded','Accept'=> 'application/json'}
request = Net::HTTP::Post.new(uri,header)
request.basic_auth '9xx5tyyyyy', 'xxxxxxxxxx69'
request.set_form_data({
'grant_type'=> 'password',
'username'=> 'username',
'password'=> 'passwordof user',
'scope'=> '5caf04b4'}
)
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
http.request(request)
end
event.set('response',response.body)
"
}
}
Error showing :[ERROR][logstash.filters.ruby] Ruby exception occurred: An existing connection was forcibly closed by the remote host