Skip to content

Commit

Permalink
Allow discovery to use both v3 and v2 snmp creds. #346 (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
i3149 authored Jul 6, 2022
1 parent 02ad285 commit ff59c82
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions pkg/inputs/snmp/disco.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,29 +220,30 @@ func doubleCheckHost(result scan.Result, timeout time.Duration, ctl chan bool, m
continue
}
}
} else { // Loop over all possibe v2c options here.
for _, community := range conf.Disco.DefaultCommunities {
device = kt.SnmpDeviceConfig{
DeviceName: result.Name,
DeviceIP: result.Host.String(),
Community: community,
UseV1: conf.Disco.UseV1,
Debug: conf.Disco.Debug,
Port: uint16(conf.Disco.Ports[0]),
Checked: time.Now(),
}
serv, err := snmp_util.InitSNMP(&device, timeout, conf.Global.Retries, posit, log)
if err != nil {
log.Warnf("There was an error when starting SNMP interface component -- %v.", err)
return
}
md, err = metadata.GetBasicDeviceMetadata(log, serv)
if err != nil {
log.Warnf("Cannot get device metadata on %s: %v. Check for correct snmp credentials.", result.Host.String(), err)
continue
}
break // We're good to go here.
}

// Loop over all possibe v2c options here if any are set.
for _, community := range conf.Disco.DefaultCommunities {
device = kt.SnmpDeviceConfig{
DeviceName: result.Name,
DeviceIP: result.Host.String(),
Community: community,
UseV1: conf.Disco.UseV1,
Debug: conf.Disco.Debug,
Port: uint16(conf.Disco.Ports[0]),
Checked: time.Now(),
}
serv, err := snmp_util.InitSNMP(&device, timeout, conf.Global.Retries, posit, log)
if err != nil {
log.Warnf("There was an error when starting SNMP interface component -- %v.", err)
return
}
md, err = metadata.GetBasicDeviceMetadata(log, serv)
if err != nil {
log.Warnf("Cannot get device metadata on %s: %v. Check for correct snmp credentials.", result.Host.String(), err)
continue
}
break // We're good to go here.
}

if md == nil { // No way to establish comminications
Expand Down

0 comments on commit ff59c82

Please sign in to comment.