Global SNMP Configuration for Telegraf

#1

I plan to pull data from multiple SNMP devices, all of which have similar SNMP credentials. Wondering if it is possible to have a global instance of SNMP credentials so that I don’t need to reproduce for every device.

#2

It isn’t possible, but you can use environment variables replacement in the configuration file:

[[inputs.snmp]]
  agents = ["foo.example.org:161", "bar.example.org:161"]
  version = 3
  sec_name = "$SEC_NAME"
  auth_protocol = "sha"
  auth_password = "$AUTH_PASSWORD"
  sec_level = "authPriv"
  priv_protocol = "AES"
  priv_password = "$PRIV_PASSWORD"

  [[inputs.snmp.field]]
    name = "hostname"
    oid = "RFC1213-MIB::sysName.0"

[[inputs.snmp]]
  agents = ["baz.example.org:161"]
  version = 3
  sec_name = "$SEC_NAME"
  auth_protocol = "sha"
  auth_password = "$AUTH_PASSWORD"
  sec_level = "authPriv"
  priv_protocol = "AES"
  priv_password = "$PRIV_PASSWORD"

  [[inputs.snmp.field]]
    name = "sys_contact"
	oid = "SNMPv2-MIB::sysContact.0"

You can specify all the agents with the same field/table settings together, and I also recommend splitting your config files into multiple files in /etc/telegraf/telegraf.d.