I have the following inputs in my telegraf.conf that go to Grafana. I can get the simpler first 3 examples to work but cannot get the 4th to work.
[[inputs.exec]]
commands = ["sh -c 'grep -i DatasetVersion /etc/aaa/systemnameX/configfile | cut -d'=' -f2'"]
name_override = "systemnameX"
timeout = "5s"
data_format = "value"
data_type = "string"
[inputs.exec.tags]
type = "dataset_version"
[[inputs.exec]]
commands = ["sh -c 'cat /root/config/OS_Version.txt | tr -d C'"]
name_override = "systemnameX"
timeout = "5s"
data_format = "value"
data_type = "string"
[inputs.exec.tags]
type = "os_version"
[[inputs.exec]]
commands = ["sh -c 'grep -i VERSION= /usr/bin/sw_install | head -1 | cut -d'=' -f2 '"]
name_override = "systemnameX"
timeout = "5s"
data_format = "value"
data_type = "string"
[inputs.exec.tags]
type = "sw_version"
[[inputs.exec]]
commands = ["/sbin/ifconfig eth0 | grep 'inet' | cut -d: -f2 | awk '{print $2}'"]
name_override = "systemnameX"
timeout = "5s"
data_format = "value"
data_type = "string"
[inputs.exec.tags]
type = "ip_address"
This is the error when I run the telegraf test
2021-09-04T06:36:51Z E! Error in plugin [inputs.exec]: exec: exit status 1 for command '/sbin/ifconfig eth0 | grep 'inet' | cut -d: -f2 | awk '{print $2}''
and when I put the exact command into a command line I get the following error:
awk: cmd. line:1: {print
awk: cmd. line:1: ^ unexpected newline or end of string
Any help about how to fix the awk part would be greatly appreciated.
cheers, Tara
I have tried running different permutations and combinations of your /sbin/ifconfig
command but its giving me also same error. But I have read the telegraf manual and come up with following approach/steps.
I have tested this in Linux with Telegraf's 1.19.3
version and it worked fine for me.
Steps:
commands
in inputs.exec
module of telegraf.script.bash
in my tested case) and place your command there like as follows:
cat /etc/telegraf/script.bash
#!/bin/bash
/sbin/ifconfig eth0 | grep 'inet' | cut -d: -f2 | awk '{print $2}'
OR you can also change your /sbin/ifconfig
command to following in a single awk
command:
/sbin/ifconfig eth0 | awk '/inet/{print $2}'
[[inputs.exec]]
commands = ["/etc/telegraf/script.bash" ]
name_override = "systemnameX"
timeout = "5s"
data_format = "value"
data_type = "string"
[inputs.exec.tags]
type = "ip_address"
sudo -u telegraf telegraf -test -config /etc/telegraf/telegraf.conf
NOTE: I have created test script in /etc/telegraf/script.bash
you can create it wherever you want to, but make sure you are giving absolute complete and correct path in conf file of telegraf.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With