From 46543d632305c9fb83beae1db85849eb119c528c Mon Sep 17 00:00:00 2001 From: Larry Kim Date: Sun, 17 Apr 2016 02:00:52 +0900 Subject: [PATCH] Possible bug fix for oid_key collision closes #1044 --- CHANGELOG.md | 1 + plugins/inputs/snmp/snmp.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd8cf98f..bcd0efa71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ based on _prefix_ in addition to globs. This means that a filter like - [#1013](https://github.com/influxdata/telegraf/pull/1013): Close dead riemann output connections. Thanks @echupriyanov! - [#1012](https://github.com/influxdata/telegraf/pull/1012): Set default tags in test accumulator. - [#1058](https://github.com/influxdata/telegraf/issues/1058): Fix possible leaky TCP connections in influxdb output. +- [#1044](https://github.com/influxdata/telegraf/pull/1044): Fix SNMP OID possible collisions. Thanks @relip ## v0.12.1 [2016-04-14] diff --git a/plugins/inputs/snmp/snmp.go b/plugins/inputs/snmp/snmp.go index 3a95e84fa..8ccfe100b 100644 --- a/plugins/inputs/snmp/snmp.go +++ b/plugins/inputs/snmp/snmp.go @@ -733,7 +733,11 @@ func (h *Host) HandleResponse(oids map[string]Data, result *gosnmp.SnmpPacket, a break nextresult } } - if strings.HasPrefix(variable.Name, oid_key) { + // If variable.Name is the same as oid_key + // OR + // the result is SNMP table which "." comes right after oid_key. + // ex: oid_key: .1.3.6.1.2.1.2.2.1.16, variable.Name: .1.3.6.1.2.1.2.2.1.16.1 + if variable.Name == oid_key || strings.HasPrefix(variable.Name, oid_key+".") { switch variable.Type { // handle Metrics case gosnmp.Boolean, gosnmp.Integer, gosnmp.Counter32, gosnmp.Gauge32,