Skip to content

Commit

Permalink
Update SNMP exporter (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev authored May 14, 2024
1 parent dd1ccf6 commit f377891
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Main (unreleased)
This port can be configured with `--server.http.listen-addr` or using
the default listen address`127.0.0.1:12345`. (@mattdurham)

### Other changes

- `prometheus.exporter.snmp`: Updating SNMP exporter from v0.24.1 to v0.26.0.

v1.1.0-rc.0
-----------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The `prometheus.exporter.snmp` component embeds
[`snmp_exporter`](https://github.com/prometheus/snmp_exporter). `snmp_exporter` lets you collect SNMP data and expose them as Prometheus metrics.

{{< admonition type="note" >}}
`prometheus.exporter.snmp` uses the latest configuration introduced in version 0.23 of the Prometheus `snmp_exporter`.
`prometheus.exporter.snmp` uses the latest configuration introduced in version 0.26 of the Prometheus `snmp_exporter`.
{{< /admonition >}}

## Usage
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ require (
github.com/prometheus/node_exporter v1.6.0
github.com/prometheus/procfs v0.12.0
github.com/prometheus/prometheus v1.99.0
github.com/prometheus/snmp_exporter v0.24.1
github.com/prometheus/snmp_exporter v0.26.0
github.com/prometheus/statsd_exporter v0.22.8
github.com/richardartoul/molecule v1.0.1-0.20221107223329-32cfee06a052
github.com/rs/cors v1.10.1
Expand Down Expand Up @@ -432,7 +432,7 @@ require (
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/gophercloud/gophercloud v1.8.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gosnmp/gosnmp v1.36.0 // indirect
github.com/gosnmp/gosnmp v1.37.0 // indirect
github.com/grafana/go-offsets-tracker v0.1.7 // indirect
github.com/grafana/gomemcache v0.0.0-20231204155601-7de47a8c3cb0 // indirect
github.com/grafana/jfr-parser v0.8.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gosnmp/gosnmp v1.36.0 h1:1Si+MImHcKIqFc3/kJEs2LOULP1nlFKlzPFyrMOk5Qk=
github.com/gosnmp/gosnmp v1.36.0/go.mod h1:iLcZxN2MxKhH0jPQDVMZaSNypw1ykqVi27O79koQj6w=
github.com/gosnmp/gosnmp v1.37.0 h1:/Tf8D3b9wrnNuf/SfbvO+44mPrjVphBhRtcGg22V07Y=
github.com/gosnmp/gosnmp v1.37.0/go.mod h1:GDH9vNqpsD7f2HvZhKs5dlqSEcAS6s6Qp099oZRCR+M=
github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY=
github.com/grafana/alloy-remote-config v0.0.4 h1:XqpZ5ZmaVc1E1MZwWoQ4pTPtDQq1L2I2TEhN5JpH8nY=
github.com/grafana/alloy-remote-config v0.0.4/go.mod h1:kHE1usYo2WAVCikQkIXuoG1Clz8BSdiz3kF+DZSCQ4k=
Expand Down Expand Up @@ -1982,6 +1984,10 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/prometheus/snmp_exporter v0.24.1 h1:AihTbJHurMo8bjtjJde8U+4gMEvpvYvT21Xbd4SzJgY=
github.com/prometheus/snmp_exporter v0.24.1/go.mod h1:j6uIGkdR0DXvKn7HJtSkeDj//UY0sWmdd6XhvdBjln0=
github.com/prometheus/snmp_exporter v0.25.1-0.20240501011921-5f907e691aa5 h1:eDoGVogLF6DRe1s7NpQI6oz8atI3eM2Q58JmHiKOkRM=
github.com/prometheus/snmp_exporter v0.25.1-0.20240501011921-5f907e691aa5/go.mod h1:zOJjSLA//ET2bH76vYBdftmKEg1LiqfNesyZy+nMHvc=
github.com/prometheus/snmp_exporter v0.26.0 h1:7THSh/mAIMmHkiVhmsrAwiH1XNGiFelhPCKBe8PXg8U=
github.com/prometheus/snmp_exporter v0.26.0/go.mod h1:GJEhIONojqxbjn3eyCykWeGVXQJg9pdYSX2scFLpEA0=
github.com/prometheus/statsd_exporter v0.22.8 h1:Qo2D9ZzaQG+id9i5NYNGmbf1aa/KxKbB9aKfMS+Yib0=
github.com/prometheus/statsd_exporter v0.22.8/go.mod h1:/DzwbTEaFTE0Ojz5PqcSk6+PFHOPWGxdXVr6yC8eFOM=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
Expand Down
8 changes: 7 additions & 1 deletion internal/static/integrations/snmp_exporter/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func Handler(w http.ResponseWriter, r *http.Request, logger log.Logger, snmpCfg
authName = "public_v2"
}

snmpContext := query.Get("snmp_context")
if len(query["snmp_context"]) > 1 {
http.Error(w, "'snmp_context' parameter must only be specified once", http.StatusBadRequest)
return
}

module, ok := (*snmpCfg).Modules[moduleName]
if !ok {
http.Error(w, fmt.Sprintf("Unknown module '%s'", moduleName), http.StatusBadRequest)
Expand Down Expand Up @@ -113,7 +119,7 @@ func Handler(w http.ResponseWriter, r *http.Request, logger log.Logger, snmpCfg

start := time.Now()
registry := prometheus.NewRegistry()
c := collector.New(r.Context(), target, authName, auth, nmodules, logger, NewSNMPMetrics(registry), concurrency)
c := collector.New(r.Context(), target, authName, snmpContext, auth, nmodules, logger, NewSNMPMetrics(registry), concurrency, false)
registry.MustRegister(c)
// Delegate http serving to Prometheus client library, which will call collector.Collect.
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func New(log log.Logger, c *Config) (integrations.Integration, error) {
func LoadSNMPConfig(snmpConfigFile string, snmpCfg *snmp_config.Config) (*snmp_config.Config, error) {
var err error
if snmpConfigFile != "" {
snmpCfg, err = snmp_config.LoadFile([]string{snmpConfigFile})
snmpCfg, err = snmp_config.LoadFile([]string{snmpConfigFile}, false)
if err != nil {
return nil, fmt.Errorf("failed to load snmp config from file %v: %w", snmpConfigFile, err)
}
Expand Down

0 comments on commit f377891

Please sign in to comment.