I’m trying to configure HTTP input plugin in telegraf using JSON, a string is obtained at the end and telegraf returns the error:
Query path must lead to a JSON object, array of objects or null, but lead to: String
My configuration:
[[inputs.http]]
urls = [
"https://localhost:8080"
]
method = "POST"
headers = {"content-type" = "application/json"}
insecure_skip_verify = true
password = 'telegraf'
username = 'verysecpass'
body = '{"count":200,"encoding":"auto"}'
data_format = "json"
json_query = '#(properties.headers.database=="stats").payload'
[[outputs.influxdb]]
content_encoding = 'identity'
database = 'stats'
urls = ['http://localhost:8086']
Input:
[
{
"properties": {
"headers": {
"database": "telegraf"
},
"content_type": "text/plain"
},
"payload": "net,cluster_id=cluster01,dc=dc02,host=specific_host01,instance=instance-00107205 network_write_packets=15100740,network_write_drops=0 1628285530000000000\n",
"payload_encoding": "string"
},
{
"properties": {
"headers": {
"database": "stats"
},
"content_type": "text/plain"
},
"payload": "dsk_stats,Region=Q3,host=specific_host01 disk_usage=8.344534641 1628285530000000000\n",
"payload_encoding": "string"
}
]
After json_jquery
is executed, the output will be:
dsk_stats,Region=Q3,host=specific_host01 disk_usage=8.344534641 1628285530000000000
This is really what I want to forward to InfluxDB. How can I avoid the telegraf error by using json, while getting a string?