Can somebody help to get the output of this script sent to influxdb via input.exec?

I would like to use input.exec to monitor lxc server status.
Here is my script and result but I am not able to send to influxdb as json format or other format.
Can someone help me to do so ?
I appreciate any help !! Tks in advance …

root@server16:/home/monitor# ./lxclist.sh
{“name”:“tm-infraestrutura16-r2-sp2”,“architecture”:“x86_64”,“type”:“container”,“state”:“Running”}
{“name”:“tm-marketdata16-r2-sp2”,“architecture”:“x86_64”,“type”:“container”,“state”:“Running”}
{“name”:“tradeserver16-proxy-prov-r1-sp2”,“architecture”:“x86_64”,“type”:“container”,“state”:“Running”}
{“name”:“tradeserver16-r1-sp2”,“architecture”:“x86_64”,“type”:“container”,“state”:“Running”}
{“name”:“tradeserver16-r2-sp2”,“architecture”:“x86_64”,“type”:“container”,“state”:“Running”}
This is the script I will use in telegraf input.exec.

root@server16:/home/monitor# cat lxclist.sh
#!/bin/bash
#lxc list --format=json | jq ‘.result |{ .name + " | " + .architecture + " | " + .type + " | " + .state.status}’
#lxc list --format=json | jq -r ‘. | " { " + | .name + " | " + .architecture + " | " + .type + " | " + .state.status + | " } "’
#jq ‘.result |{hosts: .certificates.hosts, status: .status, expires_on: .certificates.expires_on}’
#lxc list --format=json | jq ‘. | .name + " | " + .state.status’
#output=$(lxc list -c ns --format csv)

#echo ‘[{ ‘$output’ } ]’
#lxc list -c ns --format=csv
lxc list --format=json | jq -c ‘. | select(.state.status == “Running”) | {name: .name, architecture: .architecture, type: .type, state: .state.status}’

Here is my script and result but I am not able to send to influxdb as json format or other format.
Can someone help me to do so ?

Can you share your telegraf configuration file and what errors you are getting?

Sure … I will get the files and let you know.
Tks in advance …

Here is the script:

#!/bin/bash
#lxc list --format=json | jq '.result[] |{ .name + " | " + .architecture + " | " + .type + " | " + .state.status}'
#lxc list --format=json | jq -r '.[] | " { " + | .name + " | " + .architecture + " | " + .type + " | " + .state.status + | " } "'
#jq '.result[] |{hosts: .certificates.hosts, status: .status, expires_on: .certificates.expires_on}'
#lxc list --format=json | jq  '.[] | .name + " | " + .state.status'
#output=$(lxc list -c ns --format csv)
#
#echo '[{ '$output' } ]'
#lxc list -c ns --format=csv

#output=$(lxc list -c ns --format=csv)
output=$(lxc list --format=json | jq '.[] | .name + "=" + .state.status + "]}"')

printf "$output,"

The telegraf.conf

[global_tags]
  environment="virt"
  hostname="host16"
  host_type="physicalmachine"
  cluster = "production"
