Telegraf Input Exec and Piped command

Hy everyone i try to use this “piped command” on the exec input :

but i have this error :

2018-04-04T12:53:50Z E! Error in plugin [inputs.exec]: exec: exit status 2 for command ‘curl --user admin:password http:// -s | xml_grep ‘cpuUtilization’ --text_only’: curl: option --text_only: is unknown…

Command works well in CLI :

[root@influxDB ~]# curl --user admin:password http:// -s | xml_grep ‘cpuUtilization’ --text_only

On my telegraf.conf :

commands = [“curl --user admin:password http:// -s | xml_grep ‘cpuUtilization’ --text_only”]

name_override = “Hikvision_cpu”

data_format = “value”
data_type = “integer”

Telegraf doesn’t support pipes in the exec input.

You can add your command to a shell script and execute that instead. Make sure that you set the permissions on the script so that the telegraf user can execute them.

1 Like

i think it would make our lives a lot easier if telegraf could support using pipes in the exec plugin; especially for single value extractions like server power load via ipmi-dcmi etc.

For simple tasks it ought to work if you run the command in a shell:

commands = ['/bin/bash -c "curl ... | grep foo"']

Yay! thanks @daniel ! it’s a little awkward with the toml string escapes, but it does work :slight_smile: thanks!