# SNMP Trap extension add attribute to log and custom device

**URL:** <https://community.dynatrace.com/t/snmp-trap-extension-add-attribute-to-log-and-custom-device/47071>\
**Category:** Extensions\
**Tags:** snmp, extensions, logs\
**Created:** [August 8, 2024, 2:32pm UTC](https://community.dynatrace.com/t/snmp-trap-extension-add-attribute-to-log-and-custom-device/47071 "2024-08-08T14:32:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![debeste](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@debeste](https://community.dynatrace.com/u/debeste)\
**Post date:** [August 8, 2024, 2:32pm UTC](https://community.dynatrace.com/t/snmp-trap-extension-add-attribute-to-log-and-custom-device/47071/1 "2024-08-08T14:32:42Z")

</div>

Hey,

The snmp Trap extension does not make it easy to know, which log/custom device is created by which extension config. On the custom devices created, the only attribute present is the&nbsp;dt.ip\_addresses.  
I have multiple applications sending snmp traps, each having their own support team.  
So I have to create auto tag rules for each device sending traps, based on IP.

Example:&nbsp;type(snmptraps:com\_dynatrace\_ext\_snmp-traps),dt.ip\_addresses(99.4.50.24)  
Repeat 100x 😞

So it would help if I could add a variable in the extension config “application-name” thats then added to the log entry and custom device.

Is it possible to add vars to log attributes?  
And how to achieve this for the snmp trap extension, as only the metric is defined here?  
I was thinking about something like this, but it does not work as the custom devices only take their properties from the log records (& metrics) its seems.

My non working custom extension, to give some more context.

```markup
name: custom:com.dynatrace.extension.snmp-traps-generic
version: 0.0.3
minDynatraceVersion: 1.280.0
author:
  name: Dynatrace

metrics:
  - key: com.dynatrace.extension.snmp-traps-generic.traps.count
    metadata:
      displayName: Traps count
      description: Number of traps received.
      unit: Count

snmptraps:
  - group: generic
    featureSet: Events
    interval:
      minutes: 1
    metrics:
      - key: com.dynatrace.extension.snmp-traps-generic.traps.count
        type: count,delta
        value: calculated
    dimensions:
      - key: host_ip
        value: const:sender
      - key: trap_oid
        value: const:trapOID
      - key: application_name
        value: var:application-name

vars:
  - id: application-name
    displayName: Application name
    description: "The name of the application integrated through snmp traps"
    type: text

topology:
  relationships:
    - fromType: custom:com_dynatrace_ext_snmp-traps
      typeOfRelation: SAME_AS
      toType: network:device
      enabled: true
      sources:
        - sourceType: Entities
          mappingRules:
            - sourceProperty: dt.ip_addresses
              sourceTransformation: To lower case
              destinationProperty: dt.ip_addresses
              destinationTransformation: To lower case
  types:
    - name: custom:com_dynatrace_ext_snmp-traps
      displayName: SNMP Traps Device
      enabled: true
      rules:
        - idPattern: snmp_traps_device_{application_name}_{host_ip}
          instanceNamePattern: SNMP Traps source {application_name} {host_ip}
          sources:
            - sourceType: Metrics
              condition: $prefix(com.dynatrace.extension.snmp-traps-generic.traps.count)
          attributes:
            - pattern: '{device.address}'
              key: dt.ip_addresses
              displayName: Device Address
            - pattern: '{host_ip}'
              key: host_ip
              displayName: IP Address
            - pattern: var:application-name
              key: application_name
              displayName: Application name
          requiredDimensions: []
        - idPattern: snmp_traps_device_{application_name}_{host_ip}
          sources:
              - sourceType: Logs
          attributes: 
            - pattern: '{device.address}'
              key: dt.ip_addresses
              displayName: Device Address
            - pattern: '{host_ip}'
              key: host_ip
              displayName: IP Address
            - pattern: var:application-name
              key: application_name
              displayName: Application name
          requiredDimensions: 
            - key: log.source
              valuePattern: '$eq(snmptraps)'

screens:
  - entityType: custom:com_dynatrace_ext_snmp-traps
    detailsSettings:
      layout:
        autoGenerate: false
        cards:
          - type: INJECTIONS
          - key: traps_charts
            type: CHART_GROUP
          - key: traps_logs
            type: LOGS
            width: FULL_SIZE
      staticContent:
        breadcrumbs:
          - displayName: SNMP Traps sources
            entityType: custom:com_dynatrace_ext_snmp-traps
            type: ENTITY_LIST_REF
        showAddTag: true
        showGlobalFilter: false
        showProblems: true
        showProperties: true
        showTags: true
    chartsCards:
      - key: traps_charts
        displayName: Trap statistics
        numberOfVisibleCharts: 2
        mode: NORMAL
        charts:
          - displayName: Traps Count
            graphChartConfig:
              metrics:
                - metricSelector: com.dynatrace.extension.snmp-traps-generic.traps.count:splitBy()
                  visualization:
                    displayName: Traps count
                    seriesType: COLUMN
            visualizationType: GRAPH_CHART
          - displayName: Trap OIDs
            graphChartConfig:
              metrics:
                - metricSelector: com.dynatrace.extension.snmp-traps-generic.traps.count:splitBy("trapoid")
                  visualization:
                    seriesType: COLUMN
              stacked: true
            visualizationType: GRAPH_CHART
    logsCards:
      - key: traps_logs
        displayName: Trap details
        filterQuery: dt.source_entity inEntitySelector "$(entityConditions)"
        pageSize: 10
        showFiltering: true
        enablePaging: true

```

---

<div class="post-metadata">

**Author:** ![debeste](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@debeste](https://community.dynatrace.com/u/debeste)\
**Post date:** [August 14, 2024, 8:32am UTC](https://community.dynatrace.com/t/snmp-trap-extension-add-attribute-to-log-and-custom-device/47071/2 "2024-08-14T08:32:46Z")

</div>

I found a sollution myself.  
Its not ideal, but it works.  
It would help if I would know the log/snmp-trap ingest pipeline, in some ordered list form.

\*\*Important!\*\*Without these 3 log configurations, the setup does not work as intended.

- Create an aditional field&nbsp; **application\_name** &nbsp;in Log Processing, rule, based on _the snmp.trap\_oid field._  
_USING(INOUT application\_name:STRING?, snmp.trap\_oid)_  
_| FIELDS\_ADD(application\_name:IF\_THEN\_ELSE(snmp.trap\_oid CONTAINS(‘.6876.’), “VMWARE”,application\_name))_
- Add the field&nbsp;application\_name&nbsp;in&nbsp;Log custom attributes, to make the field queryable.
- Create a log metric log.snmptrap.count&nbsp;, with matcher log.source=“snmptraps” and dimensions application\_name, device.address, snmp.trap\_oid.

Extension:

```markup
name: custom:com.dynatrace.extension.snmp-traps-generic
version: 0.1.6
minDynatraceVersion: 1.280.0
author:
  name: Debeste

metrics:
  - key: custom.extension.snmp-traps-generic.traps.count
    metadata:
      displayName: Traps count
      description: Number of traps received.
      unit: Count

snmptraps:
  - group: generic
    featureSet: Events
    interval:
      minutes: 1
    metrics:
      - key: custom.extension.snmp-traps-generic.traps.count
        type: count,delta
        value: calculated
    dimensions:
      - key: host_ip
        value: const:sender
      - key: trap_oid
        value: const:trapOID

topology:
  relationships:
    - fromType: custom:com_dynatrace_ext_snmp-traps-custom
      typeOfRelation: SAME_AS
      toType: network:device
      enabled: true
      sources:
        - sourceType: Entities
          mappingRules:
            - sourceProperty: dt.ip_addresses
              sourceTransformation: To lower case
              destinationProperty: dt.ip_addresses
              destinationTransformation: To lower case
  types:
    - name: custom:com_dynatrace_ext_snmp-traps-custom
      displayName: SNMP Traps Device Custom
      enabled: true
      rules:
        - idPattern: snmp_traps_device_{application_name}_{device.address}
          instanceNamePattern: SNMP Traps source {application_name} {device.address}
          sources:
            - sourceType: Metrics
              condition: $prefix(log.snmptrap.count)
          attributes:
            - pattern: '{device.address}'
              key: dt.ip_addresses
              displayName: Device Address
            - pattern: '{application_name}'
              key: application_name
              displayName: Application name
          requiredDimensions: []
        - idPattern: snmp_traps_device_{application_name}_{device.address}
          sources:
              - sourceType: Logs
          attributes: 
            - pattern: '{device.address}'
              key: dt.ip_addresses
              displayName: Device Address
            - pattern: '{application_name}'
              key: application_name
              displayName: Application name
          requiredDimensions: 
            - key: log.source
              valuePattern: '$eq(snmptraps)'

screens:
  - entityType: custom:com_dynatrace_ext_snmp-traps-custom
    detailsSettings:
      layout:
        autoGenerate: false
        cards:
          - type: INJECTIONS
          - key: traps_charts
            type: CHART_GROUP
          - key: traps_logs
            type: LOGS
            width: FULL_SIZE
      staticContent:
        breadcrumbs:
          - displayName: SNMP Traps sources Custom
            entityType: custom:com_dynatrace_ext_snmp-traps-custom
            type: ENTITY_LIST_REF
        showAddTag: true
        showGlobalFilter: false
        showProblems: true
        showProperties: true
        showTags: true
    chartsCards:
      - key: traps_charts
        displayName: Trap statistics
        numberOfVisibleCharts: 2
        mode: NORMAL
        charts:
          - displayName: Traps Count
            graphChartConfig:
              metrics:
                - metricSelector: log.snmptrap.count:splitBy("device.address","application_name")
                  visualization:
                    displayName: Traps count
                    seriesType: COLUMN
            visualizationType: GRAPH_CHART
          - displayName: Trap OIDs
            graphChartConfig:
              metrics:
                - metricSelector: log.snmptrap.count:splitBy("device.address","application_name","snmp.trap_oid")
                  visualization:
                    seriesType: COLUMN
              stacked: true
            visualizationType: GRAPH_CHART
    logsCards:
      - key: traps_logs
        displayName: Trap details
        filterQuery: dt.source_entity inEntitySelector "$(entityConditions)"
        pageSize: 10
        showFiltering: true
        enablePaging: true

```

This results in the device names containing the application name & IP.  
Aswell as adding this data as properties to the device.

 ![debeste_0-1723624029696.png](https://global.discourse-cdn.com/dynatrace/original/2X/b/b63a3a8aff5e9472b5b67b9613dd1b5eb7025e71.png)

This setup can be simplified hugely, if it would be possible to link a VAR from the extension config to the custom device properties.

---

<div class="post-metadata">

**Author:** ![MatthieuA](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/matthieua/32/36685_2.png) [@MatthieuA](https://community.dynatrace.com/u/MatthieuA)\
**Post date:** [October 8, 2024, 5:22pm UTC](https://community.dynatrace.com/t/snmp-trap-extension-add-attribute-to-log-and-custom-device/47071/3 "2024-10-08T17:22:08Z")

</div>

I agree that this would really be very practical to be able to use “var:” in custom extensions based on SNMP Traps.&nbsp;&nbsp;Furthermore, it looks like a bug because the use of variables works fine with the datasource “snmp” (in poll mode) but does not work with “snmptraps”.&nbsp;The problem is that in certain cases, the workaround with log processing is not possible if the expected information is not present in the content of the SNMP Trap received.
