From 309f610fc3c0dfb55ba7e4ab4e3f92ff42e8755b Mon Sep 17 00:00:00 2001 From: Thibault Cohen Date: Mon, 21 Mar 2016 20:10:17 -0400 Subject: [PATCH] Fix #873 --- plugins/inputs/snmp/README.md | 8 ++++---- plugins/inputs/snmp/snmp.go | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/plugins/inputs/snmp/README.md b/plugins/inputs/snmp/README.md index ee6d17857..bee783228 100644 --- a/plugins/inputs/snmp/README.md +++ b/plugins/inputs/snmp/README.md @@ -492,12 +492,12 @@ Note: the plugin will add instance name as tag *instance* # oid attribute is useless # SNMP SUBTABLES - [[plugins.snmp.subtable]] + [[inputs.snmp.subtable]] name = "bytes_recv" oid = ".1.3.6.1.2.1.31.1.1.1.6" unit = "octets" - [[plugins.snmp.subtable]] + [[inputs.snmp.subtable]] name = "bytes_send" oid = ".1.3.6.1.2.1.31.1.1.1.10" unit = "octets" @@ -505,10 +505,10 @@ Note: the plugin will add instance name as tag *instance* #### Configuration notes -- In **plugins.snmp.table** section, the `oid` attribute is useless if +- In **inputs.snmp.table** section, the `oid` attribute is useless if the `sub_tables` attributes is defined -- In **plugins.snmp.subtable** section, you can put a name from `snmptranslate_file` +- In **inputs.snmp.subtable** section, you can put a name from `snmptranslate_file` as `oid` attribute instead of a valid OID ### Measurements & Fields: diff --git a/plugins/inputs/snmp/snmp.go b/plugins/inputs/snmp/snmp.go index ba270cb1d..a56e53ff7 100644 --- a/plugins/inputs/snmp/snmp.go +++ b/plugins/inputs/snmp/snmp.go @@ -4,7 +4,6 @@ import ( "io/ioutil" "log" "net" - "regexp" "strconv" "strings" "time" @@ -308,11 +307,10 @@ func (s *Snmp) Gather(acc telegraf.Accumulator) error { return err } else { for _, line := range strings.Split(string(data), "\n") { - oidsRegEx := regexp.MustCompile(`([^\t]*)\t*([^\t]*)`) - oids := oidsRegEx.FindStringSubmatch(string(line)) - if oids[2] != "" { - oid_name := oids[1] - oid := oids[2] + oids := strings.Fields(string(line)) + if len(oids) == 2 && oids[1] != "" { + oid_name := oids[0] + oid := oids[1] fillnode(s.initNode, oid_name, strings.Split(string(oid), ".")) s.nameToOid[oid_name] = oid }