Cannot add custom headers to http poll input in logstash


(Matt617) #1

trying to get data from the uber API to come to stdout (just as an initial test) but cannot seem to get the authorization through the HTTP Header. tried the code below. i think i am close but what am i doing wrong?

input {
  http_poller {
    urls => {
      test2 => {
        # Supports all options supported by ruby's Manticore HTTP client
        method => get
     url => "https://api.uber.com/v1/products?latitude=37.7759792&longitude=-122.41823"
        auth => {
        user => ""
        password => "P8YegbF53nWPZST5xX0ZlktVnufXYYQa01Dy0ocm"
        }
      }
    }
    request_timeout => 60
    interval => 60
    codec => "json"
    # A hash of request metadata info (timing, response headers, etc.) will be sent here
    metadata_target => "http_poller_metadata"
  }
}


output {
    stdout {}
}

also tried

input {
  http_poller {
    urls => {
      test2 => {
        # Supports all options supported by ruby's Manticore HTTP client
        method => get
     url => "https://api.uber.com/v1/products?latitude=37.7759792&longitude=-122.41823"
                headers => {
                Authorization => "P8YegbF53nWPZST5xX0ZlktVnufXYYQa01Dy0ocm"
                }
      }
    }
    request_timeout => 60
    interval => 60
    codec => "json"
    # A hash of request metadata info (timing, response headers, etc.) will be sent here
    metadata_target => "http_poller_metadata"
  }
}


output {
    stdout {}
}

(Nestor Manrique) #2

I know this post is kind of old but I was facing the same problem until I realized that for some reason I had to wrap the other headers between quotes, although the Accept header don't seem to need them.

This configuration yields syntax errors in /var/log/logstash/logstash-plain.log

input{
    http_poller{
        urls => {
            myurl => {
                url => "https://server:port/"
                headers => {
                    Accept => "application/json"
                    Content-Type => "application/json"
                }
            }
...
}

This configuration works perfectly. Note the double quotes in Content-type header.

input{
    http_poller{
        urls => {
            myurl => {
                url => "https://server:port/"
                headers => {
                    Accept => "application/json"
                    "Content-Type" => "application/json"
                }
            }
...
}

Hope this helps other people.


(system) #3