[[inputs.exec]] Test shows data, yet none makes it to influxdb

Hello there, I’m at my wits end with this problem. A simple bash script gets a value from a server. The script, a bash script, takes the value from the server, then echoes the value so that inputs.exec sends it to influxdb.
My config is like so:
commands = ["/etc/telegraf/scripts/nc_script.sh"]
tag_keys = [“Netcat”]
interval = “10s”
data_format = “value”
data_type = “integer”
name_override = “Romana”

The script is like this:
#!/usr/bin/env bash
check_server=timeout .25 nc <ip_to_server><port> | sed 's/K.*//' | awk 'NR==1 { print $2; fflush(); }' | tee mylog.txt
tlnt=while read line do echo $line done <mylog.txt
echo $tlnt

It parses the data sent by the server and removes blank spaces and a few characters so that I get a number, an integer.

And simple telegraf --config /etc/telegraf/telegraf.d/nc.conf --test shows the following:
2020-09-03T21:22:39Z I! Starting Telegraf 1.15.2
> Romana,host=myhost value=80i 1599168159000000000

Yet, that data can’t seem to find its way to influxdb. Whenever i check the status of the telegraf service there are no errors shown and no warnings. I’ve restarted the service everytime I make a change in the config and the script just so that i can be sure it’s applying the changes. The measurement it’s not there.

Hello @crlsrqlm,
I’m sorry you’re having difficulty.
'Can you please share the output section of your config? Also can you please set debug=True and then share the logs again?
Thank you!

Sure.
In the outputs section I have only the url of the influxdb instance and the username and password are correct since every other inputs plugin works. The debug now is set to true as well.
The log is as follows:
user@myhost:/etc/telegraf/telegraf.d$ telegraf --config /etc/telegraf/telegraf.d/nc.conf --test
2020-09-04T18:07:40Z I! Starting Telegraf 1.15.2
2020-09-04T18:07:40Z D! [agent] Initializing plugins
2020-09-04T18:07:40Z D! [agent] Starting service inputs
2020-09-04T18:07:41Z D! [agent] Stopping service inputs
2020-09-04T18:07:41Z D! [agent] Input channel closed
2020-09-04T18:07:41Z D! [agent] Stopped Successfully
>Romana,host=myhost value=460i 1599242861000000000

So, I figured it out. The problem was that in my inexperience I was piping the result of the netcat command through sed and and then awk into a text file (so that I could use just the last line read from the server and remove blank spaces). The clue that did it for me was that whenever I set the data_format to value and data_type to integer (since that was the value I was expecting) the test ran ok, but the service read the following error: strconv.Atoi parsing “peso=00” invalid syntax. So it was reading a string instead of an integer.

So I removed the part in the script were I was using awk and just used sed to both remove unwanted characters and blankspaces. The lines I don’t want to use are removed with a loop inside the script. By removing the need for a text file my result isn’t a string but an integer. And now I can save the results in influxdb. i’m a happy man today.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.