Send Headers in HTTP post request

Hi All,

I am not able to send additional headers in the http POST request.

yml file

heartbeat.monitors:

  • type: http

    List or urls to query

    #urls:
    urls: ["http://localhost:8724/service/XXX/YYY"]

    request details:

    check.request.method: POST
    check.request.headers: 'soapaction': '/Processes/XXXX'
    check.request.body: 'XXX'

    Configure task schedule

    schedule: '@every 10s'

Able to see the body in the request received by the service but the header is not sent.

Any help is appreciated.

Can you try with newline like this?

heartbeat.monitors:
- type: http
# List or urls to query
  urls: ["http://localhost:8724/service/XXX/YYY"]
  # request details:
  check.request.method: POST
  check.request.headers:
    soapaction: '/Processes/XXXX'
  check.request.body: 'XXX'
  # Configure task schedule
  schedule: '@every 10s'

Can you share the debug log from starting heartbeat in foreground with -e -d '*,config'?

Did you check with wireshark the header is missing?

Hi Steffen,

Thank you. The new line helped fix the issue.

here is the updated Config I used with multiple elements in header defined for URL.

#URL :
urls: ["http://localhost:9394/service/XXX/YYY"]
# request details:
check.request.method: POST
check.request.headers:
     soapaction: '/Processes/XXX'
     content-type: 'text/xml;charset=UTF-8'
check.request.body: 'XXXXX'

Is it possible to define multiple URL's and each URL having unique set of additional headers and body? How would we define this.

Thank you.
Suvitt

this is not possible. You basically want/need to define multiple monitors. Using dynamic reloading feature in heartbeat, you can have multiple json objects with url + headers/body. But note, dynamic reloading as is will change to match reloading functionality in filebeat/metricbeat in the future.

Hi Steffen,

Thanks , defining multiple monitors did the trick.

here is the sample I used.

heartbeat.monitors:
- type: http
  ##Sample SOAP/HTTP
  urls: ["http://localhost:8724/service/XXX/YYY"]
  check.request.method: POST
  check.request.headers:
    soapaction: '/Processes/XXXX'
	accept-encoding: 'gzip,deflate'
    content-type: 'text/xml;charset=UTF-8'
  check.request.body: '<SOAP message>'
  schedule: '@every 10s'
- type: http
  ##Sample rest api
  urls: ["http://localhost:8725/api/XXX/YYY"]
  check.request.method: POST
  check.request.headers:
    content-type: 'application/json'
    accept-encoding: 'gzip,deflate'
  check.request.body: '<json message>' 
  schedule: '@every 10s'

Thanks for the help.

One more tip: you might want to 'indicate' the different monitoring types for filtering in Kibana (or via Elasticsearch API). In the future you might be able to make use of this (open ticket), but for now using name will set the event type field to the name configured (to be improved according to this ticket)

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.