SNMP Trap enrichment:

Hi all,

We are trying to retrieve SNMP Trap information from multiple devices 1000+. The question now is how can we enrich the data per device is there a possible way off adding environment information.

[[processors.reverse_dns]]
field = “source”
dest = “source_name”

Than on the destination processor check if the dns contains a string and add a new tag.
[[processors…]]
field = “source_name”
regex_match = .env-name-xyz.
new_tag = “env=env.xyz”

[[processors…]]
field = “source_name”
regex_match = .env-name-yz.
new_tag = “env=env.yz”

Hope this is a bit clear and someone has a solution to this.

It looks like you have the snmp_trap input and the reverse_dns processor working already. The next steps you’re describing should be possible with a regex processor on the source_name field producing a new field (specified with regex’s result_key), and a converter processor to switch the new field to a tag.

You’ll end up with a chain: snmp_trap input → reverse_dns processor → regex processor → converter processor → output. The processor order is important so you’ll need to add an order setting on each processor. Here’s more information on setting order: telegraf/CONFIGURATION.md at master · influxdata/telegraf · GitHub

You may want to add namepass to each processor so it only processes snmp_trap metrics and ignores everything else. telegraf/CONFIGURATION.md at master · influxdata/telegraf · GitHub

Hi Reimda,

Thanks for the links, just wanted to add in my working configuration for others to use.

Just one small other question is there a way to use external datasources to enrich the data with key:value pairs (labels)?

[[inputs.snmp_trap]]
service_address = “udp://:162”

[[processors.reverse_dns]]
order = 1
[[processors.reverse_dns.lookup]]
tag = “source”
dest = “host”

[[processors.regex]]
order = 2
[[processors.regex.tags]]
#look in key matching value
key = “host”
pattern = “.wan.company-name.net.
#value
replacement = “squad-name”
#key
result_key = “squad”

It sounds like you want to enrich SNMP Trap data by adding environment information to each device based on its source. The configuration you have provided is on the right track, but you can simplify it by using a single processor that performs both the reverse DNS lookup and the environment tag addition based on a regex match.

It sounds like you want to SNMP Trap lead enrichment by adding environment information to each device based on its source. The configuration you have provided is on the right track, but you can simplify it by using a single processor that performs both the reverse DNS lookup and the environment tag addition based on a regex match.

Here’s an example configuration that should achieve the desired result using the Telegraf SNMP input plugin and the processors you mentioned:
[[inputs.snmp]]
agents = [“device1”, “device2”, “device3”] # add the list of devices you want to monitor
version = 2
community = “public”
timeout = “5s”
retries = 3
max_repetitions = 10
name = “snmp”

[[processors.reverse_dns]]
field = “host”
dest = “source_name”

[[processors.regex]]
field = “source_name”
regex = “.\.env-name-xyz\…
tagpass = [“env=env.xyz”]

[[processors.regex]]
field = “source_name”
regex = “.\.env-name-yz\…
tagpass = [“env=env.yz”]
In this example, the SNMP input plugin is configured to monitor the devices you want to retrieve SNMP Trap information from. The processors.reverse_dns processor performs a reverse DNS lookup to get the hostname of each device based on its IP address.

The processors.regex processor then adds an environment tag to each data point if the source_name field matches a regex pattern. You can add as many regex patterns as you need to cover all the environments you want to monitor.

With this configuration, the output data will contain an env tag with the appropriate value for each data point, based on the source device’s hostname.