Telegraf directory_monitor access rights

hi,
I’m using in telegraf the input directory_monitor to import variables sent from a webpage to a js file and I want to store them via telegraf in influxdb.
When I start telegraf with the command:

> sudo telegraf --config EM_names.conf --debug

everything works like a charm. The file gets opened, loaded and even moved to the "done" directory. Works as expected, nothing wrong with the config file I would say


However, if I start telegraf with the command :

> sudo systemctl start telegraf

I get errors and the files does not get processed.
These are the errors:

 [inputs.directory_monitor] Error in plugin: unable to monitor the targeted directory: open /home/ems/scripts/names>

Rights etc for directory and files is 777.

I believe I've seen somewhere (don't remember) that the file could not be copied to the "done" directory neither....

I have no clue what's going on here.



EM_names.conf.txt (4.6 KB)

Under systemD, telegraf is being run as user telegraf. So your first test command should actually be this: sudo -u telegraf telegraf --config EM_names.conf --debug

So I guess it’s a permissions issue where telegraf user cannot open /home/ems/scripts/names or any of it’s parent directories.

Thank you for the answer, and indeed, here i get now the same issue with this command. I saw already with the

ps -aux | grep telegraf that the process was running as telegraf user.

So, I already changed group of that files directory to the “telegraf” user with >chown and >chgrp commands and give full access with >chmod
For that directory and all files insides I have now full access like this:

$ ls -l /home/ems/scripts/names
drwxrwxrwx 2 telegraf telegraf 4096 Feb 9 11:55 done
drwxrwxrwx 2 telegraf telegraf 4096 Feb 2 15:17 err
-rwxrwxrwx 1 telegraf telegraf 356 Feb 8 15:40 parameters.js

Also the names directory has these rights:
$ ls -l /home/ems/scripts
drwsrwsrwt 4 telegraf telegraf 4096 Feb 8 15:40 names

But still it does not work! I had a bit hope it would work now, but no… it does not

Tried with user “ems”, my login user: same issues.
When I try with “root” as user, it works.

This is basic linux directory permissions issue.

Now the ems user does not have the x rights to that directory. Same as the telegraf user or group also doesn’t have x permission to /home/ems.

I would advice to not place the file to read into a user home directory, but somewhere shared…

Agree Hipska, although I don’t see the thing where it goes wrong with above, I agree it’s indeed a unix issue, not telegraf, unfortunately I’m not the expert, neither in both.
But I got it working, I created the same directories in /etc/telegraf/parameters directory, changed all directories to 777 and now it works also with telegraf user. Still owner and group of that directory are both root.
Now hoping it will also work when this parameter file is written from a javascript initiaded from a webpage.