Telegraf exec input insert wrong data


Hi All,

I have an issue with exec plugin and I don’t know how I can fix it.

My config in telegraf: (1.5)

commands = ["/etc/telegraf/plugins/"]
timeout = “5s”
data_format = “influx”

My script to get data:


mongo=cat $log | grep "SERVICE NOTIFICATION" | grep mongo | wc -l
echo Alertas,alertado=nagios Mongo=$mongo

then I tested:

[root@cvs1pan01 plugins]# telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d --test --input-filter=exec

  • Plugin: inputs.exec, Collection 1

Alertas,alerts=nagios,hostgroup=compute,host_type=nagiosserver,host=machine Mongo=21961 1523605711000000000

So everything seem okay, but If I check on Chronograf:

My mongo value inserts 0.

I don’t know what is happening, my real value is 21691 not 0.

Could be something about format or any exit??

I only try to insert the number of alerts I have in Nagios log to Mongo.

I would appreciate your help.

Thanks in advance.


Im trying other things like using json format and I have the same issue too:

changing influx to json in conf.

telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d --test --input-filter=exec

  • Plugin: inputs.exec, Collection 1

exec_nagios,host=machine,hostgroup=compute,host_type=nagiosserver Mongo=23008 152360739000000000

But in chronograf the same:

It is inserting 0 instead 23008.



I think what is most likely going on here is that the script works fine when ran interactively, but fails in some way, probably permissions, when ran as the telegraf user in the service scripts. Try running your --test command prefixed by sudo -u telegraf, this is not exactly the same as running it in Telegraf but it will at least run as the correct user.