[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  debug = false
  quiet = false
  logfile = ""
  hostname = "host16"
  omit_hostname = false
[[outputs.influxdb]]
  urls = ["http://influxdb.prod:8086"]
  database = "telegraf"
  retention_policy = ""
  write_consistency = "any"
  timeout = "5s"
[[inputs.linux_sysctl_fs]]
  # no config
[[inputs.socket_listener]]
  service_address = "tcp://:8094"
[[inputs.exec]]
  commands = [ "/home/monitor/lxclist.sh" ]
  interval = "15s"
  name_override = "lxc-monitor"
  data_format = "json"
[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false
[[inputs.disk]]
  ignore_fs = ["tmpfs", "devtmpfs", "devfs"]
[[inputs.diskio]]
  # no config
[[inputs.kernel]]
  # no config
[[inputs.mem]]
  # no config
[[inputs.processes]]
  # no config
[[inputs.swap]]
  # no config
[[inputs.system]]
  # no config
[[inputs.net]]
  # no config
[[inputs.netstat]]
  # no config
[[inputs.temp]]
[[inputs.hddtemp]]

Here the error, but I know the problem is my output. I do not know how to parse the right words from lxc list command.

root@host16:/home/monitor# telegraf --debug --config /etc/telegraf/telegraf.conf --input-filter exec
2022-05-27T21:20:03Z I! Starting Telegraf 1.11.2
2022-05-27T21:20:03Z I! Loaded inputs: exec
2022-05-27T21:20:03Z I! Loaded aggregators: 
2022-05-27T21:20:03Z I! Loaded processors: 
2022-05-27T21:20:03Z I! Loaded outputs: influxdb
2022-05-27T21:20:03Z I! Tags enabled: cluster=production environment=virt host=virt16 host_type=physicalmachine hostname=virt16
2022-05-27T21:20:03Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"virt16", Flush Interval:10s
2022-05-27T21:20:03Z D! [agent] Connecting outputs
2022-05-27T21:20:03Z D! [agent] Attempting connection to output: influxdb
2022-05-27T21:20:03Z D! [agent] Successfully connected to output: influxdb
2022-05-27T21:20:03Z D! [agent] Starting service inputs
2022-05-27T21:20:16Z E! [inputs.exec]: Error in plugin: unable to parse out as JSON, invalid character '"' after top-level value
2022-05-27T21:20:20Z D! [outputs.influxdb] buffer fullness: 0 / 10000 metrics. 
^C2022-05-27T21:20:25Z D! [agent] Stopping service inputs
2022-05-27T21:20:25Z D! [agent] Input channel closed
2022-05-27T21:20:25Z I! [agent] Hang on, flushing any cached metrics before shutdown
2022-05-27T21:20:25Z D! [outputs.influxdb] buffer fullness: 0 / 10000 metrics. 
2022-05-27T21:20:25Z D! [agent] Closing outputs
2022-05-27T21:20:25Z D! [agent] Stopped Successfully
root@host16:/home/monitor# service telegraf status
● telegraf.service - The plugin-driven server agent for reporting metrics into InfluxDB
   Loaded: loaded (/lib/systemd/system/telegraf.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2022-05-27 18:18:30 -03; 2min 5s ago
     Docs: https://github.com/influxdata/telegraf
 Main PID: 24436 (telegraf)
    Tasks: 28 (limit: 39321)
   Memory: 50.5M
      CPU: 3.610s
   CGroup: /system.slice/telegraf.service
           └─24436 /usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d

May 27 18:19:40 host16 telegraf[24436]: 2022-05-27T21:19:40Z E! [inputs.hddtemp]: Error in plugin: dial tcp 127.0.0.1:7634: connect: connection refused
May 27 18:19:45 host16 telegraf[24436]: 2022-05-27T21:19:45Z E! [inputs.exec]: Error in plugin: unable to parse out as JSON, invalid character ',' looking for beginning of value
May 27 18:19:50 host16 telegraf[24436]: 2022-05-27T21:19:50Z E! [inputs.hddtemp]: Error in plugin: dial tcp 127.0.0.1:7634: connect: connection refused
May 27 18:20:00 host16 telegraf[24436]: 2022-05-27T21:20:00Z E! [inputs.exec]: Error in plugin: unable to parse out as JSON, invalid character ',' looking for beginning of value
May 27 18:20:00 host16 telegraf[24436]: 2022-05-27T21:20:00Z E! [inputs.hddtemp]: Error in plugin: dial tcp 127.0.0.1:7634: connect: connection refused
May 27 18:20:10 host16 telegraf[24436]: 2022-05-27T21:20:10Z E! [inputs.hddtemp]: Error in plugin: dial tcp 127.0.0.1:7634: connect: connection refused
May 27 18:20:15 host16 telegraf[24436]: 2022-05-27T21:20:15Z E! [inputs.exec]: Error in plugin: unable to parse out as JSON, invalid character ',' looking for beginning of value
May 27 18:20:20 host16 telegraf[24436]: 2022-05-27T21:20:20Z E! [inputs.hddtemp]: Error in plugin: dial tcp 127.0.0.1:7634: connect: connection refused
May 27 18:20:30 host16 telegraf[24436]: 2022-05-27T21:20:30Z E! [inputs.exec]: Error in plugin: unable to parse out as JSON, invalid character ',' looking for beginning of value
May 27 18:20:30 host16 telegraf[24436]: 2022-05-27T21:20:30Z E! [inputs.hddtemp]: Error in plugin: dial tcp 127.0.0.1:7634: connect: connection refused
root@host16:/home/monitor# 

Tks in advance …

Forgot to include the way output is:

"tm-testeestrutura16-r2-sp2=Running]}"
"tm-testedata16-r2-sp2=Running]}"
"testemap16-proxy-prov-r1-sp2=Running]}"
"testemap16-r1-sp2=Running]}"
"testemap16-r2-sp2=Running]}",

Unfortunately, this is definitely not valid JSON, which is what would cause the error. I would try running your script and collecting the output. Then run it through a JSON validator.