Skip to content

Commit

Permalink
Remove version retrieval from scraper and update to fetch from auth i…
Browse files Browse the repository at this point in the history
…nformation

Signed-off-by: Kakuya Ando <[email protected]>
  • Loading branch information
servak committed Feb 12, 2024
1 parent 0bfbc47 commit 2097417
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
10 changes: 5 additions & 5 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type ScrapeResults struct {
pdus []gosnmp.SnmpPDU
}

func ScrapeTarget(snmp scraper.SNMPScraper, target string, module *config.Module, logger log.Logger, metrics Metrics) (ScrapeResults, error) {
func ScrapeTarget(snmp scraper.SNMPScraper, target string, auth *config.Auth, module *config.Module, logger log.Logger, metrics Metrics) (ScrapeResults, error) {
results := ScrapeResults{}
// Evaluate rules.
newGet := module.Get
Expand Down Expand Up @@ -109,11 +109,11 @@ func ScrapeTarget(snmp scraper.SNMPScraper, target string, module *config.Module
newGet = newCfg
}

version := snmp.GetVersion()
version := auth.Version
getOids := newGet
maxOids := int(module.WalkParams.MaxRepetitions)
// Max Repetition can be 0, maxOids cannot. SNMPv1 can only report one OID error per call.
if maxOids == 0 || version == gosnmp.Version1 {
if maxOids == 0 || version == 1 {
maxOids = 1
}
for len(getOids) > 0 {
Expand All @@ -127,7 +127,7 @@ func ScrapeTarget(snmp scraper.SNMPScraper, target string, module *config.Module
return results, err
}
// SNMPv1 will return packet error for unsupported OIDs.
if packet.Error == gosnmp.NoSuchName && version == gosnmp.Version1 {
if packet.Error == gosnmp.NoSuchName && version == 1 {
level.Debug(logger).Log("msg", "OID not supported by target", "oids", getOids[0])
getOids = getOids[oids:]
continue
Expand Down Expand Up @@ -346,7 +346,7 @@ func (c Collector) collect(ch chan<- prometheus.Metric, logger log.Logger, clien
)
start := time.Now()
moduleLabel := prometheus.Labels{"module": module.name}
results, err := ScrapeTarget(client, c.target, module.Module, logger, c.metrics)
results, err := ScrapeTarget(client, c.target, c.auth, module.Module, logger, c.metrics)
if err != nil {
level.Info(logger).Log("msg", "Error scraping target", "err", err)
ch <- prometheus.NewInvalidMetric(prometheus.NewDesc("snmp_error", "Error scraping target", nil, moduleLabel), err)
Expand Down
4 changes: 0 additions & 4 deletions scraper/gosnmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ func (g *GoSNMPWrapper) SetOptions(fns ...func(*gosnmp.GoSNMP)) {
}
}

func (g *GoSNMPWrapper) GetVersion() gosnmp.SnmpVersion {
return g.c.Version
}

func (g *GoSNMPWrapper) Connect() error {
st := time.Now()
err := g.c.Connect()
Expand Down
1 change: 0 additions & 1 deletion scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ type SNMPScraper interface {
WalkAll(string) ([]gosnmp.SnmpPDU, error)
Connect() error
Close() error
GetVersion() gosnmp.SnmpVersion
SetOptions(...func(*gosnmp.GoSNMP))
}

0 comments on commit 2097417

Please sign in to comment.