Include a text file in telegraf

hello everyone, i’m monitoring my routers with telegraf/influxdb via snmp , but i was wondering if it’s possible to add agents from a text file instead of adding the IPs
the current conf:
[[inputs.snmp]]
agents = [ “192.168.1.1:161”,“192.168.1.1:161” ]
The wanted conf:
[[inputs.snmp]]
agents = [ import/include /etc/telegraf/MyIPs.txt ]

Thanks

Hello @zaki,
I know you can set environment variables, but I don’t know if that syntax is supported.

I’ll check with the Telegraf team. Thanks for your patience.

Loading the list of agents from a separate file is an open issue. See Telegraf SNMP Load agent list from an external file · Issue #5440 · influxdata/telegraf · GitHub

Depending on how long your agents list is and how frequently it is updated you may be able to use environment variables to work around the current requirement to list agents in the telegraf configuration file. The link Anaisdg shared describes how to use environment variables.

If your concern is that your configuration file is too large, it might help to split it into multiple files and load them all with the --config-directory command line option. For example you could have a file just for snmp.

Thank you very much for your reply, actually, i don’t have variables and my list is not that long, i only have a text file that contains all my IPs (this list is static and won’t be changing) so in need just to know how i can load the text file in
[[inputs.snmp]]
agents = [ IPs.text ] instead of adding the IPs one by one. I think what i want is not that hard to do and surely we can do it with telegraf but i wasn’t able to find a solution online :sweat_smile:
I’ve read the link that Anaisdg has sent me but i have a small question please, in the link the variable was a HTTP link, so my question is will it accepts to put the path of my file in the same way? and if so is telegraf will be able to read what i have written in this file?

Thanks

I don’t believe telegraf can do this, but it would be pretty trivial to write
a bash script which concatenates:

  • the first part of your config file
  • the list of IPs from your test file, in the correct format
  • the last part of your config file

You can then either call the script whenever the list of IPs changes, or get
it to run whenever you restart telegraf, or something else appropriate to your
use case.

Regards,

Antony.