influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.6k stars 5.57k forks source link

inputs.http cookie_auth_headers cannot unmarshal TOML string into map[string]string #11134

Closed antitbone closed 2 years ago

antitbone commented 2 years ago

Relevant telegraf.conf

# isilon

[[inputs.http]]
  urls = [
    "https://isilon:8080/platform/1/snapshot/snapshots-summary"
  ]

  cookie_auth_url = "https://isilon:8080/session/1/session"
  cookie_auth_method = "POST"
  cookie_auth_headers = '{"Content-Type": "application/json"}'
  cookie_auth_body = '{"username": "XXX", "password": "XXX, "services": ["platform"]}'
  cookie_auth_renewal = "6h"

  name_override = "snapshots"
  insecure_skip_verify = true
  data_format = "json"
  [inputs.http.tags]
    isilon_host = "isilon"

[[outputs.influxdb]]
  urls = ["http://influx:8086"]
  database = "XXX"
  username = "XXX"
  password = "XXX"
  skip_database_creation = true
  [outputs.influxdb.tagpass]
    isilon_host  = ["isilon"]

Logs from Telegraf

2022-05-18T15:11:18Z E! [telegraf] Error running agent: Error loading config file /etc/telegraf/telegraf.d/isilon-dna.conf: error parsing http, line 10: (http.HTTP.Headers) cannot unmarshal TOML string into map[string]string

System info

telegraf-1.22.4

the "cookie_auth_headers" parameter does not seem to work

The error also occurs with the default parameter:

cookie_auth_headers = '{"Content-Type": "application/json", "X-MY-HEADER":"hello"}'
curl -ik https://isilonr:8080/session/1/session -X POST -H 'Content-Type: application/json' -d '{ "username": "XXX", "password": "XXX", "services": ["platform"] }'

HTTP/1.1 201 Created
Date: Wed, 18 May 2022 15:15:16 GMT
Server: Apache
X-Frame-Options: sameorigin
Strict-Transport-Security: max-age=31536000;
Set-Cookie: isisessid=17a4416e-52ee-4dc3-b33c-c6cf1cf91e69; path=/; HttpOnly; Secure; SameSite=strict
Set-Cookie: isicsrf=bb8b666a-acd5-4294-b30f-fff134529e29; path=/; Secure
Content-Length: 92
Content-Type: application/json
powersj commented 2 years ago

Hi,

I believe you are trying to use a string, when you should be using a map like this:

 cookie_auth_body = {"username" = "XXX", "password" = "XXX, "services" = ["platform"]}

Can you give that a try? we may need to update the example config.

antitbone commented 2 years ago

The error remains the same.

2022-05-23T06:19:13Z E! [telegraf] Error running agent: Error loading config file /etc/telegraf/telegraf.conf: Error parsing data: line 11: invalid TOML syntax

I deleted any configuration other than the lines below.

[[inputs.http]]
  urls = [
    "https://isilon:8080/platform/1/snapshot/snapshots-summary"
  ]

  cookie_auth_url = "https://isilon:8080/session/1/session"
  cookie_auth_method = "POST"
  cookie_auth_headers = '{"Content-Type": "application/json"}'
  cookie_auth_body = {"username": "XXXX", "password": "XXXX", "services": ["platform"]}
  cookie_auth_renewal = "6h"

  name_override = "snapshots"
  insecure_skip_verify = true
  data_format = "json"
  [inputs.http.tags]
    isilon_host = "isilon"

[[outputs.influxdb]]
  urls = ["http://influx:8086"]
  database = "isilon"
  username = "isilon"
  password = "XXX"
  skip_database_creation = true
  [outputs.influxdb.tagpass]
    isilon_host  = ["isilon"]
powersj commented 2 years ago

{"username": "XXXX", "password": "XXXX", "services": ["platform"]}

Ah if I had slowed down a bit more I would have noticed that these are not all strings. It is assumed that the body is a string key and value and that platform is not a string, but an array.

telegraf-tiger[bot] commented 2 years ago

Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Page. Thank you!

antitbone commented 2 years ago

A very late response.

With the TOML syntax the parameter cookie_auth_headers is valid.

cookie_auth_headers = { Content-Type = "application/json"}
cookie_auth_body = '{"username": "XXX", "password": "XXX", "services": ["platform"]}'

The plugin.http documentation can be updated to not mislead: https://github.com/influxdata/telegraf/blob/379b8ea04e8df8017611316cb9069cdf8f1512b9/plugins/inputs/http/sample.conf#L50 https://github.com/influxdata/telegraf/blob/379b8ea04e8df8017611316cb9069cdf8f1512b9/plugins/inputs/http/README.md?plain=1#L61

# cookie_auth_headers = '{"Content-Type": "application/json", "X-MY-HEADER":"hello"}'

A second problem occurs with authentication. Dell isilon array returns http code 201.

2022-07-01T12:47:20Z E! [telegraf] Error running agent: could not initialize input inputs.http: cookie auth renewal received status code: 201 (Created)
StatusOK                   = 200 // RFC 7231, 6.3.1
StatusCreated            = 201 // RFC 7231, 6.3.2

But the test only accepts code 200 https://github.com/influxdata/telegraf/blob/379b8ea04e8df8017611316cb9069cdf8f1512b9/plugins/common/cookie/cookie.go#L113-L118

powersj commented 2 years ago

Hi,

The plugin.http documentation can be updated to not mislead:

Can you confirm you are suggesting this change:

--- cookie_auth_headers = '{"Content-Type": "application/json", "X-MY-HEADER":"hello"}' 
+++ cookie_auth_headers = { Content-Type = "application/json" }

But the test only accepts code 200

I think checking for 201 is something we could change. Let me know about the doc change.

antitbone commented 2 years ago

I suggest this change

--- cookie_auth_headers = '{"Content-Type": "application/json", "X-MY-HEADER":"hello"}' 
+++ cookie_auth_headers = { Content-Type = "application/json", X-MY-HEADER = "hello" }
powersj commented 2 years ago

@antitbone can you take a look at https://github.com/influxdata/telegraf/pull/11472?

Thanks!