influxdata / telegraf

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

Error when table `inputs.http_response.headers' is in conflict with normal table #5635

Closed Gelob closed 1 year ago

Gelob commented 5 years ago

Relevant telegraf.conf:

System info:

telegraf v1.10.1-1 CentOS Linux release 7.6.1810 (Core)

Steps to reproduce:

Since inputs.http_response doesn't support multiple addresses in an array like inputs.http (https://github.com/influxdata/telegraf/issues/2294) (this really should be fixed) you have to setup multiple inputs. However when setting up multiple inputs while also using inputs.http_response.headers I get an error about a conflict from the previous input.

I read https://github.com/influxdata/telegraf/issues/4098 but that deals with inputs.http and inputs.http_response documentation already suggest not using non-inline table syntax. Even using inline table syntax the issue still occurs. I'm not sure if https://github.com/influxdata/telegraf/pull/5513 would fix this either

[[inputs.http_response]]
  address = "https://10.1.1.251/restconf/data/Cisco-IOS-XE-native:native/hostname"
  method = "GET"
  response_string_match = "Cisco-IOS-XE-native:hostname.: \"CSR1000v\""
  insecure_skip_verify = true
  [inputs.http_response.headers]
    Content-Type = "application/yang-data+json"
    Accept = "application/yang-data+json"
    Authorization = "Basic passwordremoved"

[[inputs.http_response]]
  address = "https://10.1.1.252/restconf/data/Cisco-IOS-XE-native:native/hostname"
  method = "GET"
  response_string_match = "Cisco-IOS-XE-native:hostname.: \"CSR1000v\""
  insecure_skip_verify = true`
  [inputs.http_response.headers]
    Content-Type = "application/yang-data+json"
    Accept = "application/yang-data+json"
    Authorization = "Basic passwordremoved"

Expected behavior:

Telegraf should run without errors and process both inputs.http_response plugins and their headers.

When run with just 1 input plugin everything is successful

[root@Smyserver~]# telegraf --config /etc/telegraf/telegraf.conf --input-filter http_response --test
2019-03-26T13:56:39Z I! Starting Telegraf 1.10.1
> http_response,method=GET,result=success,server=https://10.1.1.251/restconf/data/Cisco-IOS-XE-native:native/hostname,status_code=200 http_response_code=200i,response_string_match=1i,response_time=0.134175048,result_code=0i,result_type="success" 1553608600000000000

Actual behavior:

Error occurs:

[root@myserver ~]# telegraf --config /etc/telegraf/telegraf.conf --input-filter http_response --test
2019-03-26T13:47:14Z I! Starting Telegraf 1.10.1
2019-03-26T13:47:14Z E! [telegraf] Error running agent: Error parsing /etc/telegraf/telegraf.conf, toml: line 387: table `inputs.http_response.headers' is in conflict with normal table in line 377
danielnelson commented 5 years ago

Your configuration works for me, though there was a stray backtick that needs removed in the second plugin. Here is a complete working config you can run:

[[inputs.http_response]]
  address = "https://10.1.1.251/restconf/data/Cisco-IOS-XE-native:native/hostname"
  method = "GET"
  response_string_match = "Cisco-IOS-XE-native:hostname.: \"CSR1000v\""
  insecure_skip_verify = true
  [inputs.http_response.headers]
    Content-Type = "application/yang-data+json"
    Accept = "application/yang-data+json"
    Authorization = "Basic passwordremoved"

[[inputs.http_response]]
  address = "https://10.1.1.252/restconf/data/Cisco-IOS-XE-native:native/hostname"
  method = "GET"
  response_string_match = "Cisco-IOS-XE-native:hostname.: \"CSR1000v\""
  insecure_skip_verify = true
  [inputs.http_response.headers]
    Content-Type = "application/yang-data+json"
    Accept = "application/yang-data+json"
    Authorization = "Basic passwordremoved"

[[outputs.file]]
  files = ["stdout"]
Gelob commented 5 years ago

@danielnelson the stray backtick was a typo here but not in my actual config. I put the above config into a new file and it worked, however I have more than this configuration in my full telegraf.conf. I also have an inputs.http plugin enabled and when I include that above this configuration I get the error. See below for full config.

[[inputs.http]]
  urls = [
    "https://10.1.1.251/restconf/data/Cisco-IOS-XE-native:native/hostname",
    "https://10.1.1.252/restconf/data/Cisco-IOS-XE-native:native/hostname"
  ]
   method = "GET"
   headers = {"Content-Type" = "application/yang-data+json","Accept" = "application/yang-data+json"}
   username = "username"
   password = "password"
   insecure_skip_verify = true
   name_override = "cisco_restconf"
   json_string_fields = ["Cisco-IOS-XE-native:hostname"]
   data_format = "json"
   [inputs.file.tags]
     tag1 = "hostname"

[[inputs.http_response]]
  address = "https://10.1.1.251/restconf/data/Cisco-IOS-XE-native:native/hostname"
  method = "GET"
  response_string_match = "Cisco-IOS-XE-native:hostname.: \"CSR1000v\""
  insecure_skip_verify = true
  [inputs.http_response.headers]
    Content-Type = "application/yang-data+json"
    Accept = "application/yang-data+json"
    Authorization = "Basic passwordremoved"

[[inputs.http_response]]
  address = "https://10.1.1.252/restconf/data/Cisco-IOS-XE-native:native/hostname"
  method = "GET"
  response_string_match = "Cisco-IOS-XE-native:hostname.: \"CSR1000v\""
  insecure_skip_verify = true
  [inputs.http_response.headers]
    Content-Type = "application/yang-data+json"
    Accept = "application/yang-data+json"
    Authorization = "Basic passwordremoved"
danielnelson commented 5 years ago

Interesting, I didn't know it would conflict across table types. For the record the workaround is to use only non-inline tables throughout the config. Also I spotted an issue in the naming of the tag table, corrected below:

 [[inputs.http]]
   urls = [
     "https://10.1.1.251/restconf/data/Cisco-IOS-XE-native:native/hostname",
     "https://10.1.1.252/restconf/data/Cisco-IOS-XE-native:native/hostname"
   ]
    method = "GET"
-   headers = {"Content-Type" = "application/yang-data+json","Accept" = "application/yang-data+json"}
    username = "username"
    password = "password"
    insecure_skip_verify = true
    name_override = "cisco_restconf"
    json_string_fields = ["Cisco-IOS-XE-native:hostname"]
    data_format = "json"
+   [inputs.http.headers]
+     Content-Type = "application/yang-data+json"
+     Accept = "application/yang-data+json"
+   [inputs.http.tags]
+     tag1 = "hostname"

@glinton We should add a unit test for the mixed table case to #5513, if it fails then we should probably purge this style from the sample config for now.

sandeep11823 commented 4 years ago

I am getting the answer i want to upload it in influx now

powersj commented 1 year ago

Going through old issues and trying to reproduce this. I went as far back as telegraf v1.14.0 and found that the config in this comment with both inputs.http and 2x inputs.http_response works as expected.

Closing as fixed, but if someone comes across something similar please file a new issue using the latest telegraf, and provide a full config to reproduce.

Thanks!