Skip to content

Converter Plugin - panic: runtime error: invalid memory address or nil pointer dereference #8173

@heathda

Description

@heathda

Relevant telegraf.conf:

############################################################################
#                          INPUT PLUGINS                                   #
############################################################################

#HIKVISION IP Camera telegraf snmp collector
#Uses the HIK-DEVICE-MIB


[[inputs.snmp]]
  agents = [ "IP-ADDRESS" ]
  version = 2
  community = "public"
  interval = "60s"
  timeout = "10s"
  retries = 3

  [[inputs.snmp.field]]
    name = "manufacturer"
    oid = "HIK-DEVICE-MIB::manufacturer.0"

  [[inputs.snmp.field]]
    name = "deviceModel"
    oid = "HIK-DEVICE-MIB::deviceType.0"

  [[inputs.snmp.field]]
    name="cpuPercent"
    oid = "HIK-DEVICE-MIB::cpuPercent.0"

  [[processors.regex]]
    order = 1
    namepass = "cpuPercent"
    [[processors.regex.fields]]
      pattern = "([^0-9]+)"
      replacement = "${1}"

  [[processors.converter]]
    order = 2
    [processors.converter.fields]
      integer = ["cpuPercent"]

  [[inputs.snmp.field]]
    name="memUsed"
    oid = "HIK-DEVICE-MIB::memUsed.0"

  [[inputs.snmp.field]]
    name="memUsed"
    oid = "HIK-DEVICE-MIB::memUsed.0"

  [[inputs.snmp.field]]
    name="staticIp"
    oid = "HIK-DEVICE-MIB::staticIpAddr.0"

  [[inputs.snmp.field]]
    name="vidEncode"
    oid = "HIK-DEVICE-MIB::videoEncode.0"

System info:

Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-47-generic x86_64)
Telegraf 1.15.3

Steps to reproduce:

When running the test config command against the file containing the above configuration, I receive a panic: runtime error

Expected behavior:

When running the config test command: sudo telegraf --test --config /etc/telegraf/telegraf.d/hiktest.conf

Actual behavior:

The script panics:

2020-09-23T13:28:10Z I! Starting Telegraf 1.15.3
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x1f94624]

goroutine 32 [running]:
github.com/influxdata/telegraf/plugins/processors/converter.(*Converter).convertFields(0xc000545470, 0x2f59f00, 0xc0004fe8c0)
/go/src/github.com/influxdata/telegraf/plugins/processors/converter/converter.go:278 +0x8c4
github.com/influxdata/telegraf/plugins/processors/converter.(*Converter).Apply(0xc000545470, 0xc0001fa180, 0x1, 0x1, 0xc00007ca20, 0x0, 0xc000554d80)
/go/src/github.com/influxdata/telegraf/plugins/processors/converter/converter.go:86 +0x9c
github.com/influxdata/telegraf/plugins/processors.(*streamingProcessor).Add(0xc00000efa0, 0x2f59f00, 0xc0004fe8c0, 0x2f4aea0, 0xc00000f560, 0x2e53201, 0x101)
/go/src/github.com/influxdata/telegraf/plugins/processors/streamingprocessor.go:35 +0x81
github.com/influxdata/telegraf/models.(*RunningProcessor).Add(0xc0005455f0, 0x2f59f00, 0xc0004fe8c0, 0x2f4aea0, 0xc00000f560, 0x0, 0x0)
/go/src/github.com/influxdata/telegraf/models/running_processor.go:95 +0x106
github.com/influxdata/telegraf/agent.(*Agent).runProcessors.func1(0xc000053730, 0xc00000f3e0)
/go/src/github.com/influxdata/telegraf/agent/agent.go:559 +0x156
created by github.com/influxdata/telegraf/agent.(*Agent).runProcessors
/go/src/github.com/influxdata/telegraf/agent/agent.go:554 +0x90

Additional info:

The important portion of the config is:

[[inputs.snmp.field]]
    name="cpuPercent"
    oid = "HIK-DEVICE-MIB::cpuPercent.0"

  [[processors.regex]]
    order = 1
    namepass = "cpuPercent"
    [[processors.regex.fields]]
      pattern = "([^0-9]+)"
      replacement = "${1}"

  [[processors.converter]]
    order = 2
    [processors.converter.fields]
      integer = ["cpuPercent"]

The snmp pull of oid = "HIK-DEVICE-MIB::cpuPercent.0" returns a result of "10 PERCENT" without the quotes. I was attempting to use regex/converter plugin to remove the " PERCENT" portion of the result.

To go from:

name: snmp
time                agent_host cpuPercent 
----                ---------- ---------- 
1600392300000000000 IP-ADDRESS 10 PERCENT 

To:

name: snmp
time                agent_host cpuPercent 
----                ---------- ---------- 
1600392300000000000 IP-ADDRESS 10

I have tried additional regex patterns as well with the same results. Additional information info/testing can be seen on the influx community site here https://community.influxdata.com/t/changing-snmp-input-with-regex-using-telegraf-pulls-before-influxdb/16021

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugunexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions