Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
titilambert committed Mar 1, 2016
1 parent ca989b4 commit ff13f7b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion plugins/inputs/snmp/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type Host struct {
getOids []Data
bulkOids []Data
tables []HostTable
// array of processed oids
// to skip oid duplication
processedOids []string
}

type Table struct {
Expand Down Expand Up @@ -714,8 +717,15 @@ func (h *Host) HandleResponse(oids map[string]Data, result *gosnmp.SnmpPacket, a
var lastOid string
for _, variable := range result.Variables {
lastOid = variable.Name
// Remove unwanted oid
nextresult:
// Get only oid wanted
for oid_key, oid := range oids {
// Skip oids already processed
for _, processedOid := range h.processedOids {
if variable.Name == processedOid {
break nextresult
}
}
if strings.HasPrefix(variable.Name, oid_key) {
switch variable.Type {
// handle Metrics
Expand Down Expand Up @@ -767,6 +777,7 @@ func (h *Host) HandleResponse(oids map[string]Data, result *gosnmp.SnmpPacket, a
fields := make(map[string]interface{})
fields[string(field_name)] = variable.Value

h.processedOids = append(h.processedOids, variable.Name)
acc.AddFields(field_name, fields, tags)
case gosnmp.NoSuchObject, gosnmp.NoSuchInstance:
// Oid not found
Expand Down

0 comments on commit ff13f7b

Please sign in to comment.