SNMP Table input fails on Windows
Bug report
SNMP Table input fails on Windows.
Relevant telegraf.conf:
[[inputs.snmp]]
agents = [ "10.20.254.10:161" ]
version = 1
community = "public"
name = "Switches"
[[inputs.snmp.field]]
name = "hostname"
oid = "RFC1213-MIB::sysName.0"
is_tag = true
[[inputs.snmp.field]]
name = "uptime"
oid = "DISMAN-EXPRESSION-MIB::sysUpTimeInstance"
[[inputs.snmp.table]]
name = "iface"
inherit_tags = [ "hostname" ]
oid = "IF-MIB::ifTable"
# Interface tag - used to identify interface in metrics database
[[inputs.snmp.table.field]]
name = "ifDescr"
oid = "IF-MIB::ifDescr"
is_tag = true
System info:
Telegraf v1.4 on Windows 2012R2
Steps to reproduce:
- Install net-snmp 5.7 for Windows
- Use the CONFIG EXAMPLES from the SNMP plugin as above
Expected behavior:
SNMP Table info is collected and sent to InfluxDB
Actual behavior:
SNMP plugin fails to collect table data
Additional info:
Log file contains the following error:
2017-09-25T04:41:40Z E! Error in plugin [inputs.snmp]: initializing table iface: getting table columns: exit status 1: IF-MIB::ifTable
I believe the error is occurring on line 876 of snmp.go file. My understanding is that it is running the command:
snmptable -Ch -Cl -c public 127.0.0.1 IF-MIB::ifTable
When I run that command from the command line, it returns the table columns and I checked the exit code which is 0.
Use case: [Why is this important (helps with prioritizing requests)]
Pretty important for Windows sysadmins to use TICK to collect SNMP data in an office environment
I wonder if this is a permissions or environment issue, how are you running telegraf?
Telegraf is running a windows service as per documentation. If I comment out just the [[inputs.snmp.table]] section telegraf will get the other SNMP values properly. In fact when I'm collecting an individual index (port) from IF-MIB::ifTable is works no problem and is sent to InfluxDB as expected. Only when I use the table option it fails.
Also like I mentioned, I'm pretty sure it's failing when calling snmpwalk to get the headers, since the error message happens right after that check.
I just tried in another environment with another network device and I get the same error. I believe it's the way Go is wrapping and calling the net-snmp commands. BTW, yes the net-snmp commands work properly since I can call snmpwalk -v 1 -c public 10.20.254.10 IF-MIB::ifTable and it will return the results of tha table as expected.
Same here on a windows 10 64 bit system:
2017-10-19T13:46:00Z E! Error in plugin [inputs.snmp]: initializing table interface: getting table columns: exit status 1: IF-MIB::ifTable
I did a little investigation and it appears that this is caused by DOS line endings in the command output in Windows.
Thanks @danielnelson, would you know of a temporary workaround or do we have to wait till this bug is corrected?
I put part of the logic in a little test program:
...
oidFullName := "IF-MIB::ifTable"
// this won't actually try to run a query. The `-Ch` will just cause it to dump headers.
out, err := execCmd("snmptable", "-Ch", "-Cl", "-c", "public", "127.0.0.1", oidFullName)
if err != nil {
fmt.Println(err.Error())
}
...
And this doesn't trigger the error part.
@pstatho You might be able to create a wrapper script that converts to unix line endings, and wrap both snmptranslate and snmptable. I haven't tried this so I'm not sure if it will work.
@RubenN It is not actually a problem with running the commands, but with parsing the output. When we parse the oidText here it has a trailing \r. This breaks the later running of snmptable because the args are invalid.