Trying to run the following in inputs.exec:
[[inputs.exec]]
[[inputs.exec]]
interval = “60s”
commands = [
“/usr/local/bin/python3.7 /usr/local/telegraf/ucs_traffic_monitor.py /usr/local/telegraf/ucs_domains.txt influxdb-lp -vv”,
]
timeout = “50s”
data_format = “influx”
Get the following error in the log:
[inputs.exec] Error in plugin: exec: exit status 1 for command ‘/usr/local/bin/python3.7 /usr/local/telegraf/ucs_traffic_monitor.py /usr/local/telegraf/ucs_domains.txt influxdb-lp -vv’: Traceback (most recent call last):…
This traceback is from your python application. I would see what it is referring to and it may lead you to what is failing. If you cannot see the full output, I would try running the same command as the same user that telegraf is running as. Either your current user or as the telegraf
user if you are running it as a service.
It is:
-rwxr-xr-x+ 1 telegraf telegraf 123717 Sep 25 23:28 /usr/local/telegraf/ucs_traffic_monitor.py
ok so the telegraf user and group have permissions. What happens when the telegraf user runs that command?
It throws an error for for NIkko module
Always better to provide your error, but as-is I have no idea what that is
I will assume that has to do with your custom exec script. My suggestion is keep working through errors until you are able to get it to run manually.
It runs manually outside of Telegraf
hi, I’ve got the same problem. Did you find a solution?
Hi @skinfrakki. I have the same problem. Did you manage to solve this issue ? can you please share the solution. thank you
When you run your full command exactly how you have it in the command section does it work or are you running it in a different way or with different flags when it works outside of telegraf?
Exactly like this:
/usr/local/bin/python3.7 /usr/local/telegraf/ucs_traffic_monitor.py /usr/local/telegraf/ucs_domains.txt influxdb-lp -vv
Telegraf runs with a minimal environment, which means it may not inherit the environment variables available in your user shell. If your script relies on those variables, it could fail when run by Telegraf.
To fix this, you can explicitly define the required environment variables in your Telegraf config like this:
[[inputs.exec]]
commands = ["/usr/local/bin/python3.7 /usr/local/telegraf/ucs_traffic_monitor.py /usr/local/telegraf/ucs_domains.txt influxdb-lp -vv"]
data_format = "influx"
timeout = "30s"
environment = [
"PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin",
"PYTHONPATH=/your/python/path"
]
For better troubleshooting, I also recommend enabling debug logging in Telegraf:
[agent]
debug = true
logfile = "/var/log/telegraf/telegraf.log"
If you’re still running into issues, feel free to share your Python script or the exact error message from the logs, I’ll be happy to help further!