############################################################################
# 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"
Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-47-generic x86_64)
Telegraf 1.15.3
When running the test config command against the file containing the above configuration, I receive a panic: runtime error
When running the config test command: sudo telegraf --test --config /etc/telegraf/telegraf.d/hiktest.conf
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
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
Your configuration looks incorrect.
You have processors in the middle of [[inputs.snmp]]. Move them to the end:
[[inputs.snmp]]
.....
[[processors.regex]]
...
[[processors.converter]]
....
Processors and inputs are different plugins and are executed in turn.
After that, adjust the filters that you apply to the processor:
namepass = "cpuPercent"
This key takes an array. Note that namepass filters by measurement name, and you pass the field name to it.
And try running the test again. Does the error happen?
The error persists.
[[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"
[[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"
[[processors.regex]]
order = 1
namepass = ["cpuPercent"]
[[processors.regex.fields]]
pattern = "([^0-9]+)"
replacement = "${1}"
[[processors.converter]]
order = 2
[processors.converter.fields]
integer = ["cpuPercent"]
error:
2020-09-23T17:02:30Z 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 22 [running]:
github.com/influxdata/telegraf/plugins/processors/converter.(*Converter).convertFields(0xc00067b920, 0x2f59f00, 0xc0004c82a0)
/go/src/github.com/influxdata/telegraf/plugins/processors/converter/converter.go:278 +0x8c4
github.com/influxdata/telegraf/plugins/processors/converter.(*Converter).Apply(0xc00067b920, 0xc0004c0470, 0x1, 0x1, 0xc0004bd140, 0x0, 0xc00045ac00)
/go/src/github.com/influxdata/telegraf/plugins/processors/converter/converter.go:86 +0x9c
github.com/influxdata/telegraf/plugins/processors.(*streamingProcessor).Add(0xc000111cc0, 0x2f59f00, 0xc0004c82a0, 0x2f4aea0, 0xc000572040, 0x1, 0xc000570101)
/go/src/github.com/influxdata/telegraf/plugins/processors/streamingprocessor.go:35 +0x81
github.com/influxdata/telegraf/models.(*RunningProcessor).Add(0xc00067baa0, 0x2f59f00, 0xc0004c82a0, 0x2f4aea0, 0xc000572040, 0x0, 0x0)
/go/src/github.com/influxdata/telegraf/models/running_processor.go:95 +0x106
github.com/influxdata/telegraf/agent.(*Agent).runProcessors.func1(0xc000502e70, 0xc00018e100)
/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
I have a fix for the panic incoming.
Give me a sec and I should be able to fix the regex, too.
ok for the regex you need
pattern = "^(\\d+).*"
replacement = "${1}"
I will also add that you still have an incorrect filter. Try this:
[[processors.regex]]
order = 1
namepass = ["snmp"]
[[processors.regex.fields]]
key = "cpuPercent"
pattern = "^(\\d+).*"
replacement = "${1}"
Thank you!
The crashes have stopped, and the output is nearly as I think it should be. I have made both changes.
The test result inserts the letter "i" after the number value:
cpuPercent=10i
sudo telegraf --test --config /etc/telegraf/telegraf.d/hiktest.conf
2020-09-23T18:14:41Z I! Starting Telegraf 1.15.3
> snmp,agent_host=IP-ADDRESS,host=hostname cpuPercent=10i,deviceModel="DS-2CD2042WD-I",manufacturer="Hikvision",memUsed="80 PERCENT",staticIp="10.66.6.60",vidEncode="H.264" 1600885005000000000
This is a feature of the line protocol - https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/#data-types
Thank you @M0rdecay , I should have checked how it looked in influx before seeking help.
Thank you as well @ssoroka , I have learned a lot for you these past few days
Everything is now working as expected.
Should I close this issue? Excuse my ignorance, but this is my first experience with Github
I think so, since the issue has been solved.
Most helpful comment
Thank you @M0rdecay , I should have checked how it looked in influx before seeking help.
Thank you as well @ssoroka , I have learned a lot for you these past few days
Everything is now working as expected.