SNMP input plugin custom tag


#1

How can I set a custom tag in an SNMP plugin?
I like to have the tag “foo” present in every OID collected like so
hrStorageTable,agent_host=A.B.C.D,fs=/,foo=bar Used=100240i,Size=4056112i 1525764935000000000

Currently I have the following configured, but it’s not showing.

[agent]
omit_hostname = true

[[inputs.snmp]]
agents = [ “A.B.C.D” ]
version = 2
community = “XXXX”
interval = “300s”
timeout = “120s”

[[inputs.snmp.tags]]
foo = “bar”

[[inputs.snmp.table]]
name = “hrStorageTable”
inherit_tags = [ “foo” ]

[[inputs.snmp.table.field]]
name = “Used”
oid = “HOST-RESOURCES-MIB::hrStorageUsed”

[[inputs.snmp.table.field]]
name = “Size”
oid = “HOST-RESOURCES-MIB::hrStorageSize”

[[inputs.snmp.table.field]]
name = “fs”
oid = “HOST-RESOURCES-MIB::hrStorageDescr”
is_tag = true


#2

I think you just need to remove one layer of brackets from your tags table:

- [[inputs.snmp.tags]]
+ [inputs.snmp.tags]

#3

Thanks. That fixed it.
What’s the difference between single and double brackets?


#4

What’s the difference between single and double brackets?


#5

In TOML double brackets define an array of tables while single brackets create a single table.

Here is an comparison using JSON format:

Single brackets:

{
	"tags": {
		"foo": "bar"
	}
}

Double brackets:

{
	"tags": [
		{
			"foo": "bar"
		}
	]
}

Details are in the TOML spec.