# SNMP Trap enrichment:

**URL:** https://community.influxdata.com/t/snmp-trap-enrichment/15464
**Category:** Telegraf
**Tags:** telegraf, smnp
**Created:** [August 3, 2020, 2:22pm UTC](https://community.influxdata.com/t/snmp-trap-enrichment/15464 "2020-08-03T14:22:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![neeles83](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/neeles83/32/5706_2.png) [@neeles83](https://community.influxdata.com/u/neeles83)
#### Post date: [August 3, 2020, 2:22pm UTC](https://community.influxdata.com/t/snmp-trap-enrichment/15464/1 "2020-08-03T14:22:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![reimda](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/reimda/32/3723_2.png) [@reimda](https://community.influxdata.com/u/reimda)
#### Post date: [August 11, 2020, 8:02pm UTC](https://community.influxdata.com/t/snmp-trap-enrichment/15464/2 "2020-08-11T20:02:04Z")

</div>

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](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#processor-plugins)

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](https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#selectors)

---

<div class="post-metadata">

### Author: ![neeles83](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/neeles83/32/5706_2.png) [@neeles83](https://community.influxdata.com/u/neeles83)
#### Post date: [August 20, 2020, 11:50am UTC](https://community.influxdata.com/t/snmp-trap-enrichment/15464/3 "2020-08-20T11:50:00Z")

</div>

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](http://wan.company-name.net)._”  
> #value  
> replacement = “squad-name”  
> #key  
> result\_key = “squad”

---

<div class="post-metadata">

### Author: ![Florian\_Haas](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/florian_haas/32/12623_2.png) [@Florian\_Haas](https://community.influxdata.com/u/Florian_Haas)
#### Post date: [February 14, 2023, 2:41pm UTC](https://community.influxdata.com/t/snmp-trap-enrichment/15464/4 "2023-02-14T14:41:44Z")

</div>

> [@neeles83](#):
>
> 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 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](https://www.globaldatabase.com/what-is-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.
