-
Notifications
You must be signed in to change notification settings - Fork 5.8k
inputs.http does not set Content-Length header correctly #11034
Copy link
Copy link
Closed
Labels
bugunexpected problem or unintended behaviorunexpected problem or unintended behaviorplugin/input1. Request for new input plugins 2. Issues/PRs that are related to input plugins1. Request for new input plugins 2. Issues/PRs that are related to input plugins
Description
Relevant telegraf.conf
[[inputs.http]]
## List of urls to query.
urls = ["URL_WAS_HERE"]
## HTTP Request Method
method = "POST"
## Optional HTTP headers
headers = {"Content-Length" = "50"}
## Optional HTTP Request Body
body = '''{"F_":"LOGIN","DATA":{"ID":"guest","PWD":"guest"}}'''
## Optional TLS Config
insecure_skip_verify = trueLogs from Telegraf
root@servername:~# telegraf --config /etc/telegraf/telegraf.d/http_input_login_V85NX_test.conf --test --debug
2022-04-26T11:09:35Z I! Starting Telegraf 1.22.2
2022-04-26T11:09:35Z I! Loaded inputs: http
2022-04-26T11:09:35Z I! Loaded aggregators:
2022-04-26T11:09:35Z I! Loaded processors:
2022-04-26T11:09:35Z W! Outputs are not used in testing mode!
2022-04-26T11:09:35Z I! Tags enabled: host=servername
2022-04-26T11:09:35Z D! [agent] Initializing plugins
2022-04-26T11:09:35Z D! [agent] Starting service inputs
2022-04-26T11:09:38Z E! [inputs.http] Error in plugin: [url=URL_WAS_HERE]: received status code 411 (Length Required), expected any value out of [200]
2022-04-26T11:09:38Z D! [agent] Stopping service inputs
2022-04-26T11:09:38Z D! [agent] Input channel closed
2022-04-26T11:09:38Z D! [agent] Stopped Successfully
2022-04-26T11:09:38Z E! [telegraf] Error running agent: input plugins recorded 1 errors
System info
Telegraf: 1.22.2 , Operating System: Debian GNU/Linux 11 (bullseye), Kernel: Linux 5.10.0-8-amd64
Docker
No response
Steps to reproduce
- Tried the above config with no optional headers - Error code 411
- Adding a optional HTTP header with Content-length does not work either - Error code 411
- Tried using body=1 and Content-length =1, still same result. - Error code 411
- Tried body=1 and Content-length =1 with cURL and get error code 500 (As expected).
Expected behavior
Reply from API with JSON containing login details.
{
"RESULT": 1,
"SID": 19463950,
"LEVEL": "GUEST"
}Actual behavior
Reply is:
Error in plugin: [url=URL_WAS_HERE]: received status code 411 (Length Required), expected any value out of [200]
Additional info
Trying to pull data from an API that requires the Content-Length header in the POST request.
Tried with similiar .conf file using the HTTP_Response inputs plugin and this works as intended towards the same API endpoint.
.conf file:
[[inputs.http_response]]
## List of urls to query.
urls = ["URL_WAS_HERE"]
## HTTP Request Method
method = "POST"
## Optional HTTP Request Body
body = '{"F_":"LOGIN","DATA":{"ID":"guest","PWD":"guest"}}'
response_body_field = 'Test'
insecure_skip_verify = trueResponse:
root@servername:~# telegraf --config /etc/telegraf/telegraf.d/http_response_login_V85NX_test.conf --test --debug
2022-04-26T11:15:02Z I! Starting Telegraf 1.22.2
2022-04-26T11:15:02Z I! Loaded inputs: http_response
2022-04-26T11:15:02Z I! Loaded aggregators:
2022-04-26T11:15:02Z I! Loaded processors:
2022-04-26T11:15:02Z W! Outputs are not used in testing mode!
2022-04-26T11:15:02Z I! Tags enabled: host=servername
2022-04-26T11:15:02Z D! [agent] Initializing plugins
2022-04-26T11:15:02Z D! [agent] Starting service inputs
2022-04-26T11:15:05Z D! [agent] Stopping service inputs
> http_response,host=servername,method=POST,result=success,server=URL_WAS_HERE,status_code=200 Test="{
\"RESULT\": 1,
\"SID\": 19463950,
\"LEVEL\": \"GUEST\"
}",content_length=53i,http_response_code=200i,response_time=3.100586043,result_code=0i,result_type="success" 1650971706000000000
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugunexpected problem or unintended behaviorunexpected problem or unintended behaviorplugin/input1. Request for new input plugins 2. Issues/PRs that are related to input plugins1. Request for new input plugins 2. Issues/PRs that are related to input plugins