Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNMP Table input fails on Windows #3263

Closed
pstatho opened this issue Sep 25, 2017 · 9 comments · Fixed by #3396
Closed

SNMP Table input fails on Windows #3263

pstatho opened this issue Sep 25, 2017 · 9 comments · Fixed by #3396
Assignees
Labels
area/snmp bug unexpected problem or unintended behavior platform/windows
Milestone

Comments

@pstatho
Copy link

pstatho commented Sep 25, 2017

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:

  1. Install net-snmp 5.7 for Windows
  2. 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

@danielnelson
Copy link
Contributor

I wonder if this is a permissions or environment issue, how are you running telegraf?

@pstatho
Copy link
Author

pstatho commented Sep 25, 2017

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.

@pstatho
Copy link
Author

pstatho commented Sep 25, 2017

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.

@danielnelson danielnelson added area/snmp bug unexpected problem or unintended behavior platform/windows labels Sep 25, 2017
@RubenN
Copy link

RubenN commented Oct 20, 2017

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

@danielnelson
Copy link
Contributor

I did a little investigation and it appears that this is caused by DOS line endings in the command output in Windows.

@pstatho
Copy link
Author

pstatho commented Oct 22, 2017

Thanks @danielnelson, would you know of a temporary workaround or do we have to wait till this bug is corrected?

@RubenN
Copy link

RubenN commented Oct 23, 2017

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.

@danielnelson
Copy link
Contributor

@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.

@pstatho
Copy link
Author

pstatho commented Oct 25, 2017

@danielnelson the line parsing does sound like it's the issue. I suppose using ReadLine() instead would make it cross-platform. BTW, it's also used on several other lines like 850 and 877 and 970

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/snmp bug unexpected problem or unintended behavior platform/windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants