Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ executors:
# should also be updated.
golang:
docker:
- image: cimg/go:1.24
- image: cimg/go:1.25
parameters:
working_dir:
type: string
Expand Down
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here,
# .circle/config.yml should also be updated.
version: 1.24
version: 1.25
repository:
path: github.com/prometheus/snmp_exporter
build:
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ ARG ARCH="amd64"
ARG OS="linux"
COPY .build/${OS}-${ARCH}/snmp_exporter /bin/snmp_exporter
COPY snmp.yml /etc/snmp_exporter/snmp.yml
COPY LICENSE /LICENSE
COPY NOTICE /NOTICE


EXPOSE 9116
ENTRYPOINT [ "/bin/snmp_exporter" ]
Expand Down
18 changes: 6 additions & 12 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var combinedTypeMapping = map[string]map[int]string{

func oidToList(oid string) []int {
result := []int{}
for _, x := range strings.Split(oid, ".") {
for x := range strings.SplitSeq(oid, ".") {
o, _ := strconv.Atoi(x)
result = append(result, o)
}
Expand Down Expand Up @@ -118,10 +118,7 @@ func ScrapeTarget(snmp scraper.SNMPScraper, target string, auth *config.Auth, mo
maxOids = 1
}
for len(getOids) > 0 {
oids := len(getOids)
if oids > maxOids {
oids = maxOids
}
oids := min(len(getOids), maxOids)

packet, err := snmp.Get(getOids[:oids])
if err != nil {
Expand Down Expand Up @@ -355,7 +352,7 @@ func (c Collector) collect(ch chan<- prometheus.Metric, logger *slog.Logger, cli
g.MaxRepetitions = module.WalkParams.MaxRepetitions
g.UseUnconnectedUDPSocket = module.WalkParams.UseUnconnectedUDPSocket
if module.WalkParams.AllowNonIncreasingOIDs {
g.AppOpts = map[string]interface{}{
g.AppOpts = map[string]any{
"c": true,
}
}
Expand Down Expand Up @@ -423,10 +420,7 @@ func (c Collector) collect(ch chan<- prometheus.Metric, logger *slog.Logger, cli
// Collect implements Prometheus.Collector.
func (c Collector) Collect(ch chan<- prometheus.Metric) {
wg := sync.WaitGroup{}
workerCount := c.concurrency
if workerCount < 1 {
workerCount = 1
}
workerCount := max(c.concurrency, 1)
ctx, cancel := context.WithCancel(c.ctx)
defer cancel()
workerChan := make(chan *NamedModule)
Expand Down Expand Up @@ -764,7 +758,7 @@ func enumAsStateSet(metric *config.Metric, value int, labelnames, labelvalues []
return results
}

func bits(metric *config.Metric, value interface{}, labelnames, labelvalues []string) []prometheus.Metric {
func bits(metric *config.Metric, value any, labelnames, labelvalues []string) []prometheus.Metric {
bytes, ok := value.([]byte)
if !ok {
return []prometheus.Metric{prometheus.NewInvalidMetric(prometheus.NewDesc("snmp_error", "BITS type was not a BISTRING on the wire.", nil, nil),
Expand Down Expand Up @@ -936,7 +930,7 @@ func indexOidsAsString(indexOids []int, typ string, fixedSize int, implied bool,
return strings.Join(parts, "."), subOid, indexOids
case "InetAddressIPv6":
subOid, indexOids := splitOid(indexOids, 16)
parts := make([]interface{}, 16)
parts := make([]any, 16)
for i, o := range subOid {
parts[i] = o
}
Expand Down
14 changes: 7 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"time"

"github.com/gosnmp/gosnmp"
"gopkg.in/yaml.v2"
"go.yaml.in/yaml/v2"
)

type Auth struct {
Expand Down Expand Up @@ -138,7 +138,7 @@ type Module struct {
Filters []DynamicFilter `yaml:"filters,omitempty"`
}

func (c *Module) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (c *Module) UnmarshalYAML(unmarshal func(any) error) error {
*c = DefaultModule
type plain Module
return unmarshal((*plain)(c))
Expand Down Expand Up @@ -273,7 +273,7 @@ var (
)

// MarshalYAML implements the yaml.Marshaler interface.
func (s Secret) MarshalYAML() (interface{}, error) {
func (s Secret) MarshalYAML() (any, error) {
if DoNotHideSecrets {
return string(s), nil
}
Expand All @@ -283,7 +283,7 @@ func (s Secret) MarshalYAML() (interface{}, error) {
return nil, nil
}

func (c *Auth) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (c *Auth) UnmarshalYAML(unmarshal func(any) error) error {
*c = DefaultAuth
type plain Auth
if err := unmarshal((*plain)(c)); err != nil {
Expand Down Expand Up @@ -327,7 +327,7 @@ type RegexpExtract struct {
Regex Regexp `yaml:"regex"`
}

func (c *RegexpExtract) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (c *RegexpExtract) UnmarshalYAML(unmarshal func(any) error) error {
*c = DefaultRegexpExtract
type plain RegexpExtract
return unmarshal((*plain)(c))
Expand All @@ -339,15 +339,15 @@ type Regexp struct {
}

// MarshalYAML implements the yaml.Marshaler interface.
func (re Regexp) MarshalYAML() (interface{}, error) {
func (re Regexp) MarshalYAML() (any, error) {
if re.Regexp != nil {
return re.String(), nil
}
return nil, nil
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (re *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (re *Regexp) UnmarshalYAML(unmarshal func(any) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"testing"

"github.com/prometheus/common/promslog"
yaml "gopkg.in/yaml.v2"
"go.yaml.in/yaml/v2"
)

var nopLogger = promslog.NewNopLogger()
Expand Down
4 changes: 2 additions & 2 deletions generator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type MetricOverrides struct {
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *MetricOverrides) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (c *MetricOverrides) UnmarshalYAML(unmarshal func(any) error) error {
type plain MetricOverrides
if err := unmarshal((*plain)(c)); err != nil {
return err
Expand All @@ -62,7 +62,7 @@ type ModuleConfig struct {
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *ModuleConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (c *ModuleConfig) UnmarshalYAML(unmarshal func(any) error) error {
type plain ModuleConfig
if err := unmarshal((*plain)(c)); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/alecthomas/kingpin/v2"
"github.com/prometheus/common/promslog"
"github.com/prometheus/common/promslog/flag"
"gopkg.in/yaml.v2"
"go.yaml.in/yaml/v2"

"github.com/prometheus/snmp_exporter/config"
)
Expand Down
10 changes: 4 additions & 6 deletions generator/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"
"log/slog"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -466,12 +467,9 @@ func generateConfigModule(cfg *ModuleConfig, node *Node, nameToNode map[string]*

// If lookup label is used as source index in another lookup,
// we need to add this new label as another index.
for _, sourceIndex := range requiredAsIndex {
if sourceIndex == l.Labelname {
idx := &config.Index{Labelname: l.Labelname, Type: l.Type}
metric.Indexes = append(metric.Indexes, idx)
break
}
if slices.Contains(requiredAsIndex, l.Labelname) {
idx := &config.Index{Labelname: l.Labelname, Type: l.Type}
metric.Indexes = append(metric.Indexes, idx)
}

// Make sure we walk the lookup OID(s).
Expand Down
2 changes: 1 addition & 1 deletion generator/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"testing"

"github.com/prometheus/common/promslog"
yaml "gopkg.in/yaml.v2"
"go.yaml.in/yaml/v2"

"github.com/prometheus/snmp_exporter/config"
)
Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/prometheus/snmp_exporter

go 1.23.0

toolchain go1.24.1
go 1.24.0

require (
github.com/alecthomas/kingpin/v2 v2.4.0
Expand All @@ -12,7 +10,7 @@ require (
github.com/prometheus/client_model v0.6.2
github.com/prometheus/common v0.66.1
github.com/prometheus/exporter-toolkit v0.14.1
gopkg.in/yaml.v2 v2.4.0
go.yaml.in/yaml/v2 v2.4.3
)

require (
Expand All @@ -27,7 +25,6 @@ require (
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
Expand All @@ -77,7 +77,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/prometheus/common/version"
"github.com/prometheus/exporter-toolkit/web"
webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
yaml "gopkg.in/yaml.v2"
"go.yaml.in/yaml/v2"

"github.com/prometheus/snmp_exporter/collector"
"github.com/prometheus/snmp_exporter/config"
Expand Down Expand Up @@ -132,7 +132,7 @@ func handler(w http.ResponseWriter, r *http.Request, logger *slog.Logger, export
uniqueM := make(map[string]bool)
var modules []string
for _, qm := range queryModule {
for _, m := range strings.Split(qm, ",") {
for m := range strings.SplitSeq(qm, ",") {
if m == "" {
continue
}
Expand Down