Telegraf input.exe not sending data to influx but --test running successful

If you look at following test its successful but i am not seeing its sending data to influxdb, I have many other input.exe script running on same server and they are sending data successfully.

    $ telegraf --config /etc/telegraf/telegraf.d/foo-replication.conf --input-filter exec --test
    2019-09-20T15:50:48Z I! Starting Telegraf 1.12.1
    > foo_replication,host=foo.example.com,type=ActiveUsers status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=StageUsers status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=PreservedUsers status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=Hosts status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=Services status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=UserGroups status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=HostGroups status=1 1568994650000000000
    > foo_replication,host=foo.example.com,type=Netgroups status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=HBACRules status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=SUDORules status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=DNSZones status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=Certificates status=1 1568994650000000000
    > foo_replication,host=foo.example.com,type=fooConflicts status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=GhostReplicas status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=AnonymousBIND status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=MicrosoftADTrust status=0 1568994650000000000
    > foo_replication,host=foo.example.com,type=ReplicationStatus status=0 1568994650000000000

This is the input file

[[inputs.exec]]
  commands = ["/usr/local/bin/foo-replication.sh"]
  timeout = "60s"
  data_format = "influx"

I did check permission etc but no luck :frowning:
What is wrong in above output which causing issue, is there any data limit or anything i can try?

Don’t forget that --test doesn’t send the data to InfluxDB, it only prints out to the console. Does it work when you run Telegraf as a service? If not, check the logs to see what the error is.

I know --test doesn’t send data, I am running in services, if i take this script output and put it in foo.sh script like following then it works.

#!/bin/bash
echo /tmp/output.txt

somehow it doesn’t like my script execution, I check logs etc… and it’s not complaining anything.

This is my original script

#!/bin/bash
IFS=$'\n'
for qw in `/home/telegraf/checkipaconsistency/cipa -l --no-header | awk -F"|" '{print $2 ":" $7}' | grep [A-Z]`
do
  Type=`echo $qw | awk -F":" '{print $1}' | tr -d ' '`
  Status=`echo $qw | awk -F":" '{print $2}' | tr -d ' '`
  if [ $Status == OK ];then
	Status="0"
  else
	Status="1"
  fi
  echo "foo_replication,host=`hostname -s`,type=$Type status=$Status"
done

Most of the time this ends up being a permission issue. It isn’t exactly the same, but I usually start by running the script as the telegraf user:

sudo -u telegraf /path/to/the/script

Another technique you can use in your script is to write to both stdout and a file:

  echo "foo_replication,host=`hostname -s`,type=$Type status=$Status"
+ echo "foo_replication,host=`hostname -s`,type=$Type status=$Status" > /tmp/telegraf-debug

I tried

+ echo "foo_replication,host=`hostname -s`,type=$Type status=$Status" > /tmp/telegraf-debug

I can see it’s not executing this script, its not creating /tmp file… something going on. but if i run that script with telegraf user it works! so its not permission issue, look like something else going on

Check the $PATH inside the script (when run from telegraf, not via sudo).

You’re using commands like awk, grep and hostname. It’s just about possible
that they can’t be found by the script without a full path to them.

Try putting as the first executable line of the script (ie: after the
#!/bin/bash):

echo $PATH >/tmp/telegraf-path-debug

Antony.

I found the issue and it was in this line

for qw in `/home/telegraf/checkipaconsistency/cipa -l --no-header | awk -F"|" '{print $2 ":" $7}' | grep [A-Z]`

As soon as i removed -l option it started working but if i run same script by hand or with --test it works, look like it need true shell to run that -l option otherwise it won’t work.

crazy stuff but anyway now i can see data in influx :slight_smile: